• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

nginx性能实战优化

未分类 小杰 4年前 (2016-06-06) 555次浏览 已收录 0个评论

链接超时问题:
nginx 上 tcp参数优化了下


vi /etc/sysctl.conf

time_wait尽快释放和重用


net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

然后执行 /sbin/sysctl -p 让参数生效。

用于统计当前各种状态的连接的数量的命令

—————————

#netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}’

修改nginx子网站的配置

/usr/local/nginx/conf/vhost

nginx -s reload

连接数太多报错: [error] 13475#0: *16378 connect() to unix:/tmp/php-cgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream,

解决方法:修改配置文件

vi ./usr/local/php/etc/php-fpm.conf

[www]
listen = /tmp/php-cgi.sock
listen.backlog = 4096
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 1024
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 1024
request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = var/log/slow.log

重启下
/etc/init.d/php-fpm restart


原始配置:

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log




小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:nginx性能实战优化
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址