Socket优化
lsof -p pid |wc -l 查看系统占用
我们可以通过ulimit –n命令来查看最大文件打开数,如下:
32768
一般情况下是1024,我系统已经改为了32768。
修改/etc/security/limits.conf /etc/security/limits.d/90-nproc.conf
通过 vi /etc/security/limits.conf and /etc/security/limits.d/90-nproc.conf 修改其内容,在文件最后加入(数值也可以自己定义):
cat <<EOF >>/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
EOF
/etc/security/limits.d/90-nproc.conf
root soft nproc 102400
root hard nproc 102400
mysql soft nproc 102400
mysql hard nproc 102400
* soft nproc 32768
修改/etc/pam.d/login
vi /etc/pam.d/login
在后面加上
session required /lib64/security/pam_limits.so
然后重新登录即可生效了。
Tcp优化 试用于 nginx 和socket服务器
vi /etc/sysctl.conf
vm.overcommit_memory = 1
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.ipv4.tcp_max_syn_backlog = 65536
fs.file-max =9553600
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_probes = 2
net.ipv4.tcp_keepalive_intvl = 2
net.nf_conntrack_max=6553600
net.netfilter.nf_conntrack_max=6553600
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
sysctl -p 执行生效
报错:
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
解决方法如下:
modprobe bridge
echo "modprobe bridge" >>/etc/rc.local
linux 优化 http://www.netkou.cn/?post=118