博主不是专业的运维人员, 有时候新开业务服务器到生产环境忘记配置ubuntu的配置时候,就发生各种奇怪的悲剧比如:
redis出现大量TIMEWAIT状态,并且服务器不会收,原因是tcp_tw_recycle配置为0等等。为避免遗忘记录下新开的服务器必要的操作:
ubuntu网络优化
vi /etc/sysctl.conf
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 2000 65000
net.ipv4.tcp_max_tw_buckets = 6000
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.somaxconn = 2048
net.ipv4.tcp_mem = 94500000 915000000 927000000
-------------------------------
另一个优化:
net.core.rmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_default = 262144
net.core.wmem_max = 16777216
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_mem = 786432 1048576 1572864
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
vm.swappiness = 10
============================================
/sbin/sysctl -p
修改ubuntu打开文件数量
vim /etc/security/limits.conf
root soft nofile 102400
root hard nofile 102400
* soft nofile 102400
* hard nofile 102400
vi /etc/profile
ulimit -SHn 102400