Prometheus安装
二进制安装Prometheus-server
下载:https://prometheus.io/download/
- 安装
[root@jgswy-pro packet]# mkdir /data/apps
[root@jgswy-pro packet]# cd /data/apps/
[root@jgswy-pro apps]# ls
prometheus-2.45.5.linux-amd64.tar.gz
[root@jgswy-pro apps]# tar xvf prometheus-2.45.5.linux-amd64.tar.gz
[root@jgswy-pro apps]# ln -sv /data/apps/prometheus-2.45.5.linux-amd64 /data/apps/prometheus
"/data/apps/prometheus" -> "/data/apps/prometheus-2.45.5.linux-amd64"
[root@jgswy-pro apps]# ll
总用量 90516
lrwxrwxrwx. 1 root root 40 5月 21 10:03 prometheus -> /data/apps/prometheus-2.45.5.linux-amd64
drwxr-xr-x. 4 1001 127 132 5月 2 17:45 prometheus-2.45.5.linux-amd64
-rw-r--r--. 1 root root 92686411 5月 21 09:59 prometheus-2.45.5.linux-amd64.tar.gz
- 编写service文件
# cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/data/apps/prometheus/
ExecStart=/data/apps/prometheus/prometheus --config.file=/data/apps/prometheus/prometheus.yml --web.enable-lifecycle
[Install]
WantedBy=multi-user.target
- 启动服务监听9090端口
# systemctl daemon-reload && systemctl restart prometheus && systemctl enable prometheus.service
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:9090 [::]:*
二进制安装node_exporter
[root@jgswy-pro apps]# tar xvf node_exporter-1.8.0.linux-amd64.tar.gz
node_exporter-1.8.0.linux-amd64/
node_exporter-1.8.0.linux-amd64/NOTICE
node_exporter-1.8.0.linux-amd64/node_exporter
node_exporter-1.8.0.linux-amd64/LICENSE
[root@jgswy-pro apps]# ln -sv /data/apps/node_exporter-1.8.0.linux-amd64 /data/apps/node_exporter
"/data/apps/node_exporter" -> "/data/apps/node_exporter-1.8.0.linux-amd64"
[root@jgswy-pro apps]# systemctl daemon-reload && systemctl restart node-exporter && systemctl enable node-exporter.service
Created symlink from /etc/systemd/system/multi-user.target.wants/node-exporter.service to /etc/systemd/system/node-exporter.service.
端口监听9100
# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:9090 [::]:*
LISTEN 0 128 [::]:9100 [::]:*
配置采集node数据
[root@jgswy-pro prometheus]# vi prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
scrape_configs:
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: "prometheus-node"
static_configs:
- targets: ["localhost:9100"]
[root@jgswy-pro prometheus]# systemctl restart prometheus
- 验证
安装grafana
地址:https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1
# yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-11.0.0-1.x86_64.rpm
# systemctl restart grafana-server && systemctl enable grafana-server
监听端口3000
[root@jgswy-pro prometheus]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 [::]:3000 [::]:*
安装blackbox_exporter
[root@jgswy-pro apps]# tar xvf blackbox_exporter-0.25.0.linux-amd64.tar.gz
blackbox_exporter-0.25.0.linux-amd64/
blackbox_exporter-0.25.0.linux-amd64/NOTICE
blackbox_exporter-0.25.0.linux-amd64/blackbox_exporter
blackbox_exporter-0.25.0.linux-amd64/LICENSE
blackbox_exporter-0.25.0.linux-amd64/blackbox.yml
[root@jgswy-pro apps]# ln -sv blackbox_exporter-0.25.0.linux-amd64 blackbox_exporter
"blackbox_exporter" -> "blackbox_exporter-0.25.0.linux-amd64"
[root@jgswy-pro apps]# vi /etc/systemd/system/blackbox-exporter.service
[Unit]
Description=Prometheus Blackbox Exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/data/apps/blackbox_exporter/blackbox_exporter \
--config.file=/data/apps/blackbox_exporter/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@jgswy-pro apps]# systemctl restart blackbox-exporter.service && systemctl enable blackbox-exporter.service
安装Webhook-dingtalk
1、安装webhook-dingtalk插件
wget https://github.com/timonwong/prometheus-webhook-dingtalk/releases/download/v2.1.0/prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz
tar zxf prometheus-webhook-dingtalk-2.1.0.linux-amd64.tar.gz
mv prometheus-webhook-dingtalk-2.1.0.linux-amd64 /usr/local/prometheus/webhook-dingtalk
2、配置webhook-dingtalk使用systemd管理
cp /usr/local/prometheus/webhook-dingtalk/config.example.yml /usr/local/prometheus/webhook-dingtalk/config.yml
vim /usr/lib/systemd/system/webhook.service
[Unit]
Description=Prometheus-Server
After=network.target
[Service]
ExecStart=/usr/local/prometheus/webhook-dingtalk/prometheus-webhook-dingtalk --config.file=/usr/local/prometheus/webhook-dingtalk/config.yml
User=root
[Install]
WantedBy=multi-user.target
3、启动 && 开机自启
systemctl enable webhook.service --now
systemctl status webhook.service
4、验证,查看端口是否启动
netstat -anput |grep 8060