Chinaunix首页 | 论坛 | 博客
  • 博客访问: 617181
  • 博文数量: 73
  • 博客积分: 1813
  • 博客等级: 上尉
  • 技术积分: 1213
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-27 19:59
文章分类
文章存档

2013年(1)

2012年(12)

2011年(28)

2010年(31)

2009年(1)

我的朋友

分类: LINUX

2010-05-27 16:06:04

              常用系统命令

 

1.     Vmstat   检测cpu情况

[root@localhost ~]# vmstat 1 4  表示每隔1秒采集1次,共采集4次。

Procs    -----------memory----------    ---swap--    -----io----     --system--     -----cpu------

 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

 0  0   3004 134752  35092 271400    0    0    62   11  1007   30  0  1 98  0  0

 0  0   3004 134752  35092 271400    0    0    0    0  1010   20  0  0 100  0  0

 0  0   3004 134752  35092 271400    0    0    0    0  1004   21  0  0 100  0  0

 0  0   3004 134752  35092 271400    0    0     0    0  1011   19  0  1 99  0  0

 

2.     free 检测内存使用情况

[root@localhost ~]# free

                total       used       free     shared    buffers     cached

Mem:           515444     380692     134752          0      35152     271400

-/+ buffers/cache:  74140     441304

Swap:           522104       3004     519100

 

3.     uptime  查看负载情况,后面三个值表示,些时负载,过去的5分钟平均负载,过去的15分钟平均负载,一般不能大于cpu的个数,如果长时间大于cpu个数,说明系统负载过重,要检查程序了

[root@localhost ~]# uptime

 04:08:21 up  9:09,  3 users,  load average: 0.00, 0.02, 0.00

 

[root@localhost ~]# watch uptime   实时监控负载情况

Every 2.0s: uptime                                                                                              Tue May 25 04:09:58 2010

 

 04:09:58 up  9:10,  3 users,  load average: 0.00, 0.01, 0.00

 

4.     top   对系统进行全面的性能监控,可以一目了然的来查看系统性能,相当于windows的任务管理器。但是此命令同时本身也消耗系统资源,如果系统本身负载很大时,建议不要用此工具。

[root@localhost ~]# top

top - 04:10:41 up  9:11,  3 users,  load average: 0.00, 0.00, 0.00

Tasks:  81 total,   1 running,  80 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:    515444k total,   382036k used,   133408k free,    35504k buffers

Swap:   522104k total,     3004k used,   519100k free,   272044k cached

 

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                   

    1 root      15   0  2064  616  528 S  0.0  0.1   0:01.10 init                                                                      

    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0                                                                

    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                                                               

    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                                                                 

    5 root      10  -5     0    0    0 S  0.0  0.0   0:00.07 events/0                                                                  

    6 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper                                                                    

    7 root      11  -5     0    0    0 S  0.0  0.0   0:00.00 kthread                                                                   

   10 root      10  -5     0    0    0 S  0.0  0.0   0:00.17 kblockd/0                                                                  

   11 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid                                                                    

   72 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue/0                                                                  

   75 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khubd                                                                     

 

5.     netstat  此命令用来查看网络I/O情况,同进可查看端口状态,以及对应的进程,端口状态有以下几种情况:listen  establish  time_wait  close_wait  syn_sent.对于这几种状态情况,可以参看自己博客中的一篇文章。

[root@localhost ~]# netstat -antp

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      2329/hpiod          

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      29315/mysqld       

tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      2029/portmap       

tcp        0      0 0.0.0.0:982                 0.0.0.0:*                   LISTEN      2072/rpc.statd     

tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2404/cupsd         

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2447/sendmail: acce

tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      2334/python        

tcp        0      0 :::22                       :::*                        LISTEN      2372/sshd          

tcp        0      0 ::ffff:192.168.2.150:22     ::ffff:192.168.2.45:3942    ESTABLISHED 29810/2            

tcp        0      0 ::ffff:192.168.2.150:22     ::ffff:192.168.2.45:3666    ESTABLISHED 29703/1            

tcp        0      0 ::ffff:192.168.2.150:22     ::ffff:192.168.2.45:3286    ESTABLISHED 29658/0

 

6.     ps     可查看当前各进程占cpu 与内存情况,还能查看到进程号pid,如果发现有不对头的进程,可以kill掉。

[root@localhost ~]# ps aux  

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root         1  0.0  0.1   2064   616 ?        Ss   May24   0:01 init [3]                             

root         2  0.0  0.0      0     0 ?        S<   May24   0:00 [migration/0]

root         3  0.0  0.0      0     0 ?        SN   May24   0:00 [ksoftirqd/0]

root         4  0.0  0.0      0     0 ?        S<   May24   0:00 [watchdog/0]

root         5  0.0  0.0      0     0 ?        S<   May24   0:00 [events/0]

root         6  0.0  0.0      0     0 ?        S<   May24   0:00 [khelper]

root         7  0.0  0.0      0     0 ?        S<   May24   0:00 [kthread]

root        10  0.0  0.0      0     0 ?        S<   May24   0:00 [kblockd/0]

root        11  0.0  0.0      0     0 ?        S<   May24   0:00 [kacpid]

root        72  0.0  0.0      0     0 ?        S<   May24   0:00 [cqueue/0]

root        75  0.0  0.0      0     0 ?        S<   May24   0:00 [khubd]

root        77  0.0  0.0      0     0 ?        S<   May24   0:00 [kseriod]

 

=================================================================

 

除了以上的常用系统分析工具,还有几个关于网络的命令,大家也可以参考:

 

1.mii-tool  / netstat -i    查看网卡连接情况

 

2.ping        查看连通性

 

3.netstat -r  / ip route show   / route -n   查看路由表

 

4.ifconfig  查看网卡信息

 

5.ip address show dev eth0  查看eth0 ip 信息

 

6.ip address add dev eth0 10.60.32.21/24 给网卡添加ip,并不删除原有ip

 

7.ip address del dev eth0 10.60.32.21/24 删除ip

 

8.ip route add default(表名) dev eth0 via 10.60.32.1 添加默认路由

 

9.ip ro add dev eth0 10.32.60.2 添加发往主机路由

 

10.ip route add dev eth0 172.16.0.0/24 添加发往网段路由

 

11.ip route show table all  查看所有路由表

 

12.ip route add table table1 dev eth0 192.168.0.1 向路由表中添加路由

 

阅读(823) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~