2016/09/03

Linux Command Backup Part 1

Check System Memory Usage...
free -h

Check System Disk Usage...
df -h

Clean System Memory Cache...
sync; sudo echo 3 > /proc/sys/vm/drop_caches

List TCP Port 80
netstat -an | grep :80 | sort

Count TCP Port 80 Connection
netstat -n | grep :80 | wc -l

List Client IP TCP Port 80 Connection
netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1


Check Some Linux Network Settings...
sysctl net.ipv4.ip_local_port_range
sysctl net.ipv4.tcp_fin_timeout
sysctl net.ipv4.tcp_tw_recycle
sysctl net.ipv4.tcp_tw_reuse
sysctl net.core.somaxconn
sysctl net.ipv4.tcp_max_syn_backlog

Set Linux Network Settings...
sysctl net.ipv4.ip_local_port_range="1024 65535"
sysctl net.ipv4.tcp_fin_timeout=30
sysctl net.ipv4.tcp_tw_recycle=1
sysctl net.ipv4.tcp_tw_reuse=1
sysctl net.core.somaxconn=2048
sysctl net.core.netdev_max_backlog=2000
sysctl net.ipv4.tcp_max_syn_backlog=2048
sysctl -p

Compute Apache2 MaxClients number
tomeg=$(free -h | grep -i mem | awk '{print $2}')
tomem=$(free -m | grep -i mem | awk '{print $2}')
htps=$(ps -ylC apache2 |grep "apache2" |awk '{print $8'} |sort -n |tail -n 1)
of=$(ps aux | grep 'java' | awk '{print $6}' |sort -n |tail -n 1)
mysme=$(ps aux | grep 'mysqld' | awk '{print $6}' |sort -n |tail -n 1)
mb=1024
gb=1024000
nmysme=$(expr $mysme / $mb)
nhtps=$(expr $htps / $mb)
nofg=$(expr $of / $gb)
nofm=$(expr $of / $mb)
echo -e "\nTotal Memory Size = $tomeg"
echo -e "Largest apache2 Process = $nhtps"M
echo -e "Mysql Memory Usage = $nmysme"M
echo -e "Openfire Memory Usage = $nofg"G
maxc=`expr $tomem - $nmysme - $nofm`
maxcl=`expr $maxc / $nhtps`
echo -e "\nSo, The MaxClients = $maxcl"
echo -e "(we can use nearest round of value from $maxcl)"

沒有留言:

張貼留言