文章目录
Prometheus安装
安装go、wget
yum -y install go
yum -y install wget
下载Prometheus
cd /usr/local
wget https://github.com/prometheus/prometheus/releases/download/v2.45.4/prometheus-2.45.4.linux-amd64.tar.gz
tar -zxvf prometheus-2.45.4.linux-amd64.tar.gz
mv prometheus-2.45.4.linux-amd64 prometheus
cd 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.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["192.168.40.176:9090"]
- job_name: "主机地址"
static_configs:
- targets: ["192.168.xx.177:9100","192.168.xx.178:9100","192.168.xx.179:9100","192.168.xx.180:9100","192.168.xx.181:9100","192.168.xx.182:9100"]
运行Prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
关闭Prometheus
pkill prometheus
添加服务并设置开机启动
vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable prometheus.service
pkill prometheus
systemctl start prometheus.service
systemctl status prometheus.service
验证:浏览器打开IP:9090端口
Grafana安装
下载-安装-启动-自动启动-查看端口
wget https://mirrors.aliyun.com/grafana/yum/rpm/Package/grafana-enterprise-10.1.0-1.x86_64.rpm
rpm -ivh grafana-enterprise-10.1.0-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
netstat -natp | grep :3000
验证
访问ip:3000 账户:admin 密码:admin
更换中文
vi /usr/share/grafana/conf/defaults.ini
将default_language = en-US改为 zh-Hans
添加Prometheus数据源
按要求输入被监控端地址
更换仪表盘
仪表盘下载地址https://grafana.com/grafana/dashboards
文件为.json结尾
上传加载即可
node_exporter安装(被监控端)
下载-解压-更名-开放端口-重新加载-生成目录-生成日志文件
cd /opt
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar -zxvf node_exporter-1.7.0.linux-amd64.tar.gz
mv node_exporter-1.7.0.linux-amd64 node_exporter
sudo firewall-cmd --add-port=9100/tcp --permanent
sudo firewall-cmd --reload
mkdir -p /applog/node_exporter/
touch /applog/node_exporter/node_exporter.log
cd node_exporter
编辑脚本-脚本文件-授权
[root@kvm1 node_exporter]# vi node_exporter.sh
#!/bin/bash
/opt/node_exporter/node_exporter &>> /applog/node_exporter/node_exporter.log
chmod +x node_exporter.sh
添加系统文件重置-自启动-启动-状态
vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
# 启动脚本
ExecStart=/opt/node_exporter/node_exporter.sh
[Install]
WantedBy=multi-user.target
重置-自启动-启动-状态
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
systemctl status node_exporter
重启Prometheus,查看仪表盘,被控端会逐渐上线
systemctl restart prometheus