配置sysctl.conf文件修改內核參數

sysctl.conf文件

linux系統中/proc/sys目錄下存放的內核參數,可以在系統運行時進行更改,不過重啓機器後配置就會失效。
由於/proc/sys下內核文件與配置文件sysctl.conf中變量存在着對應關係,在/etc/sysctl.conf文件中修改配置內核參數可以實現永久生效,以下是本人整理的常用參數配置
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1 #開啓路由轉發功能

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1 #當出現SYN等待隊列溢出時,啓用cookies來處理,可防範少量SYN***,默認爲0,表示關閉

# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536

# # Controls the maximum size of a message, in bytes
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 2147483648 #共享內存段的最大尺寸(以字節爲單位),通常設置爲2G

# # Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296 #表示系統一次可以使用的共享內存總量(以頁爲單位)

# TCP kernel paramater
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.tcp_rmem = 4096        87380   4194304 #定義了TCP接受緩存(用於TCP接收滑動窗口)的最小值,默認值,最大值
net.ipv4.tcp_wmem = 4096        16384   4194304 #定義了TCP發送緩存(用於TCP發送滑動窗口)的最小值,默認值,最大值
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1

# socket buffer
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 = 20480
net.core.optmem_max = 81920

# TCP conn
net.ipv4.tcp_max_syn_backlog = 16384 #表示TCP三次握手建立階段接受WYN請求隊列的最大長度,默認1024,將其設置大一些可以使出現Nginx繁忙來不及accept新連接的情況時,Linux不至於丟失客戶端發起的連接請求
net.ipv4.tcp_syn_retries = 3 #在內核放棄建立連接之前發送SYN包的數量
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15

# tcp conn reuse
net.ipv4.tcp_tw_reuse = 1 #允許將TIME-WAIT sockets重新用於新的TCP連接,默認爲0表示關閉
net.ipv4.tcp_tw_recycle = 1 #開啓TCP連接中TIME-WAIT sockets的快速收回功能,默認爲0,表示關閉
net.ipv4.tcp_fin_timeout = 1 #表示當服務器主動關閉連接時,socket保持在FIN-WAIT-2狀態的最大時間

net.ipv4.tcp_max_tw_buckets = 20000 #表示操作系統允許TIME_WAIT套接字數量的最大值,如果超過這個數字,TIME_WAIT套接字將立刻被清除並打印警告信息。默認是180000,過多TIME_WAIT套接字會使Web服務器變慢
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_timestamps = 1 #?
net.ipv4.tcp_synack_retries = 1 #減少系統SYN連接重試次數,默認是5
net.ipv4.tcp_syncookies = 1

# keepalive conn
net.ipv4.tcp_keepalive_time = 300 #這個參數表示當keepalive啓用時,TCP發送keepalive消息的頻度。默認是7200 seconds,意思是如果某個TCP連接在idle 2小時後,內核才發起probe。若將其設置得小一點,可以更快地清理無效的連接
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.ip_local_port_range = 10001    65000 #定義了在UDP和TCP連接中本地端口的取值範圍

# swap
vm.overcommit_memory = 0
vm.swappiness = 10

#net.ipv4.conf.eth1.rp_filter = 0
#net.ipv4.conf.lo.arp_ignore = 1
#net.ipv4.conf.lo.arp_announce = 2
#net.ipv4.conf.all.arp_ignore = 1
#net.ipv4.conf.all.arp_announce = 2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章