知识点
- w ,vmstat ,top ,sar ,nload ,iostst ,free ,ps ,netstat ,tcpdump ,ifdown ,ifup
w命令 能够查看系统负载linux
[root@localhost ~]# w 20:58:32 up 13 min, 1 user, load average: 0.00, 0.02, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.139.1 20:47 0.00s 0.04s 0.00s w
主要关注load average这个点,其中后面的数字分别表明1分钟、5分钟、15分钟的负载。 那负载的值为多少才合适呢!经过cat /proc/cpuinfo查看ios
[root@localhost ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
若是你的processor为0,表明只有一颗cpu,因此最佳的负载值就是1。 若是是7则最佳的负载值就是8。windows
vmstat命令缓存
用w查看发现load高于processor,就可使用vmstat找到瓶颈在哪里。服务器
[root@localhost ~]# vmstat 1 5 //1表明1秒 5表明5次 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 0 0 768784 2076 133844 0 0 19 3 55 56 0 0 99 0 0 0 0 0 768768 2076 133844 0 0 0 0 43 39 0 1 99 0 0 0 0 0 768768 2076 133844 0 0 0 0 50 42 0 0 100 0 0 0 0 0 768768 2076 133844 0 0 0 0 40 34 0 0 100 0 0 0 0 0 768768 2076 133844 0 0 0 0 48 39 0 0 100 0 0
其中r列表示有多少个进程处于run的状态。b列表示进程被卡死等待的状态。swpd表示使用虚拟内存的数值,内存不够时会变大,因此0为最佳。free是空闲的内存,buff是缓冲(cpu经过内存写数据到磁盘上),cache是缓存(cpu经过内存从磁盘读取数据)。。。。网络
top命令多线程
top - display Linux processesdom
使用vmstat查看以后使用top命令能够显示linux的进程。查看具体是哪一个进程有问题!top是动态显示系统进程的。像windows里的任务管理器ssh
[root@localhost ~]# top top - 22:37:59 up 1:52, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 83 total, 1 running, 82 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999696 total, 762352 free, 95532 used, 141812 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 741948 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 520 root 20 0 305296 6248 4872 S 0.7 0.6 0:22.25 vmtoolsd 948 root 20 0 0 0 0 S 0.3 0.0 0:21.03 kworker/0:0 1 root 20 0 128164 6808 4044 S 0.0 0.7 0:03.01 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.17 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H .....
- 按M 按内存排行
- 按P 按cpu排行
- 按1 互相切换cpu
- -bn1 静态显示
- -c 显示具体的命令
经过观察发现top命令基本包含了w、vmstat的基本内容。==懒人神器==tcp
然而使用top -c能够查看具体哪一个命令。
[root@localhost ~]# top -c top - 22:39:49 up 1:54, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 83 total, 1 running, 82 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 999696 total, 762336 free, 95532 used, 141828 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 741932 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 520 root 20 0 305296 6248 4872 S 0.3 0.6 0:22.61 /usr/bin/vmtoolsd 948 root 20 0 0 0 0 S 0.3 0.0 0:21.38 [kworker/0:0] 1 root 20 0 128164 6808 4044 S 0.0 0.7 0:03.01 /usr/lib/systemd/systemd --switched-root --s+ 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kthreadd] 3 root 20 0 0 0 0 S 0.0 0.0 0:00.17 [ksoftirqd/0] 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H] 6 root 20 0 0 0 0 S 0.0 0.0 0:00.05 [kworker/u256:0] 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 [migration/0]
sar命令
查看网卡流量,先安装yum install -y sysstat
[root@localhost ~]# sar -n DEV 1 3 Linux 3.10.0-693.el7.x86_64 (localhost.localdomain) 2018年11月29日 _x86_64_ (1 CPU) 23时00分16秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 23时00分17秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 23时00分17秒 ens33 1.02 1.02 0.06 0.20 0.00 0.00 0.00 23时00分17秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 23时00分18秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 23时00分18秒 ens33 1.00 1.00 0.06 0.40 0.00 0.00 0.00 23时00分18秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 23时00分19秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 23时00分19秒 ens33 1.02 1.02 0.06 0.41 0.00 0.00 0.00 平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均时间: ens33 1.01 1.01 0.06 0.34 0.00 0.00 0.00
我的感受sar最大的用处在于他会监控网卡流量,而后将数据保存到/var/log/sa/saXX。 天天保存一份,最多保存一个月。若是哪天怀疑服务器流量不正常的时候,能够调出历史数据进行比对。使用命令 sar -f /var/log/sa/saXX 若是是sarXX则能够直接cat。
nload命令
nload也是查看网卡流量的命令,我的感受用nload看网卡流量比sar要舒服。首先也许要安装 yum install -y nload
使用左右按钮能够切换网卡!
iostat命令
cpu和内存查看完了,如今来看看磁盘。iostat查看磁盘使用命令。
关键的注意点在%util,该参数暗示了设备的繁忙程度 。通常地,若是该参数是100%表示设备已经接近满负荷运行了。因此越小越好!
iotop也能够查看磁盘的使用状况,并且他能够具体到进程!
free命令
查看内存使用状况
[root@localhost ~]# free total used free shared buff/cache available Mem: 999696 97424 587652 6808 314620 716584 Swap: 2097148 0 2097148
哇靠 top里基本上都有的。
ps命令
ps - report a snapshot of the current processes 静态显示任务管理器。
[root@localhost ~]# ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.6 128164 6816 ? Ss 20:45 0:03 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 root 2 0.0 0.0 0 0 ? S 20:45 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 20:45 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 20:45 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 20:45 0:00 [kworker/u256:0] root 7 0.0 0.0 0 0 ? S 20:45 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 20:45 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? R 20:45 0:01 [rcu_sched] root 10 0.0 0.0 0 0 ? S 20:45 0:00 [watchdog/0] root 12 0.0 0.0 0 0 ? S 20:45 0:00 [kdevtmpfs] root 13 0.0 0.0 0 0 ? S< 20:45 0:00 [netns] root 14 0.0 0.0 0 0 ? S 20:45 0:00 [khungtaskd] root 15 0.0 0.0 0 0 ? S< 20:45 0:00 [writeback] root 16 0.0 0.0 0 0 ? S< 20:45 0:00 [kintegrityd] root 17 0.0 0.0 0 0 ? S< 20:45 0:00 [bioset] root 18 0.0 0.0 0 0 ? S< 20:45 0:00 [kblockd] root 19 0.0 0.0 0 0 ? S< 20:45 0:00 [md] root 25 0.0 0.0 0 0 ? S 20:45 0:00 [kswapd0] ....
而后看到哪一个进程不爽,可使用kill xx(PID号)将其结束掉。也能够配合管道符 ‘\’使用。好比 ==ps aux | grep ngix== 查看ngix是否有启动!最后是STAT列的含义了
- D 表示不能中断的进程
- R 表示run状态的进程
- S sleep的进程
- T 暂停
- Z 僵尸
- < 高优先级
- N 低优先级
- L 内存中被锁了内存分页
- s 主进程
- L 多线程进程
-
- 前台进程
netstat命令
查看网络状态。我的感受用到最多的就是能够查看哪些端口有开放。
- -lnp 查看监听端口
- -an 查看网络链接情况
- -lntp 只查看tcp的链接
[root@localhost ~]# netstat -ltnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 807/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 890/master tcp6 0 0 :::22 :::* LISTEN 807/sshd tcp6 0 0 ::1:25 :::* LISTEN 890/master
统计各个状态的链接数: ==netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'==
tcpdump命令
抓包命令,一个很实用的命令。先安装 yum install -y tcpdump。举例2个用法,本身触类旁通。
++tcpdump -nn -i ens33++
++tcpdump -nn not port 22 and host 192.168.0.100++
++tcpdump -nn -c 100 -w 1.cap++ //这个要配合 tcpdump -r 1.cap使用!
还有一个在windows里被普遍使用的抓包工具wireshark。yum install -y wireshark。
==tshark -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"==
ifdown ens33 && ifup ens33 //重启网卡,down掉立刻再up。
mii-tool ens33 || ethtool ens33 //查看网口是否有网线链接
hostnamectl set-hostname xxoo //设置hostname,配置文件 /etc/hostname
DNS的配置文件 /etc/resolv.conf
本地host文件 /etc/hosts
w、vmstat、free 记top就好
sar 主要作监控
nload 很棒的查看网络流量工具
iostst 上面几个要么看cpu要么看内存MEM,这个就看磁盘
ps 有不少STAT
netstat 主要查看端口
tcpdump 抓包工具
ifdown ens33 && ifup ens33 重启网卡神命令
mii-tool、ethtool 查看是否有连网线detect link
hostnamectl set-hostname xxoo 设置hostname