prometheus普罗米修斯安装部署

下载

https://prometheus.io/download/

linux 安装

解压安装启动

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 格式示例:

#方式1:直接加目标地址即可
wangj1028@Mac etc % more /opt/homebrew/etc/nodes.yml 
- targets: ['106.14.95.21:9100']
- targets: ['111.229.194.1:9100']

#方式2:还可以添加相关的标签
- 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']

mac 安装

通过 Homebrew 安装

# 安装 Prometheus
brew install prometheus

# 启动 Prometheus 服务,并设置为开机自启
brew services start prometheus

验证安装

启动后,打开浏览器访问 http://localhost:9090。如果能看到 Prometheus 的 Web 界面,就说明安装和启动都成功了

停止服务:brew services stop prometheus

重启服务:brew services restart prometheus

升级 Prometheus:brew upgrade prometheus (升级后通常需要重启服务)

配置文件位置:Prometheus 的主配置文件 prometheus.yml 位于:

Intel 芯片 Mac:/usr/local/etc/prometheus.yml

Apple Silicon 芯片 Mac:/opt/homebrew/etc/prometheus.yml
  • 查看状态
#方式1:
wangj1028@Mac ~ % brew services info prometheus
prometheus (homebrew.mxcl.prometheus)
Running: ✔
Loaded: ✔
Schedulable: ✘
User: wangj1028
PID: 3641

#方式2:
wangj1028@Mac ~ % brew services list | grep prometheus
prometheus started         wangj1028 ~/Library/LaunchAgents/homebrew.mxcl.prometheus.plist

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