使用Rancher快速搭建基于Prometheus+Grafan
2021-07-09 本文已影响0人
布朗XD
一、安装Rancher
Rancher不仅可以集中管理部署在任何基础设施上的Kubernetes集群,还可以实行统一的集中式身份验证和访问控制。
Rancher官网:
https://www.rancher.cn/
我们使用rancher1.6来搭建整个环境。
docker run -d --restart=unless-stopped -p 8080:8080 rancher/server
二、配置Prometheus
添加应用

添加服务node-exporter
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter
源代码如下,用Rancher进行配置



访问一下url测试:
http://127.0.0.1:9100/metrics
如果显示如下内容则成功:

添加服务prometheus
新建目录prometheus,编辑配置文件prometheus.yml
mkdir /opt/prometheus
cd /opt/prometheus/vim prometheus.yml
内容如下:
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['172.16.69.47:9100']
labels:
instance: localhost
注意:修改IP地址,这里的172.16.69.47就是本机地址
如果将来有多台机器,就配置多个job。
启动prometheus,代码如下:
docker run -d -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus


访问url:
http://172.16.69.47:9090/graph

添加服务grafana
新建空文件夹grafana-storage,用来存储数据
mkdir /opt/grafana-storage
设置权限
chmod 777 -R /opt/grafana-storage
因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!
启动grafana
代码如下
docker run -d \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \
grafana/grafana


访问url:
http://172.16.69.47:3000
默认账号密码为 admin/admin
添加数据源:

选择数据源地址,填入之前测试的Prometheus地址:

导入模板:

输入8919,导入模板:


最后在DashBoard可以看到监控页面:
