一、网络优化(编辑/etc/sysctl.conf文件)
vim /etc/sysctl.conf
内容如下:
net.core.somaxconn=50000
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_syncookies=0
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_keepalive_time=1200
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=3
net.ipv4.tcp_max_syn_backlog=8192
net.core.netdev_max_backlog=3000
net.ipv4.ip_local_port_range=1024 65000
net.core.tcp_max_tw_buckets = 5000
net.core.rmem_max=873200
net.core.wmem_max=873200
net.ipv4.tcp_rmem=32768 436600 873200
net.ipv4.tcp_wmem=8192 436600 873200
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_retrans_collapse = 1
net.ipv4.tcp_syn_retries = 5
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_orphan_retries
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_stdurg = 0
net.ipv4.tcp_rfc1337 = 0
net.ipv4.conf.lo.accept_source_route=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.eth0.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.lo.accept_redirects=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.lo.secure_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.eth0.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.conf.lo.send_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.eth0.send_redirects=0
net.ipv4.conf.default.send_redirects=0
kernel.exec-shield = 1
kernel.randomize_va_space = 1
二、执行
/sbin/sysctl -p
三、查看测试(查看其中几个,看看是否修改)
cat /proc/sys/net/ipv4/tcp_tw_recycle
cat /proc/sys/net/core/somaxconn
四、文件打开数
ulimit -n 50000
五、nginx优化
worker_rlimit_nofile 30000;
keepalive_timeout 0;
worker_connections 10240;
六、配置完成之后 使用ab进行压力测试
1.安装ab
yum install -y httpd-tools
安装完成之后 查看版本ab -V
2.测试
ab -c 5000 -n 30000 http://192.168.1.121/index.html
七、配置nginx的状态查看器
1.首先安装请求状态的模块 eg:
./configure –prefix=/usr/local/nginx-1.8.0/ –with-http_stub_status_module
make && make install
2.配置nginx的配置文件nginx.conf
location /status {
stub_status on; #开启这个模块
access_log off; #关闭日记
allow 192.168.1.101; #允许101主机可以访问此链接
deny all; #阻止所有的ip地址
}