2020年4月27日

Linux TCP 連線數優化Script

Linux TCP 連線數優化Script如下

#!/bin/sh
#TCP Setting Tuning
sysctl -w net.core.rmem_max=33554432
sysctl -w net.core.wmem_max=33554432
sysctl -w net.ipv4.tcp_rmem='4096 87380 33554432'
sysctl -w net.ipv4.tcp_wmem='4096 65536 33554432'
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.tcp_mem='50576 64768 98152'
sysctl -w net.core.netdev_max_backlog=2500
sysctl -w net.netfilter.nf_conntrack_max=1048576
sysctl -p
if cat /etc/sysctl.conf | grep "net." ; then
  echo "tcp tuning is exist"
else
  echo "net.core.rmem_max = 33554432" >> /etc/sysctl.conf
  echo "net.core.wmem_max = 33554432" >> /etc/sysctl.conf
  echo "net.ipv4.tcp_rmem = 4096 87380 33554432" >> /etc/sysctl.conf
  echo "net.ipv4.tcp_wmem = 4096 65536 33554432" >> /etc/sysctl.conf
  echo "net.ipv4.tcp_syncookies = 1" >> /etc/sysctl.conf
  echo "net.ipv4.tcp_mem = 50576 64768 98152" >> /etc/sysctl.conf
  echo "net.core.netdev_max_backlog = 10000 " >> /etc/sysctl.conf
  echo "net.core.somaxconn=10000 " >> /etc/sysctl.conf
  echo "net.netfilter.nf_conntrack_max = 1048576" >> /etc/sysctl.conf
fi
#Maximum TCP Session
if cat /etc/security/limits.conf | grep "soft nproc" ; then
  echo "tcp session setting is exist"
else
  echo "* soft nproc 10000" >> /etc/security/limits.conf
  echo "* hard nproc 10000" >> /etc/security/limits.conf
  echo "* soft nofile 5000" >> /etc/security/limits.conf
  echo "* hard nofile 5000" >> /etc/security/limits.conf
fi

(繼續閱讀...)

Copyright © 2009 New Life in Taipei All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.