docker部署prometheus及node_exporter安装

本文介绍如何部署Prometheus监控系统及node_exporter,并通过systemctl进行管理。还介绍了如何为node_exporter添加nginx访问验证,以及如何在prometheus.yml中配置代理验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考地址:
https://www.prometheus.wang/quickstart/install-prometheus-server.html
https://spex.top/archives/systemd-prometheus-node-exporter.html

Prometheus

#创建容器之前先创建prometheus.yml文件,可百度查找模板或去官网下载prometheus的安装包里查找

docker run --name prom -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -d prom/prometheus

容器启动以后在浏览器打开ip:9090即可访问

node_exporter

#下载
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 &

#node_exporter启动的默认端口是9100,启动以后在浏览器打开ip:9100 即可查看监控数据
#查看node_exporter更多参数,可以用./node_exporter -h命令

使用systemctl来管理node_exporter

#创建管理文件
vi /etc/systemd/system/node_exporter.service
#内容
[Unit]
Description=Prometheus node_exporter

[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9111
 
 
[Install]
WantedBy=multi-user.target

启动服务

systemctl daemon-reload
systemctl enable node_exporter.service
systemctl start  node_exporter.service

为node_exporter添加nginx访问验证

如果没有htpasswd这个命令可以使用yum install httpd-tools来安装

$ htpasswd -c .htpasswd admin   
New password: 
Re-type new password: 
Adding password for user admin  


#admin为账号

添加反向代理配置,这里我用的9110作为反向代理的端口

server {
    listen 0.0.0.0:9110;
    location / {
      
      auth_basic "Prometheus";
      auth_basic_user_file "/usr/local/nginx/conf/servers/.htpasswd";#注意htpasswd的路径
      proxy_pass http://localhost:9111/;
    }
  }

然后重载nginx,配置到这一步可以打开浏览器ip:9110访问就会提示需要输入账号密码

prometheus.yml添加node_exporter的代理验证信息

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:           #这里注意缩进行,不然prometheus可能无法启动
         username: admin  #反向代理配置的账号
         password: admin  #反向代理配置的密码

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值