在CentOS系統中,監控Nginx資源可以通過多種方法和工具來實現。以下是一些常用的監控方法:
Nginx提供了一個名為ngx_http_stub_status_module
的模塊,可以用來實時監控Nginx的狀態。配置步驟如下:
/etc/nginx/nginx.conf
或/etc/nginx/conf.d/default.conf
。location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
sudo nginx -s reload
http://your_server_ip/nginx_status
,查看Nginx的狀態信息。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 --config.file=prometheus.yml
wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
tar xvfz nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
cd nginx-prometheus-exporter
./nginx-prometheus-exporter -nginx.scrape-uri http://192.168.214.100:80/stub_status
prometheus.yml
中添加以下內容:scrape_configs:
- job_name: 'nginx'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9113']
prometheus --config.file=prometheus.yml
Cockpit是CentOS 8內置的一款基于Web的可視化管理工具,提供用戶管理、防火墻管理、服務器資源監控等功能??梢酝ㄟ^yum安裝Cockpit,并使用systemctl命令啟動和啟用服務。
通過上述方法,可以有效地監控CentOS系統中Nginx的資源使用情況,及時發現并解決潛在問題,確保服務的穩定運行。