#####################################################system 优化
1增大系统连接数:ulimit -SHn 65535,如果不生效vi /etc/security/limits.conf文件最后加上
* soft nofile 65535
* hard nofile 65535
解决方法:
使用 ulimit –n 65535 可即时修改,但重启后就无效了。(注ulimit -SHn 65535 等效 ulimit -n 65535 ,-S 指soft ,-H 指hard)
有如下三种修改方式:
在/etc/rc.local 中增加一行 ulimit -SHn 65535
2. 在/etc/profile 中增加一行 ulimit -SHn 65535
3.在/etc/security/limits.conf 最后增加:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
具体使用哪种,在 CentOS 中使用第1 种方式无效果,使用第3 种方式有效果,而在Debian 中使用第2 种有效果
3 发现存在大量 TIME_WAIT 状态的连接
问题描述: 发现大量 time_wait 状态的连接 , 有时甚至达到 7000 以上
netstat n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t",state[key]}'
查找较多 time_wait 连接
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20
发现是 DB 服务器的 mysql 和 memcache 的未释放导致。
建议:在 PHP程序开发时,建议大家尽量 mysql_close,减少 msyql消耗。
解决方法: 对于大量使用 tcp 连接的应用来说,也需要对 /etc/sysctl.conf 中的参数进行相应优化 :vim /etc/sysctl.conf
编辑文件,加入以下内容:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw