一、在监控端安装prometheus
1.下载prometheus到/opt
https://prometheus.io/download/
2.解压到/usr/local/
tar xf prometheus-2.21.0-rc.0.linux-amd64.tar.gz -C /usr/local/
3.重命名
mv /usr/local/prometheus-2.21.0-rc.0.linux-amd64/ /usr/local/prometheus
二、启动prometheus
1.以默认9090端口
/usr/local/prometheus/prometheus —config.file=”/usr/local/prometheus/prometheus.yml” &
2.以systemd管理
vim /usr/lib/systemd/system/prometheus.service
#[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/usr/local/prometheus/prometheus —config.file=/usr/local/prometheus/prometheus.yml —web.read-timeout=5m —web.max-connections=10 —storage.tsdb.retention=15d —storage.tsdb.path=/prometheus/data —query.max-concurrency=20 —query.timeout=2m
User=root
[Install]
WantedBy=multi-user.target#
systemctl daemon-reload
systemctl restart prometheus.service
3.访问prometheus主界面
通过浏览器访问http://服务器IP:9090就可以访问到prometheus的主界面,点Status->Targets可以看到只监控了本机。
三、在被控端安装node_exporter组件
1.下载node_exporter到/opt
https://prometheus.io/download/
2.解压到/usr/local/
tar xf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
3.重命名
mv /usr/local/node_exporter-1.0.1.linux-amd64/ /usr/local/node_exporter
四、启动node_exporter
1.以默认9100端口
nohup /usr/local/node_exporter/node_exporter &
2.以systemd管理
vim /usr/lib/systemd/system/node_exporter.service
#[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/home/node_exporter/node_exporter
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target#
systemctl daemon-reload
systemctl restart node_exporter
五、连接prometheus与node_exporter组件
1.在prometheus的配置文件中添加job
vim /usr/local/prometheus/prometheus.yml
2.重启prometheus服务
systemctl restart prometheus.service