生产环境之Docker部署Prometheus+Grafana+InfluxDB+Skywalking

生产环境之Docker部署Prometheus+Grafana+InfluxDB+Skywalking

一、Prometheus监控docker容器

监控服务器 需要安装4个服务
  • Prometheus Server(普罗米修斯监控主服务器 )
  • Node Exporter (收集Host硬件和操作系统信息)
  • cAdvisor (负责收集Host上运行的容器信息)
  • Grafana (展示普罗米修斯监控界面)
被监控的只有安装2个
  • Node Exporter (收集Host硬件和操作系统信息)
  • cAdvisor (负责收集Host上运行的容器信息)

中文文档

需了解cadvisor

首先在监控服务器安装:

1.安装Node Exporter 来收集硬件信息

所有节点运行以下命令安装Node Exporter 容器
docker run -d -p 59100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
-v "/etc/localtime:/etc/localtime" \
--restart=always \
--name=node-exporter \ prom/node-exporter

2.安装cAdvisor 来收集容器信息 

所有节点运行以下命令来安装cAdvisor

docker run -d \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=58080:8080 \
--detach=true \
--restart=always \
--name=cadvisor \ -v "/etc/localtime:/etc/localtime" \ google/cadvisor:latest

3.安装普罗米修斯服务

首先在本地创建prometheus.yml这是普罗米修斯的配置文件
将下方内容写入到文件中
将监听的地址改为自己本机地址
mkdir -p /data/prometheus
vim /data/prometheus/prometheus.yml
# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
 
 
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
 
 
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
 
 
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
 
 
    static_configs:
    #监听的地址
    - targets: ['localhost:59090','localhost:59100']
 
 
  - job_name: 'xh-base-01'
    static_configs:
    - targets: ['172.18.68.236:58080','172.18.68.236:59100']
 
 
  - job_name: 'xh-base-02'
    static_configs:
    - targets: ['172.18.69.43:58080','172.18.69.43:59100']
 
  - job_name: 'xh-base-03'
    static_configs:
    - targets: ['172.18.69.44:58080','172.18.69.44:59100']
 
  - job_name: 'xh-master-01'
    static_configs:
    - targets: ['172.18.69.40:58080','172.18.69.40:59100']
 
  - job_name: 'xh-master-02'
    static_configs:
    - targets: ['172.18.69.41:58080','172.18.69.41:59100']
 
  - job_name: 'xh-master-03'
    static_configs:
    - targets: ['172.18.69.42:58080','172.18.69.42:59100']

启动容器

docker run -d -p 59090:9090 \
-v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v "/etc/localtime:/etc/localtime" \
--restart=always \
--name prometheus \ prom/prometheus:v2.27.1
 
当Prometheus容器启动成功后访问
 

二、在DockerMachine上运行Grafana

docker run -d -i -p 53000:3000 \
-v "/etc/localtime:/etc/localtime:ro" \
-e "GF_SERVER_ROOT_URL=http://grafana.xh.sunli.work" \
-e "GF_SECURITY_ADMIN_PASSWORD=123456" \
--restart=always \
--name grafana \ grafana/grafana:7.2.0
  • nginx配置
server{
       listen       80;
        server_name  grafana.xh.sunli.work;
        location / {
                proxy_pass http://127.0.0.1:53000;
                proxy_connect_timeout      5;
                proxy_read_timeout         10;
                proxy_send_timeout         10;
        }
    }
  • 添加Prometheus
"Configuration"——>"Data Sources"——>"Add data source"——>"URL:http://172.18.68.221:59090/"——>"Save & Test"     测试成功并保存
Create——>"import"——>"8321"——>"Load"——>"Import"    (推荐好用模板:8321、8919、2204、13978、11558、12232)
  • 展示
  • 安装实用插件
docker exec -it grafana sh
$ cd /usr/share/bin/
$ grafana-cli plugins install alexanderzobnin-zabbix-app 安装zabbix插件
$ grafana-cli plugins install grafana-worldmap-panel 安装世界地图插件
$ grafana-cli plugins install grafana-clock-panel 安装时间插件
$ grafana-cli plugins install grafana-piechart-panel 安装圆饼插件
 

三、InfluxDB的安装

说明当前最新版2.0的influxdb自带UI监控界面,与Granfan融合有点问题(only me),而1.7的版本需要进容器里创建账号密码,所以选定1.8的版本
docker run -itd -p 58086:8086 -p 2003:2003 \
        -e INFLUXDB_GRAPHITE_ENABLED=true \
        -e INFLUXDB_DB=xuehua_db0 \
        -e INFLUXDB_ADMIN_USER=admin -e INFLUXDB_ADMIN_PASSWORD=123456 \
        -e INFLUXDB_USER=xuehua -e INFLUXDB_USER_PASSWORD=123456 \
        --name=xh-influxdb \
        influxdb:1.8
  • 添加influxdb
"Configuration"——>"Data Sources"——>"Add data source"——>"URL:http://172.18.68.221:58086/"——>"Database:xuehua_db0"——>"User:xuehua"——>"Password:BaoDian1608"——>"Save & Test"     测试成功并保存
 
 

四、Docker部署skywalking

  • 启动 SkyWalking Server
docker run -itd \
--name skywalking-oap \
--restart=always \
-p 1234:1234 -p 11800:11800 -p 12800:12800 \
-e SW_STORAGE=elasticsearch7 \
-e SW_STORAGE_ES_CLUSTER_NODES=172.18.169.173:9200 \
apache/skywalking-oap-server:8.3.0-es7
  • 启动 UI
docker run -itd  \
--name skywalking-ui \
--restart=always  \
-p 48080:8080 \
--link skywalking-oap:skywalking-oap \
-e SW_OAP_ADDRESS=skywalking-oap:12800 \
apache/skywalking-ui:8.3.0
  • nginx配置
htpasswd -c /usr/local/nginx/conf/base-auth/passwd.db xuehua
server {
        listen       80;
        server_name  skywalking.xh.sunli.work;
        location / {
            proxy_pass http://127.0.0.1:48080;
            auth_basic            "Basic Auth";
            auth_basic_user_file  "/usr/local/nginx/conf/base-auth/passwd.db";
        }
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
posted @ 2021-06-24 15:02  梦里花落知多少sl  阅读(3689)  评论(0编辑  收藏  举报