在CentOS系统中,监控关键进程是确保系统稳定运行的重要步骤。以下是一些常用的方法和工具来监控CentOS的关键进程:
1. 使用 top
命令
top
是一个实时显示系统进程信息的动态视图工具。
top
你可以按 P
键按CPU使用率排序,按 M
键按内存使用率排序。
2. 使用 htop
命令
htop
是 top
的增强版本,提供了更友好的用户界面和更多的功能。
首先,安装 htop
:
sudo yum install htop
然后运行:
htop
3. 使用 ps
命令
ps
命令可以用来查看当前运行的进程。
ps aux
你可以结合 grep
来查找特定的进程:
ps aux | grep
4. 使用 systemd
和 journalctl
如果你的系统使用 systemd
,可以使用 journalctl
来查看系统日志,包括进程的启动和停止信息。
journalctl -u
5. 使用 nmon
nmon
是一个性能监控工具,可以监控CPU、内存、磁盘和网络的使用情况。
首先,安装 nmon
:
sudo yum install nmon
然后运行:
nmon
6. 使用 glances
glances
是一个跨平台的系统监控工具,可以监控CPU、内存、磁盘、网络、传感器等。
首先,安装 glances
:
sudo yum install glances
然后运行:
glances
7. 使用 Prometheus
和 Grafana
对于更复杂的监控需求,可以使用 Prometheus
来收集指标,并使用 Grafana
来可视化这些指标。
安装 Prometheus
- 下载并解压 Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz tar xvfz prometheus-2.30.3.linux-amd64.tar.gz cd prometheus-2.30.3.linux-amd64
- 配置 Prometheus:
编辑 prometheus.yml
文件,添加监控目标:
scrape_configs: - job_name: 'node' static_configs: - targets: ['localhost:9100']
- 启动 Prometheus:
./prometheus --config.file=prometheus.yml
安装 Grafana
- 下载并解压 Grafana:
wget https://dl.grafana.com/oss/release/grafana-8.2.0.linux-amd64.tar.gz tar xvfz grafana-8.2.0.linux-amd64.tar.gz cd grafana-8.2.0
- 启动 Grafana:
./bin/grafana-server
-
访问 Grafana Web界面(默认地址是
http://localhost:3000
),使用默认用户名和密码(admin/admin)登录。 -
添加 Prometheus 数据源:
- 点击左侧菜单的齿轮图标,选择“Data Sources”。
- 点击“Add data source”,选择“Prometheus”。
- 在URL字段中输入
http://localhost:9090
,然后点击“Save & Test”。
- 创建仪表盘并添加监控面板:
- 点击左侧菜单的“+”图标,选择“Dashboard”。
- 点击“Add new panel”。
- 在查询编辑器中输入 Prometheus 查询语句,例如
up
来检查所有服务的状态。 - 点击“Apply”保存面板。
通过这些工具和方法,你可以有效地监控CentOS系统中的关键进程,确保系统的稳定运行。