Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
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
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ