1.服务器安装docker
安装docker依赖环境
yum -y install yum-utils device-mapper-persistent-data lvm2
设置国内镜像源地址
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装Docker缓存
yum makecache fast
安装Docker的服务
yum -y install docker-ce
启动Docker服务
systemctl start docker
设置开机自动启动
systemctl enable docker
2.被监控的服务器安装,node-exporter
拉取镜像
docker pull prom/node-exporter
启动镜像
docker run --name=node-exporter -p 9100:9100 -itd prom/node-exporter
3.安装prometheus,收集被监控服务器的信息
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml
输入如下信息,IP改为被监控的IP
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: node1
static_configs:
- targets: ['IP:9100']
labels:
instance: IP
启动prometheus
docker run -d -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus:latest
浏览器访问地址:http://IP:9090/targets
4.安装grafana
docker pull grafana/grafana
docker run -d -p 3000:3000 --name=jmeterGrafana grafana/grafana
浏览器访问:http://ip:3000(账号密码都是:admin)
配置数据源:
填写prometheus地址:
新增监控模板:
搜索 8919模板:
最后的结果:
5.新增监控服务器
执行第1步,安装docker
执行第2步,安装node-exporter
修改:
prometheus.yml中的文件内容
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: node1
static_configs:
- targets: ['IP:9100']
labels:
instance: IP
- job_name: node2
static_configs:
- targets: ['IP:9100']
labels:
instance: IP
停止prometheus的docker:
docker ps
docker stop 67fc771a6e67
删除prometheus的镜像
docker images
docker rm prometheus
启动prometheus镜像
docker run -d -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus:latest
结果