centos7 部署Prometheus+Grafana
1、下载部署包
https://link.zhihu.com/?target=https%3A//prometheus.io/download/
https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/
https://prometheus.io/download/
https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/
组件介绍
node_exporter(用于监控每一台服务器的资源,采集agent,每一台都要装)
prometheus(数据源,装到主节点上)
grafana(可视化prometheus,装到主节点上)
2、部署安装
2.1、部署prometheus
wget https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/2.45.2%20_%202023-12-19/prometheus-2.45.2.linux-amd64.tar.gz --no-check-certificate
tar -zxvf prometheus-2.45.2.linux-amd64.tar.gz
#修改配置文件
vim prometheus.yml
static_configs:
- targets: ["localhost:9090"]
- job_name: 'linux-vm'
static_configs:
- targets: ['192.168.0.1:9100','192.168.0.2:9100','192.168.0.3:9100','192.168.0.4:9100','192.168.0.86:60023'] #填写所在的服务器ip端口,多个用 , 隔开
- job_name: 'TEST'
static_configs:
- targets: ['10.2.10.10:19100']
#临时后台启动
nohup ./prometheus --config.file=prometheus.yml --web.listen-address="172.17.0.1:9090" --web.enable-lifecycle > /tmp/prometheus.log 2>&1 &
#设置启动服务
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/workspace/prometheus/prometheus --config.file=/opt/workspace/prometheus/prometheus.yml --web.enable-lifecycle --web.listen-address=IP:9090
Restart=on-failure
[Install]
WantedBy=multi-user.target
2.2、部署grafana
2.2.1、普通安装
wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-9.5.9-1.x86_64.rpm
rpm -ivh grafana-9.5.9-1.x86_64.rpm
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
sudo /bin/systemctl start grafana-server.service
2.2.2、容器安装grafana
docker pull grafana/grafana
docker run -itd --name=grafana --restart=always -p 3000:3000 grafana/grafana
2.2.3、grafana配置面板
默认端口3000 admin/admin
配置采集数据源-datasources
http://172.17.0.1:9090
导入需要的模板编号,下载地址
https://grafana.com/grafana/dashboards/12633-linux/
12633
2.4、部署node_exporter
cp node_exporter /usr/local/bin/node_exporter
chmod 755 /usr/local/bin/node_exporter
./node_exporter --web.listen-address=192.168.0.1:9100
2.5 其他操作,grafana+Prometheus+node-export 容器化安装
/opt/workspace/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:
alertmanagers:
- static_configs:
- 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: ["172.17.0.1:9090"]
- job_name: 'S-Node'
static_configs:
- targets: ['10.22.33.222:19100','10.22.33.8:19100']
# pod-mon
- job_name: "docker-cadvisor"
static_configs:
- targets: ["172.17.0.1:8080"]
docker run -itd --name=grafana -p 3000:3000 --restart=always grafana/grafana
docker run -d --name=prometheus \
-v /opt/workspace/prometheus.yml:/etc/prometheus/prometheus.yml \
--restart=always \
-p 9090:9090 \
prom/prometheus
docker run -d --net host --restart always --name node-exporter prom/node-exporter
#
docker run -dp 19100:19100 --restart always --name node-exporter prom/node-exporter
#cadvisor 监控pod
docker run -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 8080:8080 --detach=true --name=cadvisor --net=host google/cadvisor

浙公网安备 33010602011771号