Prometheus部署
在master主机上安装docker
安装docker
# 获取源
[root@master ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
配置docker-ce 源
[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
安装docker
[root@master ~]# yum -y install docker-ce
配置docker镜像 加速
[root@master ~]# mkdir -p /etc/docker
[root@master ~]# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://wn5c7d7w.mirror.aliyuncs.com"]
}
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl restart docker
拉取prom/Prometheus官方镜像
[root@master ~]# docker pull prom/prometheus
# 查看
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
prom/prometheus latest gdi98gd4g6d8 3 days ago 201MB
在client上获取prometheus.yml配置文件
prometheus官方
# 将prometheus的安装包上传至client主机中并解压,将prometheus.yaml配置文件传输到master主机的/opt目录中
[root@client ~]# ls
anaconda-ks.cfg prometheus-2.31.1.linux-amd64.tar.gz
[root@client ~]# tar xf prometheus-2.31.1.linux-amd64.tar.gz
[root@client ~]# cd prometheus-2.31.1
[root@client prometheus-2.31.1]# scp /root/prometheus-2.31.1/prometheus.yml 192.168.220.9:/opt/prometheus.yml
root@192.168.220.10's password:
prometheus.yml
使用官方镜像运行prometheus 容器,进行端口和目录文件映射
# 查看配置文件
[root@master ~]# cat /opt/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: ["localhost:9090"]
# 映射端口和配置文件到主机上且设置随docker启动而启动容器
[root@master ]# docker run -d --name prometheus --restart always -p 9090:9090 -v /opt/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
hg654gd5f4g5d4g0d4fg5dgdf84h0gd3c01s3dr4t6h0fh406sf40s64h6tg406g
# 查看容器运行状态
[root@master ~]# docker ps | grep prometheus
hg654gd5f4g5 prom/prometheus "/bin/prometheus --c…" 10 minutes ago Up 2 minutes 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
访问
Grafana部署
拉取Grafana官方镜像
[root@master ~]# docker pull grafana/grafana
运行grafan容器,并映射端口提供服务
[root@master ~]# docker run -dit --name grafan -p 3000:3000 grafana/grafana
gd6484g69w04n8yu7j1t9g2d6f82vh9t3c987ht24b82yh44hjrct6382h4vy82i
[root@master ~]# docker ps | grep grafan
gd6484g69w04 grafana/grafana "/run.sh" 11 seconds ago Up 8 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafan
访问Grafana网页
第一次登入,需要修改密码
首页
导入下载好的模板
Grafana模板下载: 地址