参考地址:
https://www.prometheus.wang/quickstart/install-prometheus-server.html
https://spex.top/archives/systemd-prometheus-node-exporter.html
Prometheus
1 2 3 4 5
|
docker run --name prom -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -d prom/prometheus
容器启动以后在浏览器打开ip:9090即可访问
|
node_exporter
1 2 3 4 5 6 7 8 9 10 11 12
| curl -OL https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
tar -xzf node_exporter-0.17.0.linux-amd64.tar.gz cd node_exporter-0.17.0.linux-amd64/
mv node_exporter /usr/local/bin/
/usr/local/bin/node_exporter &
|
使用systemctl来管理node_exporter
1 2
| vi /etc/systemd/system/node_exporter.service
|
1 2 3 4 5 6 7 8 9 10 11
| [Unit] Description=Prometheus node_exporter
[Service] Type=simple ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9111 [Install] WantedBy=multi-user.target
|
启动服务
1 2 3
| systemctl daemon-reload systemctl enable node_exporter.service systemctl start node_exporter.service
|
为node_exporter添加nginx访问验证
如果没有htpasswd这个命令可以使用yum install httpd-tools
来安装
1 2 3 4 5 6 7
| $ htpasswd -c .htpasswd admin New password: Re-type new password: Adding password for user admin
|
添加反向代理配置,这里我用的9110作为反向代理的端口
1 2 3 4 5 6 7 8 9 10
| server { listen 0.0.0.0:9110; location / { auth_basic "Prometheus"; auth_basic_user_file "/usr/local/nginx/conf/servers/.htpasswd"; proxy_pass http://localhost:9111/; } }
|
然后重载nginx,配置到这一步可以打开浏览器ip:9110
访问就会提示需要输入账号密码
prometheus.yml添加node_exporter的代理验证信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| global: scrape_interval: 15s
scrape_configs: - job_name: prometheus static_configs: - targets: ["localhost:9090"] - job_name: local static_configs: - targets: ["192.168.110.6:9110"] basic_auth: username: admin password: admin
|