[root@localhost ~]# iostat Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 2017年11月28日 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.02 0.00 0.11 0.06 0.00 99.81 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.40 6.51 3.33 139818 71433 scd0 0.00 0.00 0.00 44 0 [root@localhost ~]# iostat 1 //每秒查看磁盤讀寫速率 Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 2017年11月28日 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.02 0.00 0.11 0.06 0.00 99.81 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.40 6.51 3.41 139818 73217 scd0 0.00 0.00 0.00 44 0 avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 100.00 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 ^C //按ctrl+c快捷鍵退出 [root@localhost ~]#
關注其中一個重要指標,就是%util 列html
按快捷鍵ctrl+c 退出查看mysql
[root@localhost ~]# iostat -x 1 Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) 2017年11月28日 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.04 0.00 0.12 0.05 0.00 99.79 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.02 0.01 0.26 0.12 6.21 3.24 49.21 0.00 12.12 6.39 24.71 2.89 0.11 scd0 0.00 0.00 0.00 0.00 0.00 0.00 8.00 0.00 23.45 23.45 0.00 23.45 0.00 avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 100.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 100.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 ^C //快捷鍵ctrl+c退出查看 [root@localhost ~]#
[root@localhost ~]# yum install -y iotop
[root@localhost ~]# free total used free shared buffers cached Mem: 1010860 354592 656268 6824 692 192560 -/+ buffers/cache: 161340 849520 Swap: 2097148 0 2097148 [root@localhost ~]#
[root@localhost ~]# free -m total used free shared buffers cached Mem: 987 347 639 6 0 188 -/+ buffers/cache: 158 828 Swap: 2047 0 2047 [root@localhost ~]#
[root@localhost ~]# free -h total used free shared buffers cached Mem: 987M 347M 639M 6.7M 692K 188M -/+ buffers/cache: 158M 828M Swap: 2.0G 0B 2.0G [root@localhost ~]#
[root@localhost ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.7 50772 7156 ? Ss 15:49 0:01 /usr/lib/systemd/system root 2 0.0 0.0 0 0 ? S 15:49 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 15:49 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 15:49 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 15:49 0:00 [kworker/u128:0] root 7 0.0 0.0 0 0 ? S 15:49 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 15:49 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/0] root 10 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/1] root 11 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/2] root 12 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/3] root 13 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/4] root 14 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/5] root 15 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/6] root 16 0.0 0.0 0 0 ? S 15:49 0:00 [rcuob/7] 等等等,只截取了一部分——>這裏顯示出了全部的進程
[root@localhost ~]# ps aux //查看系統全部進程 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.7 50772 7156 ? Ss 11月28 0:01 /usr/lib/systemd/syst root 2 0.0 0.0 0 0 ? S 11月28 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 11月28 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 11月28 0:00 [kworker/0:0H] root 6 0.0 0.0 0 0 ? S 11月28 0:00 [kworker/u128:0] root 7 0.0 0.0 0 0 ? S 11月28 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 11月28 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 11月28 0:00 [rcuob/0] root 10 0.0 0.0 0 0 ? S 11月28 0:00 [rcuob/1] root 11 0.0 0.0 0 0 ? S 11月28 0:00 [rcuob/2] 等等等,只截取了一部分——>這裏顯示出了全部的進程 [root@localhost ~]# ps -elf //查看系統全部進程 F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 12693 ep_pol 11月28 ? 00:00:01 /usr/lib/syst 1 S root 2 0 0 80 0 - 0 kthrea 11月28 ? 00:00:00 [kthreadd] 1 S root 3 2 0 80 0 - 0 smpboo 11月28 ? 00:00:00 [ksoftirqd/0] 1 S root 5 2 0 60 -20 - 0 worker 11月28 ? 00:00:00 [kworker/0:0H 1 S root 6 2 0 80 0 - 0 worker 11月28 ? 00:00:00 [kworker/u128 1 S root 7 2 0 -40 - - 0 smpboo 11月28 ? 00:00:00 [migration/0] 1 S root 8 2 0 80 0 - 0 rcu_gp 11月28 ? 00:00:00 [rcu_bh] 1 S root 9 2 0 80 0 - 0 rcu_no 11月28 ? 00:00:00 [rcuob/0] 1 S root 10 2 0 80 0 - 0 rcu_no 11月28 ? 00:00:00 [rcuob/1] 等等等,只截取了一部分——>這裏顯示出了全部的進程
線程和進程最大的區別: 1 進程裏包含了線程,線程是進程的子單元 2 同一個進程下的線程所有共享相同的內存,而進程之間內存相互隔離。
[root@localhost ~]# ps aux |grep nginx //查看nginx進程是否在存在 root 2619 0.0 0.0 112656 984 pts/0 R+ 00:00 0:00 grep --color=auto ngin [root@localhost ~]# ps aux |grep mysql //查看mysql進程是否存在 root 2643 0.0 0.0 112656 984 pts/0 R+ 00:02 0:00 grep --color=auto mysq [root@localhost ~]#
[root@hf-01 ~]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1522/master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1178/sshd tcp6 0 0 ::1:25 :::* LISTEN 1522/master tcp6 0 0 :::3306 :::* LISTEN 1525/mysqld tcp6 0 0 :::22 :::* LISTEN 1178/sshd udp 0 0 0.0.0.0:51407 0.0.0.0:* 557/avahi-daemon: r udp 0 0 0.0.0.0:5353 0.0.0.0:* 557/avahi-daemon: r raw6 0 0 :::58 :::* 7 650/NetworkManager Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 18892 1522/master private/tlsmgr unix 2 [ ACC ] STREAM LISTENING 18880 1522/master public/pickup unix 2 [ ACC ] STREAM LISTENING 18895 1522/master private/rewrite unix 2 [ ACC ] STREAM LISTENING 18898 1522/master private/bounce unix 2 [ ACC ] STREAM LISTENING 18901 1522/master private/defer unix 2 [ ACC ] STREAM LISTENING 18904 1522/master private/trace unix 2 [ ACC ] STREAM LISTENING 18907 1522/master private/verify unix 2 [ ACC ] STREAM LISTENING 18913 1522/master private/proxymap unix 2 [ ACC ] STREAM LISTENING 18916 1522/master private/proxywrite unix 2 [ ACC ] STREAM LISTENING 18919 1522/master private/smtp unix 2 [ ACC ] STREAM LISTENING 18922 1522/master private/relay unix 2 [ ACC ] STREAM LISTENING 18928 1522/master private/error unix 2 [ ACC ] STREAM LISTENING 18931 1522/master private/retry unix 2 [ ACC ] STREAM LISTENING 18934 1522/master private/discard unix 2 [ ACC ] STREAM LISTENING 18937 1522/master private/local unix 2 [ ACC ] STREAM LISTENING 11300 1/systemd /run/lvm/lvmpolld.socket unix 2 [ ACC ] STREAM LISTENING 18940 1522/master private/virtual unix 2 [ ACC ] STREAM LISTENING 18943 1522/master private/lmtp unix 2 [ ACC ] STREAM LISTENING 18946 1522/master private/anvil unix 2 [ ACC ] STREAM LISTENING 18949 1522/master private/scache unix 2 [ ACC ] STREAM LISTENING 6719 1/systemd /run/systemd/journal/stdout unix 2 [ ACC ] STREAM LISTENING 11092 1/systemd /run/lvm/lvmetad.socket unix 2 [ ACC ] STREAM LISTENING 15756 650/NetworkManager /var/run/NetworkManager/private-dhcp unix 2 [ ACC ] STREAM LISTENING 13965 1/systemd /var/run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 18884 1522/master public/cleanup unix 2 [ ACC ] STREAM LISTENING 13979 1/systemd /var/run/avahi-daemon/socket unix 2 [ ACC ] STREAM LISTENING 18887 1522/master public/qmgr unix 2 [ ACC ] STREAM LISTENING 18910 1522/master public/flush unix 2 [ ACC ] STREAM LISTENING 18925 1522/master public/showq unix 2 [ ACC ] STREAM LISTENING 19266 1525/mysqld /tmp/mysql.sock unix 2 [ ACC ] SEQPACKET LISTENING 11220 1/systemd /run/udev/control unix 2 [ ACC ] STREAM LISTENING 15580 650/NetworkManager /var/run/NetworkManager/private unix 2 [ ACC ] STREAM LISTENING 10994 1/systemd /run/systemd/private [root@hf-01 ~]#
[root@hf-01 ~]# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 52 192.168.74.129:22 192.168.74.1:49322 ESTABLISHED tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 :::3306 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN udp 0 0 0.0.0.0:51407 0.0.0.0:* udp 0 0 0.0.0.0:5353 0.0.0.0:* raw6 0 0 :::58 :::* 7 Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 18892 private/tlsmgr unix 2 [ ACC ] STREAM LISTENING 18880 public/pickup unix 2 [ ACC ] STREAM LISTENING 18895 private/rewrite unix 2 [ ACC ] STREAM LISTENING 18898 private/bounce 等等等,只截取了一部分
[root@hf-01 ~]# netstat -ltnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1522/master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1178/sshd tcp6 0 0 ::1:25 :::* LISTEN 1522/master tcp6 0 0 :::3306 :::* LISTEN 1525/mysqld tcp6 0 0 :::22 :::* LISTEN 1178/sshd [root@hf-01 ~]#
[root@hf-01 ~]# netstat -ltunp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1522/master tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1178/sshd tcp6 0 0 ::1:25 :::* LISTEN 1522/master tcp6 0 0 :::3306 :::* LISTEN 1525/mysqld tcp6 0 0 :::22 :::* LISTEN 1178/sshd udp 0 0 0.0.0.0:51407 0.0.0.0:* 557/avahi-daemon: r udp 0 0 0.0.0.0:5353 0.0.0.0:* 557/avahi-daemon: r [root@hf-01 ~]#
[root@hf-01 ~]# netstat -an |awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t" LISTEN 5 ESTABLISHED 1 [root@hf-01 ~]#
[root@hf-01 ~]# ss -an Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port nl UNCONN 0 0 0:4194954 * nl UNCONN 0 0 0:650 * nl UNCONN 0 0 0:557 * nl UNCONN 0 0 0:0 * nl UNCONN 4352 0 4:2922 * nl UNCONN 768 0 4:0 * nl UNCONN 0 0 6:0 * nl UNCONN 0 0 7:554 * nl UNCONN 0 0 7:1 * nl UNCONN 0 0 7:0 * nl UNCONN 0 0 9:0 * nl UNCONN 0 0 9:514 * nl UNCONN 0 0 9:1 * nl UNCONN 0 0 10:0 * nl UNCONN 0 0 11:0 * nl UNCONN 0 0 15:650 * 等等等,只截取了一部分 [root@hf-01 ~]# ss -an |grep -i listen //由於listen是大寫,因此加-i 參數 u_str LISTEN 0 100 private/tlsmgr 18892 * 0 u_str LISTEN 0 100 public/pickup 18880 * 0 u_str LISTEN 0 100 private/rewrite 18895 * 0 u_str LISTEN 0 100 private/bounce 18898 * 0 u_str LISTEN 0 100 private/defer 18901 * 0 u_str LISTEN 0 100 private/trace 18904 * 0 u_str LISTEN 0 100 private/verify 18907 * 0 u_str LISTEN 0 100 private/proxymap 18913 * 0 u_str LISTEN 0 100 private/proxywrite 18916 * 0 等等等,只截取了一部分
[root@hf-01 ~]# tcpdump -nn tcpdump: packet printing is not supported for link type NFLOG: use -w [root@hf-01 ~]# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.74.129 netmask 255.255.255.0 broadcast 192.168.74.255 inet6 fe80::20c:29ff:feff:fe93 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ff:fe:93 txqueuelen 1000 (Ethernet) RX packets 11067 bytes 12250186 (11.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2631 bytes 312427 (305.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@hf-01 ~]# tcpdump -nn -i eno16777736 5204, ack 6605, win 159, length 180 06:27:41.186368 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 45955204:45955384, ack 6605, win 159, length 180 06:27:41.186422 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 45955384:45955564, ack 6605, win 159, length 180 等等等,運行後,會顯示出不少的信息 按ctrl+c退出
[root@hf-01 ~]# tcpdump -nn -i eno16777736 port 22 4, length 0 06:52:04.034073 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228004:228376, ack 1, win 159, length 372 06:52:04.034155 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228376:228556, ack 1, win 159, length 180 06:52:04.034302 IP 192.168.74.1.49322 > 192.168.74.129.22: Flags [.], ack 228556, win 252, length 0 06:52:04.034387 IP 192.168.74.129.22 > 192.168.74.1.49322: Flags [P.], seq 228556:228832, ack 1, win 159, length 276 等等等,只截取了一部分
在這裏複製另外一個終端,並打開,跑vmstat 1命令 在當前終端查看,輸入如下命令 [root@hf-01 ~]# tcpdump -nn -i eno16777736 -c 10 -w 1.cap tcpdump: listening on eno16777736, link-type EN10MB (Ethernet), capture size 262144 bytes 10 packets captured 10 packets received by filter 0 packets dropped by kernel [root@hf-01 ~]# file 1.cap 1.cap: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 262144) [root@hf-01 ~]#
[root@hf-01 ~]# tcpdump -r 1.cap //查看1.cap文件 reading from file 1.cap, link-type EN10MB (Ethernet) 07:02:05.134302 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 4218852344:4218852492, ack 3076966380, win 159, length 148 07:02:05.134859 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 148, win 255, length 0 07:02:05.257655 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 148:280, ack 1, win 159, length 132 07:02:05.462113 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 280, win 255, length 0 07:02:06.258704 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 280:428, ack 1, win 159, length 148 07:02:06.462164 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 428, win 254, length 0 07:02:07.259714 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 428:560, ack 1, win 159, length 132 07:02:07.460218 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 560, win 254, length 0 07:02:08.260717 IP 192.168.74.129.ssh > 192.168.74.1.49322: Flags [P.], seq 560:708, ack 1, win 159, length 148 07:02:08.460263 IP 192.168.74.1.49322 > 192.168.74.129.ssh: Flags [.], ack 708, win 253, length 0 [root@hf-01 ~]#
tcp三次握手四次揮手linux
tshark幾個用法ios