1.磁盘
获取磁盘空间的使用情况
[root@bogon /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 37G 993M 37G 3% /系统盘
devtmpfs 901M 0 901M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 143M 872M 15% /boot
tmpfs 183M 0 183M 0% /run/user/0
2.内存
-
Markdown
-
[root@bogon /]# free -m total used free shared buff/cache available Mem: 1823 141 1326 8 354 1461 Swap: 2047 0 2047 -
[root@bogon /]# free total used free shared buff/cache available Mem: 1867024 145236 1358804 8792 362984 1496512 Swap: 2097148 0 2097148
延伸:link
Mem:表示物理内存统计
total: 表示系统总物理内存5993156kb(约5852M)
used: 表示总计分配给缓存(包含buffers 与cached),但其中可能部分缓存未实际使用
free:表示未分配的内存
shared: 表示共享内存
buffers:表示系统分配但未被使用的buffers数量
cached:表示系统分配但未被使用的cache的数量
free数值不准
3.负载
Markdown
[root@bogon /]# top
top - 12:53:44 up 3:37, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 91 total, 1 running, 89 sleeping, 1 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
KiB Mem : 1867024 total, 1357036 free, 146348 used,363640 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1495384 avail Mem
-
Markdown
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+COMMAND 10302 root 20 0 0 0 0 S 0.3 0.0 0:02.76 kworker/0:3 1 root 20 0 128164 6812 4048 S 0.0 0.4 0:04.96 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.29 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.73 kworker/u256:0
注意问题:
1.load average: 0.00, 0.01, 0.05 注意观察此负载值,数值过大表示此服务器较为繁忙
2.cpu显示会出现超过百分之百的情况,如果偶尔则为正常,长时间居高不下需要去看此进程是否夯住,采取相应措施
4.进程
ps -ef
[root@bogon /]# ps -ef|grep ssh
root 999 1 0 09:16 ? 00:00:00 /usr/sbin/sshd -D
root 1303 999 0 09:17 ? 00:00:01 sshd: root@pts/0
root 12717 1307 0 13:08 pts/0 00:00:00 grep --color=auto ssh
eg:root 进程用户; 999 进程的pid ;1 父id
5.端口号
netstat -nlp
[root@bogon /]# ps -ef|grep ssh
root 999 1 0 09:16 ? 00:00:00 /usr/sbin/sshd -D
root 1303 999 0 09:17 ? 00:00:01 sshd: root@pts/0
root 12717 1307 0 13:08 pts/0 00:00:00 grep --color=auto ssh
[root@bogon /]# netstat -nlp|grep 999
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 999/sshd
tcp6 0 0 :::22 ::: LISTEN 999/sshd
6.启动服务,登陆web页面
service httpd start centos6.x 7.x
systemctl start httpd centos7.x
[root@bogon /]# systemctl start httpd
[root@bogon /]# ps -ef |grep httpd
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13157 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13158 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13159 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13160 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13161 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 13165 1307 0 13:16 pts/0 00:00:00 grep --color=auto httpd
[root@bogon /]#
[root@bogon /]# netstat -nlp|grep 13136
tcp6 0 0 :::80 ::: LISTEN 13136/httpd
[root@bogon ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 你的ip netmask 255.255.255.0 broadcast 你的ip.255
inet6 fe80::f507:c148:b565:facc prefixlen 64 scopeid 0x20
ether 00:0c:29:2f:44:7f txqueuelen 1000 (Ethernet)
RX packets 22236 bytes 15920055 (15.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7973 bytes 2867328 (2.7 MiB)
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
loop txqueuelen 1 (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
ip和端口号都有了 就可以去web端看一下了,如果页面出现无法访问从以下两个方面找问题:
1.防火墙是否关闭,如果是running,则需要先关闭防火墙
[root@bogon ~]# firewall-cmd --state
running
[root@bogon ~]# systemctl stop firewalld.service 关闭防火墙
2.查看端口
[root@bogon ~]# netstat -nlp|grep http
tcp6 0 0 :::80 ::: LISTEN 13136/httpd
这三类都没有问题
0.0.0.0:80 当前的ip
:::08 当前的ip
ip:08 当前的ip
如果为以下两类,则需要去看下配置文件
127.0.0.1:80 本地自己访问自己 window和其他服务器无法进行访问
localhost:80
7.杀进程
kill -9 进程pid
kill -9 进程pid 进程pid 进程pid
kill -9 $(pgrep -f 匹配关键词)
[root@bogon conf]# ps -ef|grep http
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13157 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13158 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13159 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13160 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@bogon conf]# kill -9 13157
[root@bogon conf]# ps -ef|grep http
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13158 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13159 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13160 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@bogon conf]# ps -ef|grep http
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13158 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13159 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13160 13136 0 13:16 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13311 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13312 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@bogon conf]# kill -9 13158 13159 13160
[root@bogon conf]# ps -ef|grep http
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13311 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13312 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
[root@bogon conf]# ps -ef|grep http
root 13136 1 0 13:15 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13311 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13312 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13313 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13314 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13315 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 13316 13136 0 13:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 13357 13142 0 13:54 pts/1 00:00:00 grep --color=auto http
[root@bogon conf]# pgrep -f http
13136
13311
13312
13313
13314
13315
13316
[root@bogon conf]# echo $(pgrep -f http)
13136 13311 13312 13313 13314 13315 13316
[root@bogon conf]# kill -9 $(pgrep -f http)
[root@bogon conf]# ps -ef|grep http
root 13368 13142 0 13:56 pts/1 00:00:00 grep --color=auto http #查询自身
!!!!此命令慎用
CentOS系统资源监控与管理
本文详细介绍了在CentOS系统中如何监控和管理磁盘空间、内存使用、负载、进程、端口号等关键资源,提供了实用的命令行操作指南,帮助系统管理员有效维护服务器稳定运行。

被折叠的 条评论
为什么被折叠?



