服务器安装
1.下载镜像包
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
2.启动node-exporter
docker run -d --privileged=true --name=nodeexporter \
-p 9100:9100\
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter \
3.启动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: ['192.168.91.132:9100']
labels:
instance: localhost
注意:修改IP地址,这里的192.168.91.132就是本机地址
启动prometheus
docker run -d --privileged=true --name=prometheus \
-p 9090:9090 \
-v /etc/localtime:/etc/localtime \
-v /opt/prometheus/data:/etc/prometheus \
prom/prometheus --web.enable-lifecycle \
--config.file=/etc/prometheus/prometheus.yml
访问url:http://192.168.91.132:9090/graph
效果
访问targets,url如下:http://192.168.91.132:9090/targets
效果如下:
4.启动grafana
新建空文件夹grafana-storage,用来存储数据
mkdir /opt/grafana-storage
设置权限
chmod 777 -R /opt/grafana-storage
因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!
启动grafana
docker run -d --privileged=true --name=grafana \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \<