现在的位置: 首页 > 综合 > 正文

Linux服务器维护常用命令

2013年10月07日 ⁄ 综合 ⁄ 共 1288字 ⁄ 字号 评论关闭
文章目录

 原贴:

Linux服务器维护常用命令

2009年1月11日

实时查看正在执行的sql语句

/usr/sbin/tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings |
egrep -i
‘SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL’

查看http连接

netstat -n | awk ‘/^tcp/ {++state[$NF]} END {for(key in state) print key,”t”,state[key]}’

查看SYN状态的http连接

netstat -an | grep SYN | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort | uniq -c | sort -nr | more

查看TIME_WAIT状态的http连接

netstat -tna | cut -b 49- |grep TIME_WAIT | sort |more
netstat -an | grep TIME_WAIT | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort | uniq -c | sort -nr | more

查看ESTABLISHED状态的http连接

netstat -an | grep ESTABLISHED | awk ‘{print $5}’ | awk -F: ‘{print $1}’ | sort | uniq -c | sort -nr | more
netstat -an | grep “:80″ | grep ESTABLISHED | sort | more

批量kill进程

ps -efww|grep sqlr-listener|grep -v grep|cut -c 9-15|xargs kill -9

查看活动的php-cgi连接数

netstat -anpo|grep php-cgi|wc -l

按ip查看httpd连接数

netstat -anlp | grep 80 | grep tcp | awk {’print $5′} | awk -F: {’print $1′}| sort |uniq -c | sort -nr

禁IP

iptables -A INPUT -s IP地址 -j REJECT
iptables -A INPUT -s IP地址/24 -j REJECT

route add -net IP地址 netmask 255.255.255.0 reject

调试命令

strace -p pid

跟踪指定的进程pid.

gdb -p pid

跟踪指定的进程pid.

批量查找文件并删除

find . -name test.php -exec rm {} ;
find . -name test.php | xargs rm -rf

更改某一目录下所有目录的权限, 不包括文件, aaa 是目录名

find aaa -type d -exec chmod 755 {} ;

替换文件内容

sed -i ’s/b/strong/g’ index.html

此命令搜索 index.html 文件中的 b 并将其替换为 strong。

Linux

 

抱歉!评论已关闭.