上传文件至指定目录
# 上传文件至/home/zhoujibin/package
# 主程序
/home/zhoujibin/package/prometheus-2.45.0.linux-amd64.tar.gz
# node节点程序
/home/zhoujibin/package/node_exporter-1.6.1.linux-amd64.tar.gz
# 可视化软件
/home/zhoujibin/package/grafana-10.1.1.linux-amd64.tar.gz
安装软件
安装prometheus
参考:https://blog.csdn.net/qq_31725371/article/details/114697770
解压安装包
tar -xvf /home/zhoujibin/package/prometheus-2.45.0.linux-amd64.tar.gz -C /home/zhoujibin
编写自启服务
vim /usr/lib/systemd/system/prometheus.service
# begin
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/home/zhoujibin/prometheus-2.45.0.linux-amd64/prometheus --config.file=/home/zhoujibin/prometheus-2.45.0.linux-amd64/prometheus.yml --web.listen-address=:19090 --storage.tsdb.retention.time=12h --web.enable-lifecycle
[Install]
WantedBy=multi-user.target
# end
:wq
systemctl daemon-reload
# 设置开机自启
systemctl enable prometheus.service
启动服务
service prometheus start
# 查看启动状态
service prometheus status
安装node_export
需要监控的的节点都需要安装
解压安装包
tar -xvf /home/zhoujibin/package/node_exporter-1.6.1.linux-amd64.tar.gz -C /home/zhoujibin/
编写自启服务
vim /usr/lib/systemd/system/node_exporter.service
# begin
[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/home/zhoujibin/node_exporter-1.6.1.linux-amd64/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
# end
:wq
systemctl daemon-reload
# 设置开机自启
systemctl enable node_exporter.service
启动服务
service node_exporter start
# 查看启动状态
service node_exporter status
安装nginx-exporter
解压安装包
mkdir /home/zhoujibin/nginx-prometheus-exporter_0.11.0_linux_amd64;
tar -xvf /home/zhoujibin/package/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz -C /home/zhoujibin/nginx-prometheus-exporter_0.11.0_linux_amd64
编写自启服务
vim /usr/lib/systemd/system/nginx_exporter.service
# begin
[Unit]
Description=nginx_exporter
After=network.target
[Service]
ExecStart=/home/zhoujibin/nginx-prometheus-exporter_0.11.0_linux_amd64/nginx-prometheus-exporter -nginx.scrape-uri=http://192.168.0.12:28888/nginx_status
Restart=on-failure
[Install]
WantedBy=multi-user.target
# end
:wq
systemctl daemon-reload
# 设置开机自启
systemctl enable nginx_exporter.service
启动服务
service nginx_exporter start
# 查看启动状态
service nginx_exporter status
配置监控节点信息
修改配置
# 配置节点根据实际情况调整即可,此次监控nginx和appn01
vim /home/zhoujibin/prometheus-2.45.0.linux-amd64/prometheus.yml
# 注意,若web.listen-address中的端口做了修改,- targets: ["localhost:19090"] 中的端口也需要做对应的改动
- job_name: 'nginx'
static_configs:
- targets: ["nginx:9100"]
- job_name: 'appn01'
static_configs:
- targets: ["appn01:9100"]
重启服务
service prometheus restart
安装grafana
解压安装包
tar -xvf /home/zhoujibin/package/grafana-10.1.1.linux-amd64.tar.gz -C /home/zhoujibin/
编写自启服务
vim /usr/lib/systemd/system/grafana-server.service
# begin
[Unit]
Description=grafana
After=network.target
[Service]
ExecStart=/home/zhoujibin/grafana-10.1.1/bin/grafana-server -homepath /home/zhoujibin/grafana-10.1.1
Restart=on-failure
[Install]
WantedBy=multi-user.target
# end
:wq
systemctl daemon-reload
# 设置开机自启
systemctl enable grafana-server.service
启动服务
service grafana-server start
# 查看启动状态
service grafana-server status