Docker初见(六)Docker 安装Prometheus和Grafana

本次安装Prometheus和Grafana版本如下:

  • prom/node-exporter
  • prom/prometheus
  • prom/alertmanager
  • grafana/grafana

1.下载镜像包

docker pull prom/node-exporter
docker pull prom/prometheus
prom/alertmanager
docker pull grafana/grafana

2.启动node-exporter

docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--name node-exporter \
prom/node-exporter

访问http://192.168.130.131:9100/metrics
成功如下图所示:

node-exporter

3. 启动alertmanager

1)建立配置和数据文件夹文件夹

#新建空文件夹grafana-storage,用来存储数据
mkdir /home/prometheus/alertmanager/
mkdir /home/prometheus/alertmanager/data/
mkdir /home/prometheus/alertmanager/config/
#设置权限
chmod 777 -R /home/prometheus/alertmanager/
#创建配置文件
cd /home/prometheus/alertmanager/config/
vi alertmanager.yml

内容如下:

global:
  resolve_timeout: 1m
  # The smarthost and SMTP sender used for mail notifications.
  #smtp_smarthost: ''
  #smtp_from: ''
  #smtp_auth_username: ''
  #smtp_auth_password: ''

route:
  receiver: 'default-receiver'
    # The labels by which incoming alerts are grouped together. For example,
  # multiple alerts coming in for cluster=A and alertname=LatencyHigh would
  # be batched into a single group.
  #group_by: ['alertname']

  # When a new group of alerts is created by an incoming alert, wait at
  # least 'group_wait' to send the initial notification.
  # This way ensures that you get multiple alerts for the same group that start
  # firing shortly after another are batched together on the first
  # notification.
  # group_wait: 5s

  # When the first notification was sent, wait 'group_interval' to send a batch
  # of new alerts that started firing for that group.
  # group_interval: 30s

  # If an alert has successfully been sent, wait 'repeat_interval' to
  # resend them.
  repeat_interval: 1m
receivers:
  - name: 'default-receiver'

2)启动alertmanager,3个容器构建集群

#alertmanager1  
docker run -d -p 9093:9093 -p 9094:9094 \
-v /home/prometheus/alertmanager/config/alertmanager.yml:/etc/alertmanager/config.yml \
-v /home/prometheus/alertmanager/data:/alertmanager/data \
--name alertmanager1  prom/alertmanager \
--config.file="/etc/alertmanager/config.yml" \
--storage.path=/alertmanager/data \
- -web.external-url=http://alertmanager1:9083 \
--cluster.listen-address=alertmanager1:9094 \
--cluster.peer alertmanager2:9084 \
--cluster.peer alertmanager3:9074

#alertmanager2
docker run -d -p 9083:9083 -p 9084:9084 \
-v /home/prometheus/alertmanager/config/alertmanager.yml:/etc/alertmanager/config.yml \
-v /home/prometheus/alertmanager/data:/alertmanager/data \
--name alertmanager2  prom/alertmanager \
--config.file="/etc/alertmanager/config.yml" \
--storage.path=/alertmanager/data \
--cluster.listen-address=alertmanager2:9084 \
--cluster.peer alertmanager1:9094 \
--cluster.peer alertmanager3:9074

#alertmanager3
docker run -d -p 9073:9073 -p 9074:9074 \
-v /home/prometheus/alertmanager/config/alertmanager.yml:/etc/alertmanager/config.yml \
-v /home/prometheus/alertmanager/data:/alertmanager/data \
--name alertmanager3  prom/alertmanager \
--config.file="/etc/alertmanager/config.yml" \
--storage.path=/alertmanager/data \
--cluster.listen-address=alertmanager3:9074 \
--cluster.peer alertmanager1:9094 \
--cluster.peer alertmanager2:9084

4.启动prometheus

1)新建目录prometheus,编辑配置文件prometheus.yml

mkdir /home/prometheus
cd /home/prometheus/
vi prometheus.yml

内容如下:

global:
  scrape_interval:     60s
  evaluation_interval: 60s
alerting:
  alertmanagers:
  - scheme: http
    static_configs:
    - targets:
      - "192.168.130.131:9093"
      - "192.168.130.131:9083"
      - "192.168.130.131:9073"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['192.168.130.131:9090']
        labels:
          instance: prometheus
 
  - job_name: linux
    static_configs:
      - targets: ['192.168.130.131:9100']
        labels:
          instance: localhost

job_name就是任务项,可增加;192.168.130.131就是本机ip

2)启动prometheus

docker run  -d \
-p 9090:9090 \
-v /home/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  \
--name prometheus prom/prometheus

访问http://192.168.130.131:9090/graph
成功如下图:

prometheus

4.启动grafana

1)建立数据文件夹

#新建空文件夹grafana-storage,用来存储数据
mkdir /home/prometheus/grafana-storage
#设置权限
chmod 777 -R /home/prometheus/grafana-storage

2)启动grafana

docker run -d \
-p 3000:3000 \
--name=grafana \
-v /home/prometheus/grafana-storage:/var/lib/grafana \
grafana/grafana

访问http://192.168.130.131:3000/
成功如下图:

grafana

默认用户名/密码:admin/admin

你可能感兴趣的:(Docker初见(六)Docker 安装Prometheus和Grafana)