guo20082200的个人博客分享 http://blog.sciencenet.cn/u/guo20082200

博文

linux_centos 第20次课 linux的日常管理

已有 2813 次阅读 2015-8-27 23:31 |个人分类:Linux学习|系统分类:科研笔记|关键词:学者

20次课 linux日常管理

[root@ghq~]# w

00:29:31 up  5:09, 3 users,  load average: 0.00,0.00, 0.00

USER     TTY     FROM              LOGIN@   IDLE  JCPU   PCPU WHAT

root     tty1    :0               19:20    5:09m 23.87s 23.87s /usr/bin/Xorg :

root     pts/0   :0.0             19:21    2:08m 0.01s  0.01s bash

root     pts/1   192.168.182.1    22:21    0.00s 0.30s  0.24s w

 

[root@ghq pub]# uptime

07:04:39 up 4 min,  3 users, load average: 0.09, 0.28, 0.15

 

CPU是怎么运作的?

[root@ghq pub]# top  退出按q

 

Shift+M  shift >   shift <

 

[root@ghq pub]# top -bn1  (显示所有的进程,不是动态的,可以写进脚本)

 

[root@ghq pub]# vmstat

procs-----------memory---------- ---swap-- -----io------system-- -----cpu-----

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

 0  0     0 664896 24140 167860   0    0   112    10   82  128  1  2 95 2  0

 

[root@ghq pub]# iostat

Linux2.6.32-431.el6.i686 (ghq)        08/27/2015      _i686_  (1 CPU)

 

avg-cpu:  %user  %nice %system %iowait  %steal   %idle

          0.84    0.00   1.67    1.03    0.00  96.46

 

Device:            tps   Blk_read/s  Blk_wrtn/s   Blk_read   Blk_wrtn

sda               3.08       147.08        14.85     382016     38562

sdb               0.25         1.75         0.00       4552          0

 

[root@ghq pub]# yum install -y iotop

[root@ghqpub]# iotop  (类似命令top

TotalDISK READ: 0.00 B/s | Total DISK WRITE: 0.00 B/s

 

[root@ghq pub]# strace  (命令strace

usage:strace [-dDffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file]

             [-p pid] ... [-s strsize] [-uusername] [-E var=val] ...

             [command [arg ...]]

  or: strace -c [-D] [-e expr] ... [-Ooverhead] [-S sortby] [-E var=val] ...

             [command [arg ...]]

-c-- count time, calls, and errors for each syscall and report summary

-f-- follow forks, -ff -- with output into separate files

-F-- attempt to follow vforks, -h -- print help message

-i-- print instruction pointer at time of syscall

-q-- suppress messages about attaching, detaching, etc.

-r-- print relative timestamp, -t -- absolute timestamp, -tt -- with usecs

-T-- print time spent in each syscall, -V -- print version

-v-- verbose mode: print unabbreviated argv, stat, termio[s], etc. args

-x-- print non-ascii strings in hex, -xx -- print all strings in hex

-acolumn -- alignment COLUMN for printing syscall results (default 40)

-eexpr -- a qualifying expression: option=[!]all or option=[!]val1[,val2]...

  options: trace, abbrev, verbose, raw,signal, read, or write

-ofile -- send trace output to FILE instead of stderr

-Ooverhead -- set overhead for tracing syscalls to OVERHEAD usecs

-ppid -- trace process with process id PID, may be repeated

-D-- run tracer process as a detached grandchild, not as parent

-sstrsize -- limit length of print strings to STRSIZE chars (default 32)

-Ssortby -- sort syscall counts by: time, calls, name, nothing (default time)

-uusername -- run command as username handling setuid and/or setgid

-Evar=val -- put var=val in the environment for command

-Evar -- remove var from the environment for command

 

[root@ghqpub]# sar

Linux2.6.32-431.el6.i686 (ghq)        08/27/2015      _i686_  (1 CPU)

 

12:00:01AM     CPU     %user    %nice   %system   %iowait   %steal     %idle

12:10:01AM     all      0.02     0.00      0.29      0.03     0.00     99.66

12:20:01AM     all      0.02     0.00      0.25      0.01     0.00     99.72

12:30:01AM     all      0.03     0.00      0.34      0.01     0.00     99.62

12:40:01AM     all      0.03     0.00      0.35      0.01     0.00     99.60

12:50:01AM     all      0.02     0.00      0.26      0.01     0.00     99.71

01:00:01AM     all      0.02     0.00      0.27      0.02     0.00     99.69

01:10:01AM     all      0.03     0.00      0.29      0.02     0.00     99.67

01:20:01AM     all      0.02     0.00      0.25      0.01     0.00     99.73

01:30:01AM     all      0.03     0.00      0.29      0.01     0.00     99.66

01:40:01AM     all      0.02     0.00      0.27      0.01     0.00     99.69

01:50:01AM     all      0.02     0.00      0.26      0.01     0.00     99.71

02:00:01AM     all      0.02     0.00      0.24      0.01     0.00     99.74

02:10:02AM     all      0.02     0.00      0.28      0.01     0.00     99.68

02:20:01AM     all      0.02     0.00      0.25      0.01     0.00     99.72

02:30:01AM     all      0.03     0.00      0.27      0.01     0.00     99.69

Average:        all     0.02      0.00     0.28      0.01      0.00    99.69

 

07:00:30AM       LINUX RESTART

 

07:10:01AM     CPU     %user    %nice   %system   %iowait   %steal     %idle

07:20:01AM     all      0.91     0.00      0.67      0.03     0.00     98.40

07:30:01AM     all     0.06      0.00      0.43     0.02      0.00     99.49

07:40:01AM     all      0.02     0.00      0.30      0.01     0.00     99.67

07:50:01AM     all      1.12     0.00      1.39      1.29     0.00     96.20

Average:        all     0.53      0.00      0.70     0.34      0.00     98.44

 

[root@ghq pub]# rpm -qf `which sar`

sysstat-9.0.4-22.el6.i686

 

[root@ghq pub]# sar -n DEV 1 4 (查看网卡流量)

Linux2.6.32-431.el6.i686 (ghq)        08/27/2015      _i686_  (1 CPU)

 

07:53:57AM     IFACE   rxpck/s  txpck/s    rxkB/s    txkB/s  rxcmp/s   txcmp/s  rxmcst/s

07:53:58AM        lo      0.00     0.00      0.00      0.00     0.00      0.00      0.00

07:53:58AM      eth0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

07:53:58AM      pan0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

 

07:53:58AM     IFACE   rxpck/s  txpck/s    rxkB/s    txkB/s  rxcmp/s   txcmp/s  rxmcst/s

07:53:59AM        lo      0.00     0.00      0.00      0.00     0.00      0.00      0.00

07:53:59AM      eth0      1.00     1.00      0.06      0.47     0.00      0.00      0.00

07:53:59AM      pan0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

 

07:53:59AM     IFACE   rxpck/s  txpck/s    rxkB/s    txkB/s  rxcmp/s   txcmp/s  rxmcst/s

07:54:00AM        lo      0.00     0.00      0.00      0.00     0.00      0.00      0.00

07:54:00AM      eth0      1.00     1.00      0.06      0.47     0.00      0.00      0.00

07:54:00AM      pan0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

 

07:54:00AM     IFACE   rxpck/s  txpck/s    rxkB/s    txkB/s  rxcmp/s   txcmp/s  rxmcst/s

07:54:01AM        lo      0.00     0.00      0.00      0.00     0.00      0.00      0.00

07:54:01AM      eth0      1.01     1.01      0.06      0.48     0.00      0.00      0.00

07:54:01AM      pan0      0.00     0.00      0.00      0.00     0.00      0.00      0.00

 

Average:        IFACE  rxpck/s   txpck/s    rxkB/s   txkB/s   rxcmp/s   txcmp/s rxmcst/s

Average:           lo      0.00     0.00      0.00      0.00     0.00      0.00      0.00

Average:         eth0      0.75     0.75      0.04      0.36     0.00      0.00      0.00

Average:         pan0     0.00      0.00      0.00     0.00      0.00      0.00     0.00

 

 

[root@ghq pub]# sar -b 1 3

Linux2.6.32-431.el6.i686 (ghq)        08/27/2015      _i686_  (1 CPU)

 

08:06:57AM       tps      rtps     wtps   bread/s   bwrtn/s

08:06:58AM      0.00      0.00     0.00      0.00      0.00

08:06:59AM      0.00      0.00     0.00      0.00      0.00

08:07:00AM      2.97      0.00     2.97      0.00     63.37

Average:         1.00      0.00     1.00      0.00     21.26

 

查看内存命令 free  free –m free –g

 

查看进程的命令: ps  pstree

 

[root@ghq pub]# ps -elf|head  这个命令也可以

FS UID        PID  PPID  CPRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD

4S root         1     0 0  80   0 -  725 -      07:00 ?        00:00:01 /sbin/init

1S root         2     0 0  80   0 -    0 -      07:00 ?        00:00:00 [kthreadd]

1S root         3     2  0-40   - -     0 -     07:00 ?        00:00:00[migration/0]

1S root         4     2 0  80   0 -    0 -      07:00 ?        00:00:00 [ksoftirqd/0]

1S root         5     2  0-40   - -     0 -     07:00 ?        00:00:00[migration/0]

5S root         6     2  0-40   - -     0 -     07:00 ?        00:00:00[watchdog/0]

1S root         7     2 0  80   0 -    0 -      07:00 ?        00:00:00 [events/0]

1S root         8     2 0  80   0 -    0 -      07:00 ?        00:00:00 [cgroup]

1S root         9     2 0  80   0 -    0 -      07:00 ?        00:00:00 [khelper]

 

[root@ghq pub]# ps -eo pid,args,psr

 

[root@ghq pub]# netstat –lnp (查看系统监听了那些端口)

 

[root@ghq pub]# netstat –an  tcp/ip协议)

 

[root@ghq pub]# dig @8.8.8.8 www.baidu.com

 

;<<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>>@8.8.8.8 www.baidu.com

;(1 server found)

;;global options: +cmd

;;Got answer:

;;->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47071

;;flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

 

;;QUESTION SECTION:

;www.baidu.com.                 IN      A

 

;;ANSWER SECTION:

www.baidu.com.          296     IN     CNAME   www.a.shifen.com.

www.a.shifen.com.       213    IN      A       119.75.218.70

www.a.shifen.com.       213    IN      A       119.75.217.109

 

;;Query time: 41 msec

;;SERVER: 8.8.8.8#53(8.8.8.8)

;;WHEN: Thu Aug 27 08:29:39 2015

;;MSG SIZE  rcvd: 90


20.docx



https://m.sciencenet.cn/blog-575910-916501.html

上一篇:linux_centos第17次课
下一篇:第24_4次课 LAMP的搭建

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-6 00:10

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部