prometheus安装部署

下载

https://prometheus.io/download/

服务器直接下载

curl -O https://github.com/prometheus/prometheus/releases/download/v3.5.0/prometheus-3.5.0.linux-amd64.tar.gz

curl -O https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz

解压安装启动

tar -zxvf prometheus-2.45.0.linux-amd64.tar.gz
cd prometheus-2.45.0.linux-amd64/
nohup ./prometheus &

访问地址

访问地址:http://192.168.70.128:9090/

传统开机自启

echo "cd /root/prometheus-$prometheusbb.linux-amd64 && nohup ./prometheus &" >> /etc/rc.d/rc.local
chmod a+x /etc/rc.d/rc.local

指定端口和配置文件

./prometheus --config.file=/etc/prometheus/prometheus.yml \
             --web.listen-address=:9090 \
             --storage.tsdb.path=/data/prometheus

系统服务启动

创建启动文件

vim /etc/systemd/system/prometheus.service 

编写配置文件

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/修改为自己的路径/prometheus-3.5.0.linux-amd64/prometheus --web.listen-address=:9090修改为自己的端口 --config.file=/修改为自己的路径/prometheus-3.5.0.linux-amd64/prometheus.yml --storage.tsdb.path=/修改为自己的路径/prometheus-3.5.0.linux-amd64/data
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

默认端口

默认端口是 9090
指定端口:--web.listen-address=:9090

启停操作

systemctl daemon-reload
systemctl enable prometheus.service 
systemctl stop prometheus.service
systemctl start prometheus.service
systemctl status prometheus.service
systemctl restart prometheus.service 
systemctl status prometheus.service

配置节点

global:
  scrape_interval: 15s

scrape_configs:
  # 静态写法——直接写死 IP
  - job_name: 'node-static'
    static_configs:
      - targets:
        - '192.168.1.11:9110'   # 第 1 台被监控机
        - '192.168.1.12:9110'   # 第 2 台被监控机
        - '192.168.1.13:9110'   # 第 3 台被监控机

  # 文件发现写法——把 IP 写到单独 JSON/YAML 文件,便于自动扩缩
  - job_name: 'node-file'
    file_sd_configs:
      - files:
        - '/etc/prometheus/targets/nodes.yml'

/etc/prometheus/targets/nodes.yml 格式示例:

- targets: ['192.168.1.21:9110']
  labels:
    env: prod
- targets: ['192.168.1.22:9110']
  labels:
    env: test
图片[1]-prometheus安装部署-秋风落叶
图片[2]-prometheus安装部署-秋风落叶

登录验证

http://192.168.70.128:9090/metrics

图片[3]-prometheus安装部署-秋风落叶

添加其它节点数据

vim prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'node_exporter'
    static_configs:
      - targets: ['192.168.70.128:9100']

© 版权声明
THE END
点赞8 分享