CentOS下查看cpu、磁盘、内存使用情况以及如何清理内存

CentOS系统运行状态管理,查看内存、cpu,磁盘、网速及带宽等情况

Quick Start

核查服务器基本情况

查看内存使用情况

1
free -m

查看cpu使用情况

1
top #查看进程运行情况

查看磁盘以及分区情况

1
df -h

查看网络情况

1
ifconfig

安装测网速、带宽工具、speedtest-cli工具

1
2
3
4
5
6
7
8
#下载python测速脚本
wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py --no-check-certificate

#赋权限
chmod +rx speedtest.py

#执行测试
./speedtest.py

至此已经可以看到网络及带宽情况

1
2
3
4
5
6
7
8
9
10
11

#Retrieving speedtest.net configuration...
#Testing from HuaBei Oil Communication CO. Information Center (175.5.1.1)...
#Retrieving speedtest.net server list...
#Selecting best server based on ping...
#Hosted by China Unicom (Tianjin) [111.69 km]: 6.83 ms
#Testing download speed................................................................................
#Download: 2.40 Mbit/s
#Testing upload speed................................................................................................
#Upload: 3.93 Mbit/s


查看端口使用情况

1
2
3
4
5
#1.方法一
lsof -i:端口号

#2.方法二
netstat -apn|grep 端口号

服务器排查以及优化

  • 清理内存
1
2
3
4
5
6
7
8
9
10
#1.【推荐】释放网页缓存(To free pagecache),
sync
echo 1 > /proc/sys/vm/drop_caches

#2.释放目录项和索引(To free dentries and inodes)
sync
echo 2 > /proc/sys/vm/drop_caches
#3.释放网页缓存,目录项和索引(To free pagecache, dentries and inodes):
sync
echo 3 > /proc/sys/vm/drop_caches