prometheus2.40.2

1、部署prometheus server
官网下载地址:https://prometheus.io/download/

[root@ubuntu2004 ~]#tar xf prometheus-2.40.2.linux-amd64.tar.gz -C /usr/local/

[root@ubuntu2004 ~]#cd /usr/local/
[root@ubuntu2004 local]#mv prometheus-2.40.2.linux-amd64 prometheus-2.40.2
[root@ubuntu2004 local]#ln -s /usr/local/prometheus-2.40.2 /usr/local/prometheus

[root@ubuntu2004 local]#cd prometheus
[root@ubuntu2004 prometheus]#ln -s /usr/local/prometheus/prometheus /usr/local/bin/
[root@ubuntu2004 prometheus]#cp prometheus.yml{,.bak}

#基于systemd管理启动、停止
[root@ubuntu2004 prometheus]#vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Monitoring system and time series database
Documentation=https://prometheus.io/docs/introduction/overview/

[Service]
Restart=always
#User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
SendSIGKILL=no
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target

[root@ubuntu2004 prometheus]#systemctl daemon-reload

[root@ubuntu2004 prometheus]#systemctl stop prometheus.service
[root@ubuntu2004 prometheus]#systemctl start prometheus.service
[root@ubuntu2004 prometheus]#ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=772,fd=3))
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=739,fd=13))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=772,fd=4))
LISTEN 0 4096 *:9090 *:* users:(("prometheus",pid=6640,fd=3))

prometheus2.40.2

2、部署node exporter
#prometheus节点:
[root@ubuntu2004 ~]#tar xf node_exporter-1.4.0.linux-amd64.tar.gz
[root@ubuntu2004 ~]#cd node_exporter-1.4.0.linux-amd64/
[root@ubuntu2004 node_exporter-1.4.0.linux-amd64]#mv node_exporter /usr/local/bin/

[root@ubuntu2004 node_exporter-1.4.0.linux-amd64]#vim /usr/lib/systemd/system/exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
#User=prometheus
ExecStart=/usr/local/bin/node_exporter --collector.ntp --collector.mountstats --collector.systemd --collector.ethtool --collector.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always

[Install]
WantedBy=multi-user.target


[root@ubuntu2004 node_exporter-1.4.0.linux-amd64]#systemctl daemon-reload
[root@ubuntu2004 node_exporter-1.4.0.linux-amd64]#systemctl start exporter.service

[root@ubuntu2004 ~]#ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=772,fd=3))
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=739,fd=13))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=772,fd=4))
LISTEN 0 4096 *:9090 *:* users:(("prometheus",pid=6640,fd=3))
LISTEN 0 4096 *:9100 *:* users:(("node_exporter",pid=51385,fd=7))
#其他被监控节点:
[root@ubuntu2004 ~]#tar xf node_exporter-1.4.0.linux-amd64.tar.gz
[root@ubuntu2004 ~]#mv node_exporter-1.4.0.linux-amd64/node_exporter /usr/local/bin/
[root@ubuntu2004 ~]#vim /usr/lib/systemd/system/exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always

[Install]
WantedBy=multi-user.target

[root@ubuntu2004 ~]#systemctl daemon-reload
[root@ubuntu2004 ~]#systemctl start exporter.service

[root@ubuntu2004 ~]#ss -ntlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=739,fd=13))
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=772,fd=3))
LISTEN 0 4096 *:9100 *:* users:(("node_exporter",pid=46958,fd=3))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=772,fd=4))
3、修改prometheus配置监控各节点
[root@ubuntu2004 prometheus]#pwd
/usr/local/prometheus
[root@ubuntu2004 prometheus]#vim prometheus.yml
......
- job_name: "node_exporter"
metrics_path: '/metrics'
scheme: 'http'
static_configs:
- targets:
- "10.0.0.101:9100"
- "10.0.0.102:9100"
- "10.0.0.103:9100"
[root@ubuntu2004 prometheus]#systemctl restart prometheus.service
发表评论

相关文章