二进制部署prometheus
下载并解压
wget https://github.com/prometheus/prometheus/releases/download/v2.37.0/prometheus-2.37.0.linux-amd64.tar.gz
tar xvf prometheus-2.37.0.linux-amd64.tar.gz
创建软连接
ln -sv /apps/prometheus-2.37.0.linux-amd64 /apps/prometheus
配置自动启动
--web.enable-lifecycle:配置热加载
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=/apps/prometheus/
ExecStart=/apps/prometheus/prometheus --config.file=/apps/prometheus/prometheus.yml --web.enable-lifecycle
[Install]
WantedBy=multi-user.target
启动
systemctl daemon-reload
systemctl restart prometheus
systemctl enable prometheus
查看端口
netstat -tunlp
热加载操作方法,修改完配置之后直接执行curl
curl -X POST http://10.0.0.9:9090/-/reload
安装node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvf node_exporter-1.3.1.linux-amd64.tar.gz
ln -sv /apps/node_exporter-1.3.1.linux-amd64 /apps/node_exporter
启动
cd /apps/node_exporter
./node_exporter
修改prometheus.yml,添加主机10.0.0.13端口好9100
vim /apps/prometheus/prometheus.yml
static_configs:
- targets: ["localhost:9090","10.0.0.13:9100"]
加载配置
curl -X POST http://10.0.0.9:9090/-/reload
浏览器访问下prometheus,可以看到多了一台10.0.0.13
配置一个node_exporter自动启动
[root@VM-0-13-centos ~]# cat /etc/systemd/system/node-exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/apps/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
systemctl start node-exporter.service
systemctl enable node-exporter.service
prometheus.yml可以添加多个job_name
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: ["localhost:9090","10.0.0.13:9100"]
- job_name: "prometheus-node"
static_configs:
- targets: ["10.0.0.12:9090","10.0.0.11:9100"]
安装Grafana
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.5.4-1.x86_64.rpm
yum install grafana-enterprise-8.5.4-1.x86_64.rpm
systemctl restart grafana-server.service
systemctl enable grafana-server.service
浏览器访问http://IP:9090 账号密码 admin. admin
添加数据源
修改之后点Save Test
访问官网找一个模板
https://grafana.com/grafana/dashboards/?dataSource=prometheus
导入id 1860点击load
选择数据源
效果图
11074