基于Grafana和Prometheus的监视系统(2):环境配置
0.基本说明
- 如何使用的组件的快速构建部署: docker镜像
- docker compose 方便容器的管理
1. 基本环境
- docker-ce [https://docs.docker.com/get-started/]
- docker componse [https://docs.docker.com/compose/install/]
2. 配置
- docker-compose.yml
docker 镜像包括: prometheus, node-expoter, grafana, pushgateway, elasticsearch
version: '3.3'
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9590:9090'
- '9501:9501'
networks:
- monitor-net
node-exporter:
image: prom/node-exporter:v0.15.2
ports:
- '9100:9100'
networks:
- monitor-net
grafana:
image: grafana/grafana
volumes:
- grafana_data:/var/lib/grafana
- ./grafana.ini:/etc/grafana/grafana.ini
environment:
- GF_SECURITY_ADMIN_PASSWORD=pass
depends_on:
- prometheus
ports:
- '3000:3000'
networks:
- monitor-net
pushgateway:
image: prom/pushgateway
ports:
- '9591:9091'
networks:
- monitor-net
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.0.1
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ports:
- 9500:9200
networks:
- esnet
elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:6.0.1
container_name: elasticsearch2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
networks:
- esnet
volumes:
grafana_data: {}
prometheus_data: {}
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet:
monitor-net:
docker-compose几个常用的命令
-
docker-compose stop
停止容器 -
docker-compose rm
移除容器 -
docker-compose up -d
后台启动
- prometheus.yml
global:
scrape_interval: 5s
external_labels:
monitor: 'my-monitor'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.1.223:9590']
- job_name: 'node resources'
scrape_interval: 10s
static_configs:
- targets: ['node-exporter:9100']
- job_name: 'pushgateway'
static_configs:
- targets: ['pushgateway:9091']
honor_labels: true
- job_name: 'ts_data_history'
static_configs:
- targets: ['192.168.1.222:9501']
- grafana.ini
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true
host = smtp.qq.com:465
user = aa@qq.com
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = aa
;cert_file =
;key_file =
skip_verify = true
from_address = aa@qq.com
from_name = lww
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com
[emails]
;welcome_email_on_sign_up = false
- elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"