网站


文章


命令


查看进程打开的句柄数并进行排序

  1. lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
  2. 其中第一列是打开的句柄数,第二列是进程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'

内核

  1. https://github.com/shihyu/linux_kernel_driver/tree/master/Books
  2. http://www.oldlinux.org/
  3. Linux 漫画 https://jvns.ca/zines/ https://drawings.jvns.ca/
  4. https://wizardzines.com/