zoukankan      html  css  js  c++  java
  • nginx php 优化

    一、nginx优化

         use epoll (那是肯定的)

         worker_rlimit_nofile 65535 (增加nginx打开文件描述符数)

      fastcgi_connect_timeout 300s;(这三条能有效的避免504错误)

      fastcgi_send_timeout 300s;

      fastcgi_read_timeout 300s;

          fastcgi_pass  unix:/tmp/php.socket (fast-cgi转发使用unix socket而不是用端口)

         使用php-fpm而不是swawn-cgi

    二、linux内核优化

       1、 ulimit -n 65535 (打开文件描述符数,注意只对本次root登录有效,想要永久生效 vim /etc/profile 在里面加上该命令 ,注意编辑后 source /etc/profile)

       2、 vim /etc/security/limits.conf,增加 

        * soft nofile 65535
        * hard nofile 65535

          其实作用是跟ulimit -n 效果一样的

       3、vim /etc/sysctl.conf

           net.ipv4.tcp_max_tw_buckets = 6000  (减少time_wait的数量,免得拖死服务)

           net.ipv4.tcp_tw_recycle = 1 (快速回收time_wait)

           net.ipv4.tcp_tw_reuse = 1 (重用time_wait)

       net.core.somaxconn = 511 (linux的核心函数listen优化,参见http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/023/2333/2333s2.html

      net.ipv4.tcp_max_syn_backlog = 8192 (SYN_RECV状态队列的数量,一般默认值为512或者1024,即超过这个数量,系统将不再接受新的TCP连接请求,一定程度上可以防止系统资源耗尽。可根据情况增加该值以接受更多的连接请求。)

          net.ipv4.tcp_syncookies = 1 (表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;)

          修改成功后运行 /sbin/sysctl -p即可生效

     4、修改 /proc/sys/net/core/somaxconnn

           echo 8192 > /proc/sys/net/core/somaxconn (改成8192)

          具体说明可以在linux 下执行 man listen ,然后参照https://computing.llnl.gov/linux/slurm/high_throughput.html

          简单来说就是增加连接请求队列的长度 :The  backlog  parameter defines the maximum length the queue of pending connections may grow to.

          

          

  • 相关阅读:
    vSphere笔记01~02
    【科普】人眼到底等于多少像素
    《标题党》自我修炼的10个秘籍
    说说云盘背后的黑科技!
    用shell批量编码转换
    Java课设--俄罗斯方块Tetris
    教程,Python图片转字符堆叠图
    谈谈索引的哲学思想
    MySQL索引实战经验总结
    博客要转型啦
  • 原文地址:https://www.cnblogs.com/sky20081816/p/3118600.html
Copyright © 2011-2022 走看看