nginx 최적화 와 커 널 최적화 왕 장 ~ ~

7036 단어
nginx 명령 의 최적화 (프로필) [편집]
worker_processes 8;
nginx   ,    cpu     ,       。
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
       cpu,    8      8 cpu,       ,            cpu。
worker_rlimit_nofile 102400;
         nginx              ,             (ulimit -n) nginx     ,  nginx           ,     ulimit -n      。
use epoll;
  epoll I/O  ,       。
worker_connections 102400;
            ,     nginx          worker_processes*worker_connections。
keepalive_timeout 60;
keepalive    。
client_header_buffer_size 4k;
             ,                 ,               1k,              1k,           。         getconf PAGESIZE  。
open_file_cache max=102400 inactive=20s;
            ,        ,max      ,          ,inactive                   。
open_file_cache_valid 30s;
                   。
open_file_cache_min_uses 1;
open_file_cache    inactive              ,        ,               ,   ,        inactive         ,     。

커 널 매개 변수 최적화 [편집]
net.ipv4.tcp_max_tw_buckets = 6000
timewait   ,   180000。
net.ipv4.ip_local_port_range = 1024    65000
           。
net.ipv4.tcp_tw_recycle = 1
  timewait    。
net.ipv4.tcp_tw_reuse = 1
    。   TIME-WAIT sockets      TCP  。
net.ipv4.tcp_syncookies = 1
  SYN Cookies,   SYN       ,  cookies   。
net.core.somaxconn = 262144
web   listen   backlog           net.core.somaxconn   128, nginx   NGX_LISTEN_BACKLOG   511,          。
net.core.netdev_max_backlog = 262144
                           ,               。
net.ipv4.tcp_max_orphans = 262144
         TCP                   。        ,                  。              DoS  ,                 ,        (         )。
net.ipv4.tcp_max_syn_backlog = 262144
                         。   128M       ,    1024,        128。
net.ipv4.tcp_timestamps = 0
             。  1Gbps                。            "  "    。        。
net.ipv4.tcp_synack_retries = 1
         ,        SYN           SYN ACK。                。                 SYN+ACK    。
net.ipv4.tcp_syn_retries = 1
             SYN    。
net.ipv4.tcp_fin_timeout = 1
            ,           FIN-WAIT-2     。              ,      。    60 。2.2        180 ,        ,      ,            WEB   ,                   ,FIN- WAIT-2     FIN-WAIT-1  ,         1.5K  ,          。
net.ipv4.tcp_keepalive_time = 30
 keepalive     ,TCP  keepalive     。   2  。

완전한 커 널 최적화 설정 [편집]
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

간단 한 nginx 최적화 프로필 [편집]
user  www www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000;
error_log  /www/log/nginx_error.log  crit;
pid        /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 204800;

events
{
 use epoll;
 worker_connections 204800;
}

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

 charset  utf-8;

 server_names_hash_bucket_size 128;
 client_header_buffer_size 2k;
 large_client_header_buffers 4 4k;
 client_max_body_size 8m;

 sendfile on;
 tcp_nopush     on;

 keepalive_timeout 60;

 fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
               keys_zone=TEST:10m
               inactive=5m;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 16k;
 fastcgi_buffers 16 16k;
 fastcgi_busy_buffers_size 16k;
 fastcgi_temp_file_write_size 16k;
 fastcgi_cache TEST;
 fastcgi_cache_valid 200 302 1h;
 fastcgi_cache_valid 301 1d;
 fastcgi_cache_valid any 1m;
 fastcgi_cache_min_uses 1;
 fastcgi_cache_use_stale error timeout invalid_header http_500;
 
 open_file_cache max=204800 inactive=20s;
 open_file_cache_min_uses 1;
 open_file_cache_valid 30s;
 


 tcp_nodelay on;
 
 gzip on;
 gzip_min_length  1k;
 gzip_buffers     4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types       text/plain application/x-javascript text/css application/xml;
 gzip_vary on;


 server
 {
   listen       8080;
   server_name  ad.test.com;
   index index.php index.htm;
   root  /www/html/;

   location /status
   {
       stub_status on;
   }

   location ~ .*\.(php|php5)?$
   {
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       include fcgi.conf;
   }

   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
   {
     expires      30d;
   }

   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
   access_log  /www/log/access.log  access;
     }

}

좋은 웹페이지 즐겨찾기