欢迎光临
我们一直在努力

linux nginx 高并发配置

直接贴配置

1、linux 内核配置 net.core 如下

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000


//linux 内核配置   vi /etc/sysctl.conf    sysctl -p



net.core.somaxconn = 65535
net.core.rmem_default = 8388608
net.core.wmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_syncookies = 0
net.ipv4.ip_local_port_range = 1024 65535

2、关于nginx的配置项 nginx.conf 配置如下


user  root;
worker_processes    16;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 65535;

events {
    use epoll;
    worker_connections 65535;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
	
    sendfile    on;
    tcp_nopush on;
    tcp_nodelay on; 
    fastcgi_buffers 16 256k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    server_names_hash_bucket_size 256;
    client_header_buffer_size 64k;
    large_client_header_buffers 16 64k;
    client_max_body_size 16m;
    keepalive_timeout  60;
	
    upstream yktxwfxService{
	  server 192.168.132.60:8091 weight=1 ;
	  server 192.168.132.61:8091 weight=1 ;
          server 192.168.132.62:8091 weight=1 ;
	  server 192.168.132.63:8091 weight=1 ;
	  server 192.168.132.64:8091 weight=1 ;
	  server 192.168.132.65:8091 weight=1 ;
	  server 192.168.132.66:8091 weight=1 ;
	  server 192.168.132.67:8091 weight=1 ;
    }
    #gzip  on;

    #include /etc/nginx/conf.d/*.conf;

    server {
     listen      80;
     server_name  localhost;

     #charset koi8-r;
     #access_log  /var/log/nginx/host.access.log  main;

     location / {
        proxy_buffer_size 256k;
        proxy_buffers 32 128k;
        proxy_busy_buffers_size 512k;
        proxy_read_timeout 200;
        proxy_pass   http://yktxwfxService;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        #root   /usr/share/nginx/html;
        #index  index.html index.htm;
     }

     #error_page  404              /404.html;

     # redirect server error pages to the static page /50x.html
     #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
        root   /usr/share/nginx/html;
     }

     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     #
     #location ~ \.php$ {
     #    proxy_pass   http://127.0.0.1;
     #}

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     #location ~ \.php$ {
     #    root           html;
     #    fastcgi_pass   127.0.0.1:9000;
     #    fastcgi_index  index.php;
     #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     #    include        fastcgi_params;
     #}

     # deny access to .htaccess files, if Apache's document root
     # concurs with nginx's one
     #
     #location ~ /\.ht {
     #    deny  all;
     #}
    }

}

3、linux 系统连接以及打开文件最大限制修改

linux 默认值 open files 和 max user processes 为1024
通过以下命令可以查看
#ulimit -n
1024
#ulimit –u
1024

可以直接通过  ulimit –n 65535  ulimit –u 65535 进行即时修改
但是重启后无效   

赞(0) 打赏
未经允许不得转载:彬的博客 » linux nginx 高并发配置
分享到: 更多 (0)

评论 抢沙发

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

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏