系统监控工具
进程管理工具
kill -l 信号种类
httpd主页实验(kill -1)
前后台切换
系统监控工具
dstat、vmstat、iostat
[root@centos7 ~]# dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
1 1 98 1 0 0| 271k 216k| 0 0 | 0 3B| 154 184
0 0 100 0 0 0| 0 0 | 240B 870B| 0 0 | 53 71
1 0 100 0 0 0| 0 0 | 540B 390B| 0 0 | 54 69
0 0 100 0 0 0| 0 0 | 240B 390B| 0 0 | 37 55
0 0 100 0 0 0| 0 0 | 240B 390B| 0 0 | 63 78
0 0 100 0 0 0| 0 0 | 780B 390B| 0 0 | 47 55
0 0 100 0 0 0| 0 0 |1020B 390B| 0 0 | 66 73
0 0 100 0 0 0| 0 1024B| 544B 390B| 0 0 | 54 67
0 0 100 0 0 0| 0 4096B| 950B 390B| 0 0 | 74 85
0 0 100 0 0 0| 0 0 | 488B 390B| 0 0 | 47 65 ^C
[root@centos7 ~]# dstat -c
----total-cpu-usage----
usr sys idl wai hiq siq
1 1 97 1 0 0
0 0 100 0 0 0
0 0 100 0 0 0
0 0 100 0 0 0
0 0 100 0 0 0
0 0 100 0 0 0^C
[root@centos7 ~]# dstat -d
-dsk/total-
read writ
347k 285k
0 16k
0 0
0 0
0 0
0 0
0 0
0 0 ^C
[root@centos7 ~]# dstat -g
---paging--
in out
0 4B
0 0
0 0
0 0
0 0
0 0 ^C
[root@centos7 ~]# dstat -m
------memory-usage-----
used buff cach free
594M 40.0k 1060M 169M
595M 40.0k 1060M 169M
595M 40.0k 1060M 169M
595M 40.0k 1060M 169M
595M 40.0k 1060M 169M^C
[root@centos7 ~]# dstat -p
---procs---
run blk new
0 0 1.0
0 0 0
0 0 0
0 0 0^C
[root@centos7 ~]# dstat -r
--io/total-
read writ
6.27 1.19
0 0
0 0
0 0
0 0 ^C
[root@centos7 ~]# dstat -s
----swap---
used free
12k 4096M
12k 4096M
12k 4096M^C
[root@centos7 ~]# sdtat --tcp
bash: sdtat: command not found...
Similar command is: 'dstat'
[root@centos7 ~]# dstat --tcp
----tcp-sockets----
lis act syn tim clo
10 2 0 0 0
10 2 0 0 0
10 2 0 0 0
10 2 0 0 0^C
[root@centos7 ~]# dstat udp
You did not select any stats, using -cdngy by default.
dstat: incorrect argument, try dstat -h for the correct syntax
[root@centos7 ~]# dstat --udp
--udp--
lis act
10 0
10 0
10 0
10 0
10 0^C
[root@centos7 ~]# dstat --unix
--unix-sockets-
dgm str lis act
41 443 66 377
41 443 66 377
41 443 66 377
41 443 66 377^C
[root@centos7 ~]# dstat --raw
raw
raw
0
0
0
0
0
0^C
[root@centos7 ~]# dstat --socket
------sockets------
tot tcp udp raw frg
1 7 8 0 0
1 7 8 0 0
1 7 8 0 0^C
[root@centos7 ~]# dstat --ipc
--sysv-ipc-
msg sem shm
0 0 2
0 0 2
0 0 2^C
[root@centos7 ~]# dstat --top-cpu
-most-expensive-
cpu process
vmtoolsd 0.1
vmtoolsd 0.5
vmtoolsd 0.5
kworker/0:2 0.5
xfsaild/sda2 0.5
vmtoolsd 0.5
rcu_sched 0.5
vmtoolsd 0.5
vmtoolsd 0.5
vmtoolsd 0.5
-most-expensive-
cpu process
ksmtuned 0.5
irqbalance 0.5^C
[root@centos7 ~]# dstat --top-io
----most-expensive----
i/o process
packagekitd 386k 174k
sshd: root@ 146B 240B
sshd: root@ 78B 160B
sshd: root@ 78B 160B
irqbalance 6144B 0
sshd: root@ 71B 160B
sshd: root@ 78B 160B
vmtoolsd 9744B 0
sshd: root@ 71B 160B^C
[root@centos7 ~]# dstat --top-mem
--most-expensive-
memory process
gnome-shell 145M
gnome-shell 145M
gnome-shell 145M
gnome-shell 145M
gnome-shell 145M^C
[root@centos7 ~]# dstat --top-latency
--highest-total--
latency process
rcu_sched 817
ksoftirqd/1 3391
ksoftirqd/1 1090
rcu_sched 994
rcu_sched 1048
kworker/1:2 123
ksoftirqd/1 981
xfsaild/sda2 136
rcu_sched 1063
ksoftirqd/1 1029^C
[root@centos7 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 12 133548 40 1229856 0 0 166 134 88 103 1 1 97 1 0
[root@centos7 ~]# iostat
Linux 3.10.0-514.el7.x86_64 (centos7.bai.com) 07/01/2017 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.25 0.78 0.72 0.98 0.00 97.27
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
scd0 0.01 0.02 0.00 66 0
sda 10.58 332.49 265.27 1013497 808601
sdb 0.05 0.34 0.00 1044 0
sdc 0.05 0.34 0.00 1044 0
sdd 0.05 0.34 0.00 1044 0
进程管理工具;
pidof、pgerp 、ps aux 、pstree
kill -l、trap -l
#pidof bc查看进程编号
[root@centos7 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
[root@centos7 ~]# pidof bc
5730
[root@centos7 ~]# kill -3 5730
[root@centos7 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
^\Quit (core dumped)
[root@centos7 ~]#
相当于quite命令退出
kill -l 信号种类
[root@centos7 ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[root@centos7 ~]# trap -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
###trap -l 、 kill -l 查看信号管理种类
1---无需关闭进程,将其重新读取配置文件
2---终止正在运行中的进程:相当于ctrl+c
3---相当于ctrl+\ 相当用quit命令退出
9---强制杀死正在运行中的进程
15---终止运行的进程,相当于kill 、可以不写 -15。打开vim用15关闭进程,不能保存文件。
18---继续运行
19---后台休眠
pgrep命令
查询当前某个用户开启了那些进程
pgrep -U bai发起者进程编号
-aU 进程名称
pgrep -u bai 生效者进程编号
pgrep -au bai
pstree 查看树状结构进程编号
[bai@centos7 ~]$ ping 127.1
PING 127.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.113 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.046 ms
[root@centos7 ~]# pgrep -aU bai
6026 -bash
6070 ping 127.1
[root@centos7 ~]# pgrep -u bai
6026
6070
[root@centos7 ~]# pgrep -au bai
6026 -bash
6070 ping 127.1
kill -15
杀父进程
[root@centos7 ~]# pgrep -aU bai
6026 -bash
6259 ping 127.1
[root@centos7 ~]# pgrep -au bai
6026 -bash
6259 ping 127.1
[root@centos7 ~]# kill 6026
[root@centos7 ~]# pgrep -au bai
6026 -bash
6259 ping 127.1
[root@centos7 ~]# pgrep -aU bai
6026 -bash
6259 ping 127.1
[root@centos7 ~]#
不起作用 15命令
kill -9
1、[root@centos7 ~]# pgrep -aU bai
7095 -bash
7135 vim f
[root@centos7 ~]# kill -9 7095
[root@centos7 ~]# pgrep -aU bai
ping特殊
2、[root@centos7 ~]# pgrep -au bai
7261 -bash
7301 ping 127.1
[root@centos7 ~]# kill -9 7261
[root@centos7 ~]# pgrep -au bai
7301 ping 127.1
再生进程
[root@centos6 ~]#ps aux |grep ming
root 2616 0.0 0.0 4068 540 tty2 Ss+ 02:38 0:00 /sbin/mingetty /dev/tty2
root 2618 0.0 0.0 4068 540 tty3 Ss+ 02:38 0:00 /sbin/mingetty /dev/tty3
root 2620 0.0 0.0 4068 544 tty4 Ss+ 02:38 0:00 /sbin/mingetty /dev/tty4
root 2626 0.0 0.0 4068 544 tty5 Ss+ 02:38 0:00 /sbin/mingetty /dev/tty5
root 2640 0.0 0.0 4068 544 tty6 Ss+ 02:38 0:00 /sbin/mingetty /dev/tty6
root 4549 0.0 0.0 103336 852 pts/1 S+ 07:28 0:00 grep ming
kill 1 杀死父进程,不能在生成
###killall bash
[root@centos7 ~]# pidof bash
4020 2152 648
[root@centos7 ~]# killall bash
可以杀死所有bash进程
[root@centos7 ~]# killall vim
[root@centos7 ~]# pidof vim
4230 4229
[root@centos7 ~]# killall -9 vim
[root@centos7 ~]# pidof vim
###pkill 支持模式 信号杀进程 与kill 类似
杀进程终端,
[root@centos7 ~]# w
15:05:21 up 3 min, 3 users, load average: 0.20, 0.45, 0.22
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root :0 :0 15:02 ?xdm? 16.50s 0.33s gdm-session-worker [pam/gdm-autologin]
root pts/0 192.168.239.1 15:03 1.00s 0.08s 0.03s w
root pts/2 192.168.239.1 15:04 33.00s 0.06s 0.06s -bash
[root@centos7 ~]# who
root pts/1 2017-07-01 13:04 (192.168.239.1)
root :0 2017-07-01 13:04 (:0)
root pts/0 2017-07-01 14:22 (192.168.239.1)
root pts/2 2017-07-01 14:29 (192.168.239.1)
[root@centos7 ~]# tty
/dev/pts/1
[root@centos7 ~]# pgrep -t pts/0
4020
[root@centos7 ~]# tty
/dev/pts/0
[root@centos7 ~]# pgrep -t /dev/pts/0
[root@centos7 ~]# pgrep -t pts/0
4020
[root@centos7 ~]# pkill -t pts/0
[root@centos7 ~]# pgrep -t pts/0
4020
[root@centos7 ~]# pkill -t pts/0 -9
[root@centos7 ~]# pgrep -t pts/0
httpd主页实验(kill -1);
安装好httpd服务、links;
#kill -1 重新读取配置文件
###nmcli connection reload ,重新新读取配置文件
修改服务配置文件;
vim /etc/httpd/conf/httpd.conf
修改目录后的变化
centos7
#cd /var/www/html 存放外部服务主页文件所在的目录
#echo www.mage.com > index.html
创建主页
#systemctl status httpd
查看是否启用服务
#systemctl start httpd
启用服务
#links 192.168.8.133
CENTOS6启用字符界面游览器
#yum -y install links
安装字符游览器
centos7
#iptables -vnL
产看防火墙
#iptables -F
关闭防火墙
#links 192...
echo testpage > test.html
#links 192.168.8.133/taes.html
更改主页位置
mkdir /var/www/newsite
echo new site page > /var/www/newsite/index.html
放到新的目录
需要在配置文件更改路径;/var/www/newsite/
不用重启发信号可以启用,查看发到哪个进程上,重新读取配置文件
#pstree 查看进程
httpd 父进程;
#ps axu
#kill 1 (hup) 3287
#links 192.168.8.133
vim /etc/httpd/conf/httpd.conf
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See for detailed information.
# In particular, see
#
# for a discussion of each configuration directive.
#
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# The configuration directives are grouped into three basic sections:
# 1. Directives that control the operation of the Apache server process as a
# whole (the 'global environment').
# 2. Directives that define the parameters of the 'main' or 'default' server,
# which responds to requests that aren't handled by a virtual host.
# These directives also provide default values for the settings
# of all virtual hosts.
# 3. Settings for virtual hosts, which allow Web requests to be sent to
# different IP addresses or hostnames and have them handled by the
# same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "/etc/httpd" will be interpreted by the
# server as "/etc/httpd/logs/foo.log".
"/etc/httpd/conf/httpd.conf" 1009L, 34419C
前后台切换
#ping 127.1
前端执行敲命令不起作用
#pidof ping
查看进程编号
#kill -19 +进程编号
后台暂停
[root@centos7 ~]# w
15:20:47 up 18 min, 3 users, load average: 0.01, 0.04, 0.11
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root :0 :0 15:02 ?xdm? 20.00s 0.34s gdm-session-worker [pam/gdm-autologin]
root pts/0 192.168.239.1 15:03 7.00s 0.06s 0.00s ping 127.1
root pts/2 192.168.239.1 15:04 7.00s 0.10s 0.04s w
[root@centos7 ~]#
[root@centos7 ~]# pidof ping
3368
[root@centos7 ~]# kill -19 3368
[root@centos7 ~]# pidof ping
3380 3368
[root@centos7 ~]# killall -19 ping
64 bytes from 127.0.0.1: icmp_seq=48 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=49 ttl=64 time=0.051 ms
64 bytes from 127.0.0.1: icmp_seq=50 ttl=64 time=0.055 ms
64 bytes from 127.0.0.1: icmp_seq=51 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=52 ttl=64 time=0.052 ms
[2]+ Stopped ping 127.1
[root@centos7 ~]# ls
anaconda-ks.cfg Desktop Downloads httpd-2.4.25.tar.bz2 Music Pictures Templates Videos
bin Documents httpd-2.4.25 initial-setup-ks.cfg part Public user.txt
[root@centos7 ~]# pwd
/root
[root@centos7 ~]# who
root :0 2017-07-01 15:02 (:0)
root pts/0 2017-07-01 15:03 (192.168.239.1)
root pts/2 2017-07-01 15:04 (192.168.239.1)
[root@centos7 ~]# blkid
/dev/sda1: UUID="dfe31250-40b8-4eaf-bf35-f462946a56e4" TYPE="xfs"
/dev/sda2: UUID="f86bb45c-c257-4f7c-ae3c-fa72b50f277c" TYPE="xfs"
/dev/sda3: UUID="47a6bd61-66c5-4ddc-92fe-e2325e613aee" TYPE="swap"
/dev/sda5: UUID="f3824e25-f0da-4699-9607-f50ec1795e2d" TYPE="xfs"
/dev/sr0: UUID="2016-12-05-13-52-39-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
切换到后台停止后先前 敲过得命令执行后显示到屏幕上
[root@centos7 ~]# ps axu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.1 0.3 193628 6732 ? Ss 15:01 0:01 /usr/lib/systemd/systemd --switched-ro
root 2 0.0 0.0 0 0 ? S 15:01 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 15:01 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 15:01 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 15:01 0:00 [kworker/u256:0]
root 7 0.0 0.0 0 0 ? S 15:01 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 15:01 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? R 15:01 0:00 [rcu_sched]
root 10 0.0 0.0 0 0 ? S 15:01 0:00 [watchdog/0]
###查看运行程序进程状态信号
[root@centos7 ~]# jobs
[1]+ Stopped ping 127.1
[root@centos7 ~]# kill -18 3368
[root@centos7 ~]# 64 bytes from 127.0.0.1: icmp_seq=69 ttl=64 time=0.044 ms
64 bytes from 127.0.0.1: icmp_seq=70 ttl=64 time=0.051 ms
64 bytes from 127.0.0.1: icmp_seq=71 ttl=64 time=0.051 ms
###kill -18
后台运行
kill -22
[root@centos7 ~]# kill -22 3368
64 bytes from 127.0.0.1: icmp_seq=739 ttl=64 time=0.059 ms
64 bytes from 127.0.0.1: icmp_seq=740 ttl=64 time=0.052 ms
[1]+ Stopped ping 127.1
#ps axu
root 3368 0.0 0.0 127912 1224 pts/0 T 15:20 0:00 ping 127.1
fg 1 从后台调到前台,不管休眠还是运行
bg 1 将后台休眠调到后台运行
cmd+ & 后台运行
前台运行时不能在当前界面输入命令执行,用快捷键ctrl+z切换到后台暂停(休眠)界面再输入bg 1就可以后运行了,输入fg 1 调回前台运行。
###前台执行断开网络(断开端口)命令不在执行
###后台执行断开网络(断开端口)命令不在执行
###开启screen会话界面可以后台运行
#yum -y install screen
#screen
#ping 127.1
[root@centos7 ~]# pstree -p
├─sshd(993)─┬─sshd(2990)───bash(2994)───pstree(4224)
└─sshd(3085)───bash(3089)───screen(4176)───screen(4177)───bash(4178)───ping(4213+
断开网络后
[root@centos7 ~]# ps axu|grep ping
root 4213 0.0 0.0 127912 1228 pts/1 S+ 16:12 0:00 ping 127.1
root 4438 0.0 0.0 112648 964 pts/0 S+ 16:23 0:00 grep --color=auto ping
[root@centos7 ~]# pidof ping
4213
[root@centos7 ~]# pstree -p
├─screen(4177)───bash(4178)───ping(4213)
├─smartd(599)
├─sshd(993)─┬─sshd(2990)───bash(2994)───pstree(4381)
└─sshd(4275)───bash(4279)
根ssh服务没关系了。后台还在运行中
恢复screen 的端口
[root@centos7 ~]# screen -ls
There is a screen on:
4177.pts-2.centos7 (Detached)
1 Socket in /var/run/screen/S-root.
[root@centos7 ~]# screen -r
nohup ping 127.1&
[root@centos7 ~]# nohup ping 127.1 &
[1] 4710
[root@centos7 ~]# nohup: ignoring input and appending output to ‘nohup.out’
[root@centos7 ~]# tail -f nohup.out
64 bytes from 127.0.0.1: icmp_seq=263 ttl=64 time=0.051 ms
64 bytes from 127.0.0.1: icmp_seq=264 ttl=64 time=0.062 ms
64 bytes from 127.0.0.1: icmp_seq=265 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=266 ttl=64 time=0.047 ms
64 bytes from 127.0.0.1: icmp_seq=267 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=268 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=269 ttl=64 time=0.049 ms
不断地输出到nohup.out 文件里
[root@centos7 ~]# nohup ping 127.1 &>/dev/null &
[3] 4912
#last 查看日志