一 關(guān)閉selinux
selinux對(duì)很多服務(wù)的要求以及安全策略非常多非常多,,新手很難駕馭,,所以一般建議關(guān)閉, 但在加固一些網(wǎng)絡(luò)服務(wù)時(shí),,還是需要開啟的
1
2 |
#disable selinux sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config |
二. 更換yum的更新源
如果服務(wù)器不是位于教育網(wǎng)內(nèi),中科大的鏡像源速度也很一般啊, 強(qiáng)烈建議整合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 |
三 定時(shí)校正服務(wù)器時(shí)間
作為生產(chǎn)機(jī)的服務(wù)器時(shí)間的準(zhǔn)備性非常重要, 我們需要定時(shí)根據(jù)NTP服務(wù)器時(shí)間自動(dòng)校準(zhǔn)時(shí)間, 全世界各地有很多ntp服務(wù), 我們一般會(huì)選擇當(dāng)?shù)氐姆?wù)器, 但是, 我們要慎重選擇像中國國家授時(shí)中心的標(biāo)準(zhǔn)時(shí)間服務(wù)器(210.72.145.44), 可能是訪問量過大, 造成負(fù)載過大而無法訪問。
推薦使用以下NTP服務(wù)器:
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點(diǎn)15分、6點(diǎn)15分,、12點(diǎn)15分、18點(diǎn)15分與時(shí)間同步服務(wù)器進(jìn)行同步:
1 |
15 0,6,12,18 * * * ntpdate 1.asia.pool.ntp.org |
四. 設(shè)置終端模式(init 3)
1,、vi /etc/inittab
2,、找到id:5:initdefault: 這行
3、將5改為3即可,,即id:3:initdefault:
五 停止網(wǎng)卡對(duì)ipv6的支持
在CentOS默認(rèn)的狀態(tài)下,,ipv6是被啟用的狀態(tài)。因?yàn)槲覀儾皇褂胕pv6,,所以停止ipv6,,以最大限 度保證安全和快速。
#vi /etc/modprobe.conf ← 修改相應(yīng)配置文件,,添加如下行到文尾:
alias net-pf-10 off
alias ipv6 off
六 調(diào)整Linux的最大文件打開數(shù)
Linux最大文件打開數(shù)的默認(rèn)值很低,,必須修改的高一些
vim /etc/security/limit.conf
在最后一行添加
* soft nofile 60000
* hard nofile 65535
值得注意的是,,通過命令ulimit -SHn是改變不了linux系統(tǒng)的最大文件打開數(shù)的,,寫進(jìn)/etc/rc.d/rc.local也是不行的。
七 關(guān)閉不需要的服務(wù)
根據(jù)自己的需要和網(wǎng)絡(luò)上的資料整理了80多個(gè)常見的centos5.6服務(wù)
下載: centos常見服務(wù)優(yōu)化與說明
參考:http://chinaestone./blog/965923
八 TCP性能優(yōu)化
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 |