sysctl.conf的優化

內核參數sysctl.conf的優化

安裝的Centos5.5_x86_64原來的sysctl.conf如下

#cat /etc/sysctl.conf |grep -v '^$' |grep -v '#'

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 = 4294967295

kernel.shmall = 268435456

在最後面添加如下參數

fs.file-max = 6553600

kernel.shmmni = 4096

kernel.sem = 250 32000 100 128

net.ipv4.ip_local_port_range = 1024 65536

net.core.rmem_default = 16777216

net.core.rmem_max=16777216

net.core.wmem_default = 16777216

net.core.wmem_max=16777216

net.ipv4.tcp_rmem=4096 87380 16777216

net.ipv4.tcp_wmem=4096 65536 16777216

net.ipv4.tcp_fin_timeout = 15

net.ipv4.tcp_keepalive_time = 600

net.ipv4.tcp_tw_recycle = 1

net.core.netdev_max_backlog = 30000

net.ipv4.tcp_no_metrics_save=1

net.core.somaxconn = 262144

net.ipv4.tcp_max_orphans = 8000

net.ipv4.tcp_max_syn_backlog = 8000

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

 

運行sysctl -p,使配置生效

這裏的"fs.file-max = 6553600"其實是由"fs.file-max = 512 * PROCESSES"得到的,我們指定PROCESSES的值爲12800,即爲"fs.file-max =512 *12800"

kernel.shmmax:表示單個共享內存段的最大值,以字節爲單位,此值一般爲物理內存的一半,不過大一點也沒關係,這裏設定的爲4GB,即"4294967295/1024/1024/1024=4G"

kernel.shmmni:表示單個共享內存段的最小值,一般爲4kB,即4096bit

kernel.shmall:表示可用共享內存的總量,單位是頁,在32位系統上一頁等於4kB,也就是4096字節

fs.file-max:表示文件句柄的最大數量。文件句柄表示在Linux系統中可以打開的文件數量。

ip_local_port_range:表示端口的範圍,爲指定的內容。

kernel.sem:表示設置的信號量,這4個參數內容大小固定。

net.core.rmem_default:表示接收套接字緩衝區大小的缺省值(以字節爲單位)。

net.core.rmem_max :表示接收套接字緩衝區大小的最大值(以字節爲單位)

net.core.wmem_default:表示發送套接字緩衝區大小的缺省值(以字節爲單位)。

net.core.wmem_max:表示發送套接字緩衝區大小的最大值(以字節爲單位)。

net.ipv4.tcp_fin_timeout: 減少處於FIN-WAIT-2連接狀態的時間,使系統可以處理更多的連接

net.ipv4.tcp_keepalive_timekeepalive打開的情況下,TCP發送keepalive消息的頻率。

net.ipv4.tcp_tw_recycle加速TIME-WAIT sockets回收

net.core.netdev_max_backlog每個網絡接口接收數據包的速率比內核處理這些包的速率快時,允許送到隊列的數據包的最大數目

net.ipv4.tcp_no_metrics_save

net.core.somaxconn系統同時發起連接的tcp連接

net.ipv4.tcp_max_orphans系統所能處理不屬於所有進程的TCP sockets最大數量

net.ipv4.tcp_max_syn_backlog對於那些依然還未獲得客戶端確認的連接請求?需要保存在隊列中最大數目(默認1024),增加此參數能夠比較有效的緩解小規模的SYN Flood***

net.ipv4.tcp_synack_retries tcp第二次握手中,決定內核在放棄連接之前所送出的 SYN+ACK 數目(默認值是5)減小此參數可以防禦DDOS***

net.ipv4.tcp_syn_retries  對於一個新建tcp連接,內核要發送多少個 SYN 連接請求才決定放棄(默認值是5)減小此參數可以防禦DDOS***

 

#取消 ICMP 接受 Redirect

net.ipv4.conf.lo.accept_redirects=0

net.ipv4.conf.all.accept_redirects=0

net.ipv4.conf.eth0.accept_redirects=0

net.ipv4.conf.default.accept_redirects=0

net.ipv4.conf.lo.accept_source_route=0

net.ipv4.conf.all.accept_source_route=0

net.ipv4.conf.eth0.accept_source_route=0

net.ipv4.conf.default.accept_source_route=0

net.ipv4.conf.lo.accept_redirects=0

net.ipv4.conf.all.accept_redirects=0

net.ipv4.conf.eth0.accept_redirects=0

net.ipv4.conf.default.accept_redirects=0

net.ipv4.conf.lo.secure_redirects=0

net.ipv4.conf.all.secure_redirects=0

net.ipv4.conf.eth0.secure_redirects=0

net.ipv4.conf.default.secure_redirects=0

net.ipv4.conf.lo.send_redirects=0

net.ipv4.conf.all.send_redirects=0

net.ipv4.conf.eth0.send_redirects=0

net.ipv4.conf.default.send_redirects=0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章