安装文件下载
文件下载地址:
prometheus-2.37.1.linux-amd64.tar.gz
pushgateway-1.4.3.linux-amd64.tar.gz
node_exporter-1.3.1.linux-amd64.tar.gz
alertmanager-0.24.0.linux-amd64.tar.gz
grafana-9.1.5.linux-amd64.tar.gz
将所有文件下载存放到 /opt/prom 目录并解压
prometheus 服务端部署
创建服务
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/prometheus-2.37.1.linux-amd64/prometheus --config.file=/opt/prom/prometheus-2.37.1.linux-amd64/prometheus.yml --web.listen-address=:9090 --web.enable-lifecycle
[Install]
WantedBy=multi-user.target
--web.enable-lifecycle
开启配置文件热加载,开启后修改 prometheus.yml 配置文件后不用重启 prometheus 服务,支持两种方式重新加载配置文件:
1、kill -HUP $(pidof prometheus)
2、curl -XPOST http://192.168.50.4:9090/-/reload
启动服务
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9090
浏览器访问:http://192.168.50.4:9090/
prometheus 推送网关部署
创建服务
vi /etc/systemd/system/pushgateway.service
[Unit]
Description=Prometheus Pushgateway
Documentation=https://prometheus.io/docs/instrumenting/pushing/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/pushgateway-1.4.3.linux-amd64/pushgateway --web.listen-address=:9091
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable pushgateway
systemctl start pushgateway
配置推送网关
编辑 prometheus.yml 文件,在 scrape_configs 配置下新增一个 job
- job_name: "push-metrics"
static_configs:
- targets: ["192.168.50.4:9091"]
重新载入配置
kill -HUP $(pidof prometheus)
prometheus 节点导出器部署
创建服务
vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus node_exporter
Documentation=https://prometheus.io/docs/instrumenting/exporters/
After=network.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/node_exporter-1.3.1.linux-amd64/node_exporter --web.listen-address=:9100
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9100
浏览器访问:http://192.168.50.4:9100/metrics
导出器配置
编辑 prometheus.yml 文件,在 scrape_configs 配置下新增一个 job
- job_name: "192.168.50.4"
static_configs:
- targets: ["192.168.50.4:9100"]
重新载入配置
kill -HUP $(pidof prometheus)
prometheus 告警管理器部署
创建服务
vi /etc/systemd/system/alertmanager.service
[Unit]
Description=Prometheus Alertmanager
Documentation=https://prometheus.io/docs/alerting/latest/overview/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/alertmanager-0.24.0.linux-amd64/alertmanager --config.file=/opt/prom/alertmanager-0.24.0.linux-amd64/alertmanager.yml --web.listen-address=:9093
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl enable alertmanager
systemctl start alertmanager
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 9093
浏览器访问:http://192.168.50.4:9093/
配置告警
将 prometheus.yml 文件的告警配置修改为如下内容:
alerting:
alertmanagers:
- static_configs:
- targets:
- 192.168.50.4:9093
重新载入配置
kill -HUP $(pidof prometheus)
Grafana 部署
创建服务
vi /etc/systemd/system/grafana.service
[Unit]
Description=Grafana Server
Documentation=https://grafana.com/docs/
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/opt/prom/grafana-9.1.5/bin/grafana-server --homepath /opt/prom/grafana-9.1.5 --config /opt/prom/grafana-9.1.5/conf/defaults.ini
[Install]
WantedBy=multi-user.target
通过 defaults.ini
配置文件中的 http_port
修改服务端口号,注释时使用英文分号,即 ;
启动服务
systemctl daemon-reload
systemctl enable grafana
systemctl start grafana
执行 netstat
命令查看端口是否启动
netstat -nltup | grep 3000
浏览器访问:http://192.168.50.4:3000/
初始账号密码:admin/admin
参考链接
https://prometheus.io/docs/prometheus/2.37/getting_started/
https://blog.csdn.net/qq_36546699/article/details/108316533
https://www.cnblogs.com/yjmyzz/p/how-to-install-prometheus-and-grafana.html
标签:opt,amd64,--,prometheus,Grafana,Prometheus,systemctl,linux,安装 From: https://www.cnblogs.com/nihaorz/p/16711443.html