码迷,mamicode.com
首页 > 其他好文 > 详细

Centos系统初始优化设置

时间:2017-09-12 23:19:05      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:linux   centos   系统初始   

更新YUM

一般系统安装完后需要更新软件包,但使用国外的yum源速度没得说,慢的不要不要。所以推荐使用国内的YUM源。

笔者一般使用网易或阿里的源可以登录相关的官网上下载使用,以下以阿里的yum源为例:

阿里镜像官网:http://mirrors.aliyun.com/

首先先备份原有的yum

mv  CentOS-Base.repo CentOS-Base.repo.bak


下载阿里yum源

wget http://mirrors.aliyun.com/repo/Centos-6.repo
mv Centos-6.repo CentOS-Base.repo

增加epel源

wget http://mirrors.aliyun.com/repo/epel-6.repo


执行yum更新

yum clean all    ##清除yum缓存
yum makecache##重建缓存
yum update ##升级linux系统



关闭不需要的服务

yum install ntsysv

netsysv

以下列出必要的服务

crond 自动计划任务

network 网络服务

sshd OpenSSh 服务器守护进程

rsyslog Linux日志服务

其他暂时还未使用的建议关闭


关闭不必的tty

查看系统当前打开的TTY控制台

[root@localhost ~]# ps -aux | grep tty | grep -v grep
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root       1345  0.0  0.0   4068   268 tty2     Ss+  Sep10   0:00 /sbin/mingetty /dev/tty2
root       1347  0.0  0.0   4068   268 tty3     Ss+  Sep10   0:00 /sbin/mingetty /dev/tty3
root       1349  0.0  0.0   4068   268 tty4     Ss+  Sep10   0:00 /sbin/mingetty /dev/tty4
root       1351  0.0  0.0   4068   268 tty5     Ss+  Sep10   0:00 /sbin/mingetty /dev/tty5
root       1353  0.0  0.0   4068   268 tty6     Ss+  Sep10   0:00 /sbin/mingetty /dev/tty6
root      19958  0.0  0.0   4064   584 tty1     Ss+  03:40   0:00 /sbin/mingetty /dev/tty1


可以看出一共有6个,事实上没必要开启太多,所以建议关闭一些。

接下来修改配置文件,使其打开2个。

[root@localhost ~]# cat /etc/init/start-ttys.conf 
#
# This service starts the configured number of gettys.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file start-ttys.override and put your changes there.
start on stopped rc RUNLEVEL=[2345]
env ACTIVE_CONSOLES=/dev/tty[1-6]      #修改[1-6]为[1-2],然后重启即可
env X_TTY=/dev/tty1
task
script
. /etc/sysconfig/init
for tty in $(echo $ACTIVE_CONSOLES) ; do
[ "$RUNLEVEL" = "5" -a "$tty" = "$X_TTY" ] && continue
initctl start tty TTY=$tty
done
end script



校正服务器时间

yum install ntp
echo "01 01 *   *    *   /usr/bin/ntpdate ntp.api.bz   >> /dev/null  2>&1"    >>  /etc/crontab 
ntpdate ntp.api.bz



调整Linux最大打开文件数

ulimit -SHn 65535
cat /etc/security/limits.conf #末尾添加两行
.......
*soft nofile65535
*hardnofile65535
........

ulimits -n 一般不能正真的看出最大文件数可以使用以下脚本查看

[root@localhost ~]# cat testulimit.sh
#!/bin/bash
for pid in `ps aux | grep nginx | grep -v grep| awk ‘{print $2}‘`
do
cat /proc/${pid}/limits | grep "Max open files"
done


增加sudu权限用户

vim /etc/sudoers
....
rootALL=(ALL) ALL
admin  ALL=(ALL)  NOPASSWD:ALL  ##增加这行,NOPASSWD是使用sudo时不用输入root密码



修改SSH登录配置

禁止root 用户登录

sed -i ‘s@PermitRootLogin yes@PermitRootLogin no@‘ /etc/ssh/sshd_config

禁止空密码登录

sed -i ‘s@#PermitEmptyPasswords no@PermitEmptyPasswords no@‘ /etc/ssh/sshd_config

关闭SSH反向查询,提高SSH访问速度

sed -i "s@#UseDNS yes@#UseDNS no@" /etc/ssh/sshd_config


本文出自 “TOP-ONE” 博客,请务必保留此出处http://onenice.blog.51cto.com/13201315/1964746

Centos系统初始优化设置

标签:linux   centos   系统初始   

原文地址:http://onenice.blog.51cto.com/13201315/1964746

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!