- 论坛徽章:
- 0
|
本帖最后由 dynamiclu 于 2012-05-24 15:12 编辑
下面这些是我在平时工作中,不断整理出来的,非常实用的linux系统命令
系统相关:
1.cat /proc/cpuinfo ##查看CPU的核数
2.cat /proc/version ##查看linux版本
3.ulimit -n ##显示当前文件描述符
4.ulimit -HSn 65536 ##修改当前用户环境下的文件描述符为65536
5.getconf LONG_BIT ##查看linux系统的位数,是32或还是64, 较实用
6.lsof ##列出当前系统打开文件, 特实用,可grep出你的进程或软件正在操作什么文件
7.ps -eLf | grep java | wc -l ##查看java的线程数,如果是单个java容器,就指这个容器的,多个指所有的总数
8.cat /etc/resolv.conf ##DNS域名解析的配置文件, 内部DNS用得多的系统经常使用
9.cat /etc/hosts ##查看host配置
连接状态:
(1). netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn 或
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}' ##查看各tcp连接各状态的连接情况
(2). netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n30 ##查找80端口请求连接量最大的前30个IP(常用于查找攻来源,爬虫分析)
(3). netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n10 ##查找time_wait状态连接量前10
(4). netstat -nat -n | awk -F: '/tcp/{a[$(NF-1)]++}END{for(i in a)if(a>5)print i}' ##查询同时连接量大于5个连接的端口和IP
网站日志分析(apache或nginx):
1). cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10 #取10,按量的倒序排 或cat access.log|awk '{counts[$(1)]+=1}; END {for(url in counts) print counts[url], url}'
##获得访问次数前10位的ip地址,具体print出来的第几项,还需要看log_format,那项是$remote_addr
2).cat access.log |awk '{print $10}'|sort|uniq -c|sort -nr|head -10 ##访问次数最多的文件或页面,取前10 还需要看log_format,第10项为页面
3).cat access.log |awk '{print $1}'|grep 'article.html' sort|uniq -c|sort -nr|head -10 ##查询文章页访问次数最多的前个IP
4).awk '($9 ~/404/)' access.log | awk '{print $9,$10}' | sort ##统计404的情况
5).cat access.log |awk '($NF > 10){print $NF " "$1" "$10 }'|sort -nr|head -30 ##查出前30个访问时间超过10秒的请求, 包括请求时间、IP、页面 |
|