nginx內核調優

1.修改查詢單個用戶對文件描述符的使用限制,即打開文件的個數
2.修改查詢單個用戶最多擁有的進程數,即一個用戶全部打開的最大進程數nginx

[root@localhost security]# egrep -v '^$|^#' limits.conf web

  • soft nofile 65536
  • hard nofile 65536
  • soft nproc 65536
  • hard nproc 65536

注意:重啓生效。服務器

[root@localhost ~]# ulimit -u
65536
[root@localhost ~]# ulimit -n
65536cookie

優化內核:
/etc/sysctl.conf
默認配置:
net.ipv4.tcp_max_tw_buckets = 8192
net.ipv4.ip_local_port_range = 32768 60999
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 128
net.core.netdev_max_backlog = 1000
net.ipv4.tcp_max_orphans = 8192
net.ipv4.tcp_max_syn_backlog = 128
net.ipv4.tcp_synack_retries = 5
net.ipv4.tcp_syn_retries = 6
net.ipv4.tcp_fin_timeout = 60
net.ipv4.tcp_keepalive_time = 7200socket

修改後的配置:
[root@localhost etc]# sysctl -p
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30tcp

註解:
net.ipv4.tcp_max_tw_buckets = 6000
設置timewait的值
net.ipv4.ip_local_port_range = 1024 65000
設置系統容許打開的端口範圍值
net.ipv4.tcp_tw_recycle = 1
用於設置是否啓用timeout快速回收
net.ipv4.tcp_tw_reuse = 1
設置是否開啓從新使用,即容許將TIME-WAIT sockets從新用於新的TCP鏈接
net.ipv4.tcp_syncookies = 1
是否啓用syncookies。若是啓用,當出現syn等待隊列溢出,則使用coookie來處理
net.core.somaxconn = 65535
web應用中listen函數的backlog。nginx定義的NGX_LISTEN_BACKLOG
net.core.netdev_max_backlog = 262144
設置被傳輸到隊列數據包的最大數目,在網卡接收數據包的速率比內核處理數據包的速率快時,那麼會出現排隊現象,這個參數用於設置這個隊列的大小
net.ipv4.tcp_max_orphans = 262144
設置Linux可以處理不屬於任何進程的套子節數量,所謂不屬於任何進程的進程就是孤兒進程。在快速、大量的鏈接中這種進程會不少,所以要適當設置,若是這種"孤兒"進程套接字數量大於這個指定的值,使用dmesg查看是會出現"too many of orphands sockes"的警告
net.ipv4.tcp_max_syn_backlog = 262144
記錄還沒有接收到客戶端確認信息的鏈接請求的最大值
net.ipv4.tcp_synack_retries = 1
用於設置SYN重試的次數,在TCp的3次握手中的第二次握手,內核須要發送一個迴應前面一個SYN的ACK的SYN。就是說爲了打開對方的鏈接,內核發出的SYN的次數。減小該參數有利於避免DDOS***
net.ipv4.tcp_syn_retries = 1
設置在內核放棄創建鏈接以前發送SYN包的數量
net.ipv4.tcp_fin_timeout = 1
表示若是套接字由本段要求關閉,這個參數決定了它保持在FIN_WAIT_2狀態的時間。對端能夠出錯並永遠不關閉鏈接,甚至之外宕機。能夠按此設置,但要記住的是,即便是一個輕載的web服務器,也有由於大量的死套接字而內存溢出的風險,FIN-WAIT-2的危險性比FIN-WAIT-1要小,由於它嘴都只能消耗1.5KB的內存,可是它的生存期要長一些。
net.ipv4.tcp_keepalive_time = 30
當啓用keeplive的時候,改參數用於設置TCP發送keeplive消息的頻度ide

相關文章
相關標籤/搜索