Linux系统检查常用命令

By admin, 11 十月, 2021

1. 用top查看进程占用情况

top命令可以动态地看到哪些进程占用CPU、内存较多。

有个命令glances可以查看比top更多、更清晰的数据,不过可能需要另外安装。

2. 查看web进程数

如果在top命令里看到有很多web进程,可以查一下究竟有多少,是不是有大量的web访问请求。

2.1 Apache

ps -ef | grep apache | wc -l

2.2  Nginx + php-fpm

ps -ef | grep php | wc -l

3. pstree查看进程树

pstree可以比较清晰地看到整个系统有什么进程,以便找出一些异常的进程。

4. netstat -nlp查看系统开放端口

此命令可以查看系统运行了哪些服务,开放了哪些端口,有没有一些不需要的端口在运行。

5. vnstat -h查看网络流量

此命令有结果的前提是之前已经启用了vnstat服务。

6. w查看当前登录用户

如果怀疑有其他人正在非法登录系统,w可以查看。当前进程树也可以看到。w可以看到登录用户来自的IP。

7. Web访问日志

7.1 Apache

less /var/log/apache2/access.log

可以看到有什么用户访问了web的哪些路径。

7.2 Nginx

less /var/log/nginx/access.log

7.3 goaccess

access.log看起来有点累,goaccess可以自动对其做一些统计,结果很值得一读。

安装goaccess:

sudo apt install goaccess 

使用goaccess:

goaccess /var/log/nginx/access.log 

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"