网站
- http://man.linuxde.net/
- http://www.commandlinefu.com/
- https://www.kernel.org/doc/man-pages/
- 命令行的艺术:https://github.com/jlevy/the-art-of-command-line/blob/master/README-zh.md
- 高级Bash脚本编程指南
- Command Substitution
文章
- http://www.linuxvirtualserver.org/zh/lvs1.html
- http://www.brendangregg.com/linuxperf.html
- Computer Science from the Bottom Up:https://www.bottomupcs.com/
- Linux常用命令知识积累:http://siye1982.github.io/2016/02/25/linux-list/
- 如何用十条命令在一分钟内检查Linux服务器性能:http://www.infoq.com/cn/news/2015/12/linux-performance
**内存**
VSS/RSS/PSS/USS:http://www.cnblogs.com/tekkaman/p/4031427.html
命令
查看进程打开的句柄数并进行排序
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
其中第一列是打开的句柄数,第二列是进程ID
统计某个端口的连接数
netstat -an | grep -i "36081" | wc -l
显示网络端口以及进程id
netstat -tulpn
统计TCP状态
netstat -pant | awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s\t%d\n",key,state[key]) }'
iptables 只允许特定ip访问指定端口:
查看当前规则:
iptables -L -n
设置访问规则:
iptables -I INPUT -p tcp --dport 9200 -j DROP
iptables -I INPUT -s 192.168.1.1 -p tcp --dport 9200 -j ACCEPT
iptables -I INPUT -i lo -p tcp --dport 9200 -j ACCEPT
iptables -I INPUT -s 192.168.1.1 -p tcp --dport 9200 -j ACCEPT
保存当前规则:
/etc/rc.d/init.d/iptables save
service iptables restart
vim /etc/sysctl.conf
net.ipv4.tcp_max_tw_buckets = 600000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 10240
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_keepalive_time = 1200
sysctl -p
杀死进程
ps -ef| grep Node|grep -v grep|awk '{print $2}'|xargs kill -9
部署项目脚本
#!/usr/bin/expect
set timeout 30
spawn ssh root@192.168.1.250
expect "*password*"
send "passwd123\r"
expect "*#*"
send "cd /ntocc/tomcat/\r"
send "./bin/shutdown.sh\r"
sleep 1
send "./bin/stop.sh\r"
expect "*SUCCESS*"
#send "rm -f webapps/txt-server-http.war;rm -rf webapps/txt-server-http;\r"
#expect "*#"
spawn scp server-web/target/web.war root@192.168.1.186:/server-web
expect "*password*"
send "passwd123\r"
expect "*100%*"
spawn ssh root@192.168.1.186
expect "*password*"
send "passwd123\r"
expect "*#*"
#解压war包
send "cd /server-web\r"
send "jar xvf web.war\r"
send "rm -rf web.war\r"
#启动Tomcat
send "cd /server-web/tomcat\r"
send "./bin/startup.sh;tail -f logs/catalina.out -n 0\r"
expect "org.apache.catalina.startup.Catalina.start Server startup"
exit
SSH自动连接
//生成SSH公钥和私钥
ssh-keygen -t rsa
//修改端口号
vim /etc/ssh/sshd_config
/etc/init.d/ssh reboot
//将公钥添加到服务器
cat ~/.ssh/id_rsa.pub | ssh root@192.168.1.1 -p 122 "cat >> ~/.ssh/authorized_keys"
//设置Shell别名
alias dev='ssh admin@192.168.1.1 -p 222'