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

2020年2月9日

BGP Looking Glass Server

日常的工作需要Looking Glass 加快查修問題的速度,除了BGP網路外,還有一般的專線跟上網線路,都會需要類似BGP Looking Glass Server的功能,想把它整合成統一的Ping Server,目前使用了Open Source的BGP Looking Glass程式,再稍微修改一下程式後,就可以達到想要的功能,以下為在CentOS上面建置的方式

Step 1:先到https://github.com/Cougar/lg ,先照網站上面的介紹,捉取程式
yum install git
git config --global url."https://".insteadOf git://
git clone https://github.com/Cougar/lg.git

Step 2:安裝必要的環境程式
yum install wget perl-Net-Telnet perl-Net-Telnet-Cisco perl-XML-Parser httpd
yum install gcc* perl-CPAN
yum install perl*
yum install mtr
yum install perl-DB_File
安裝perl的外掛,要用cpanm 安裝,後面CGI程式會到用,沒安裝會無法執行主程式,會一直跳Perl執行錯的error log
cpanm Net::SSH::Perl
cpanm Net::Telnet::Perl

Step 3:將git捉下來的程式放到WEB執行的目錄,並設定好對應的Apache的權限
mkdir /var/www/html/lg
cd /var/www/html/lg
cp /root/lg-1.9/lg.cgi .
cp /root/lg-1.9/favicon.ico .
cp /root/lg-1.9/lg.conf .