分享

Centos安装后配置优化 | btCoder

 左目右于 2011-11-08

Centos安装后配置优化

一 关闭selinux
selinux对很多服务的要求以及安全策略非常多非常多,新手很难驾驭,所以一般建议关闭, 但在加固一些网络服务时,还是需要开启的

1
2
#disable selinux
 sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

二. 更换yum的更新源
如果服务器不是位于教育网内,中科大的镜像源速度也很一般啊, 强烈建议整合sohu或者163的更新源:

1
2
3
4
5
6
7
cd /etc/yum.repos.d
mv CentOS-Base.repo  CentOS-Base.repo.save
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo
mv CentOS-Base-sohu.repo CentOS-Base.repo
wget http://mirrors.163.com/.help/CentOS-Base-163.repo
wget http://mirrors.ustc.edu.cn/centos/CentOS-Base.5.mirrors.repo
yum makecache

三 定时校正服务器时间
作为生产机的服务器时间的准备性非常重要, 我们需要定时根据NTP服务器时间自动校准时间, 全世界各地有很多ntp服务, 我们一般会选择当地的服务器, 但是, 我们要慎重选择像中国国家授时中心的标准时间服务器(210.72.145.44), 可能是访问量过大, 造成负载过大而无法访问。
推荐使用以下NTP服务器:
1.asia.pool.ntp.org
0.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

1
2
yum install ntp
crontab -e

增加一行,在每天的0点15分、6点15分、12点15分、18点15分与时间同步服务器进行同步:

1
15 0,6,12,18 * * * ntpdate 1.asia.pool.ntp.org


四. 设置终端模式(init 3)
1、vi /etc/inittab
2、找到id:5:initdefault: 这行
3、将5改为3即可,即id:3:initdefault:

五 停止网卡对ipv6的支持
在CentOS默认的状态下,ipv6是被启用的状态。因为我们不使用ipv6,所以停止ipv6,以最大限 度保证安全和快速。
#vi /etc/modprobe.conf ← 修改相应配置文件,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off

六 调整Linux的最大文件打开数
Linux最大文件打开数的默认值很低,必须修改的高一些
vim /etc/security/limit.conf
在最后一行添加
* soft nofile 60000
* hard nofile 65535

值得注意的是,通过命令ulimit -SHn是改变不了linux系统的最大文件打开数的,写进/etc/rc.d/rc.local也是不行的。

七 关闭不需要的服务
根据自己的需要和网络上的资料整理了80多个常见的centos5.6服务
下载: centos常见服务优化与说明

参考:http://chinaestone./blog/965923

八 TCP性能优化

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380    4194304
net.ipv4.tcp_wmem = 4096        16384    4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    65000

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多