linux nginx 内核优化,(推荐)linux之nginx高并发配置及网络优化

一、网络优化(编辑/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地址

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值