目录
二、下载prometheus和grafana、node-exporter镜像包
目前我使用这个
部署系统:Centos 7.2以上
# 关闭防火墙
service firewalld stop
# 不启用防火墙
systemctl disable firewalld
一、安装docker
yum -y install docker
systemctl start docker
# 设置docker开机启动
systemctl enable docker
二、下载prometheus和grafana、node-exporter镜像包
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
三、启动node-exporter
docker run -d --restart=always --name node-exporter \
-p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
-v /etc/localtime:/etc/localtime \
-v /etc/timezone:/etc/timezone \
--net="host" \
prom/node-exporter
# -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone 我后加的 解决时区问题
我使用这个
docker run -d -p 9100:9100 --restart=always --name node-exporter -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone prom/node-exporter
等待几秒钟,查看端口9100是否起来了
netstat -anpt
# 浏览器访问
http://192.168.233.131:9100/metrics
四、启动prometheus
编辑配置文件prometheus.yml
mkdir -p /opt/prom/{prometheus,prometheus/tsdb,prometheus/rules}
# 赋权限
chmod 777 -R /opt/prom/{prometheus,prometheus/tsdb,prometheus/rules}
cd /opt/prom/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 # 这个应该是监控node
static_configs:
- targets: ['192.168.91.132:9100']
labels:
instance: localhost
注意:修改IP地址,这里的192.168.91.132就是本机地址,监控node_exporter
#启动
docker run -d -p 9090:9090 --restart=always --name prometheus \
-u root \
-v /opt/prom/prometheus/tsdb:/etc/prometheus/tsdb \
-v /opt/prom/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone \
--privileged=true prom/prometheus \
--storage.tsdb.path=/etc/prometheus/tsdb \
--storage.tsdb.retention=7d \
--config.file=/etc/prometheus/prometheus.yml
# -v /etc/localtime:/etc/localtime -v /etc/timezone:/etc/timezone 我后加的,解决时区问题
# rules版本
docker run -d -p 9090:9090 --restart=always --name prome