设为首页收藏本站

安徽论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 25851|回复: 0

Prometheus容器化部署的实践方案

[复制链接]

90

主题

513

回帖

1048

积分

金牌会员

Rank: 6Rank: 6

积分
1048
发表于 2022-3-26 11:04:19 | 显示全部楼层 |阅读模式
网站内容均来自网络,本站只提供信息平台,如有侵权请联系删除,谢谢!
环境

            主机名            IP地址            服务                                    prometheus            192.168.237.137            prometheus、grafana                            node-exporter            192.168.237.131            node_exporter        容器化部署prometheus

1、安装docker
  1. [root@prometheus ~]# docker version
  2. Client: Docker Engine - Community
  3. Version:           20.10.11
  4. API version:       1.41
  5. Go version:        go1.16.9
  6. Git commit:        dea9396
  7. Built:             Thu Nov 18 00:36:58 2021
  8. OS/Arch:           linux/amd64
  9. Context:           default
  10. Experimental:      true

  11. Server: Docker Engine - Community
  12. Engine:
  13.   Version:          20.10.11
  14.   API version:      1.41 (minimum version 1.12)
  15.   Go version:       go1.16.9
  16.   Git commit:       847da18
  17.   Built:            Thu Nov 18 00:35:20 2021
  18.   OS/Arch:          linux/amd64
  19.   Experimental:     false
  20. containerd:
  21.   Version:          1.4.12
  22.   GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
  23. runc:
  24.   Version:          1.0.2
  25.   GitCommit:        v1.0.2-0-g52b36a2
  26. docker-init:
  27.   Version:          0.19.0
  28.   GitCommit:        de40ad0
复制代码
2、运行prometheus容器
  1. //拉取镜像
  2. [root@prometheus ~]# docker pull prom/prometheus
  3. Using default tag: latest
  4. latest: Pulling from prom/prometheus
  5. 3cb635b06aa2: Pull complete
  6. 34f699df6fe0: Pull complete
  7. 33d6c9635e0f: Pull complete
  8. f2af7323bed8: Pull complete
  9. c16675a6a294: Pull complete
  10. 827843f6afe6: Pull complete
  11. 3d272942eeaf: Pull complete
  12. 7e785cfa34da: Pull complete
  13. 05e324559e3b: Pull complete
  14. 170620261a59: Pull complete
  15. ec35f5996032: Pull complete
  16. 5509173eb708: Pull complete
  17. Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb
  18. Status: Downloaded newer image for prom/prometheus:latest
  19. docker.io/prom/prometheus:latest

  20. //在/opt目录下提供prometheus的默认配置文件
  21. [root@prometheus ~]# ls /opt/
  22. prometheus.yml

  23. //运行容器
  24. ##--restart always 总是重启,开机自启
  25. ## 将本地提供的配置文件映射到容器,ro 容器内只读
  26. [root@prometheus ~]# docker run --name prometheus -d --restart always -p 9090:9090 -v /opt/prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus:latest
  27. a0ba5535f0ea3b0f44574fd237802f2ef19f4624c3752c3bf8122a4d79a26428
  28. [root@prometheus ~]# docker ps
  29. CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
  30. a0ba5535f0ea   prom/prometheus:latest            "/bin/prometheus --c…"   11 seconds ago   Up 11 seconds             0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus

  31. //查看端口
  32. [root@prometheus ~]# ss -anltu
  33. Netid     State      Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process     
  34. tcp       LISTEN     0           128                    0.0.0.0:22                  0.0.0.0:*                    
  35. tcp       LISTEN     0           128                    0.0.0.0:9090                0.0.0.0:*                    
  36. tcp       LISTEN     0           128                       [::]:22                     [::]:*                    
  37. tcp       LISTEN     0           128                       [::]:9090                   [::]:*                    
复制代码
使用ip+9090/targets访问prometheus默认网页

部署node_exporter
  1. //下载安装包
  2. [root@node-exporter ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz
  3. [root@node-exporter ~]# ls
  4. anaconda-ks.cfg  node_exporter-1.3.0.linux-amd64.tar.gz

  5. //解压
  6. [root@node-exporter ~]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
  7. [root@node-exporter ~]# mv /usr/local/node_exporter-1.3.0.linux-amd64/ /usr/local/node_exporter
  8. [root@node-exporter ~]# ls /usr/local/
  9. bin  etc  games  include  lib  lib64  libexec  node_exporter  sbin  share  src

  10. //编写service文件,启动并开机自启
  11. [root@node-exporter ~]# cat /usr/lib/systemd/system/node_exporter.service
  12. [unit]
  13. Description=The node_exporter Server
  14. After=network.target

  15. [Service]
  16. ExecStart=/usr/local/node_exporter/node_exporter
  17. Restart=on-failure
  18. RestartSec=15s
  19. SyslogIdentifier=node_exporter

  20. [Install]
  21. WantedBy=multi-user.target
  22. [root@node-exporter ~]# systemctl daemon-reload
  23. [root@node-exporter ~]# systemctl enable --now node_exporter.service
  24. Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.
  25. [root@node-exporter ~]# systemctl status node_exporter.service
  26. ● node_exporter.service
  27.    Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
  28.    Active: active (running) since 四 2021-12-30 19:26:59 CST; 8s ago
  29. Main PID: 27878 (node_exporter)
  30.    CGroup: /system.slice/node_exporter.service
  31.            └─27878 /usr/local/node_exporter/node_exporter

  32. //查看端口
  33. [root@node-exporter ~]# ss -anltu
  34. Netid State      Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
  35. tcp   LISTEN     0      128                        *:22                                     *:*                  
  36. tcp   LISTEN     0      128                     [::]:22                                  [::]:*                  
  37. tcp   LISTEN     0      128                     [::]:9100                                [::]:*                  

  38. ## node-exporter部署成功就可以在Prometheus主机上添加节点进行监控
复制代码
添加节点到prometheus中

修改本地prometheus.yml文件
  1. //修改配置文件
  2. [root@prometheus ~]# tail -8 /opt/prometheus.yml
  3. scrape_configs:
  4.   # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  5.   - job_name: "prometheus"
  6.     static_configs:
  7.       - targets: ["localhost:9090"]
  8.   - job_name: "centos"                        //指定一个工作名称
  9.     static_configs:
  10.       - targets: ["192.168.237.131:9100"]                                //指定node-exporter节点的IP和端口号
  11. ## 如果有多个节点
  12.   - job_name: "centos"       
  13.     static_configs:
  14.       - targets:
  15.         - "192.168.237.131:9100"
  16.         - "192.168.237.132:9100"
  17.         - "192.168.237.133:9100"


  18. //重启容器,重新读取配置文件
  19. [root@prometheus ~]# docker restart prometheus
  20. prometheus
  21. [root@prometheus ~]# docker ps
  22. CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
  23. a0ba5535f0ea   prom/prometheus:latest            "/bin/prometheus --c…"   26 minutes ago   Up 3 seconds              0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus
复制代码
访问prometheus默认网页
成功添加节点

部署grafana画图工具
  1. //拉取grafan/grafan官方镜像
  2. [root@prometheus ~]# docker pull grafana/grafana
  3. Using default tag: latest
  4. latest: Pulling from grafana/grafana
  5. 97518928ae5f: Pull complete
  6. 5b58818b7f48: Pull complete
  7. d9a64d9fd162: Pull complete
  8. 4e368e1b924c: Pull complete
  9. 867f7fdd92d9: Pull complete
  10. 387c55415012: Pull complete
  11. 07f94c8f51cd: Pull complete
  12. ce8cf00ff6aa: Pull complete
  13. e44858b5f948: Pull complete
  14. 4000fdbdd2a3: Pull complete
  15. Digest: sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062
  16. Status: Downloaded newer image for grafana/grafana:latest
  17. docker.io/grafana/grafana:latest

  18. [root@prometheus ~]# docker images
  19. REPOSITORY                      TAG       IMAGE ID       CREATED        SIZE
  20. prom/prometheus                 latest    a3d385fc29f9   12 days ago    201MB
  21. grafana/grafana                 latest    9b957e098315   2 weeks ago    275MB

  22. //使用官方grafana镜像运行容器
  23. [root@prometheus ~]# docker run -d --name grafana -p 3000:3000 --restart always grafana/grafana
  24. 0b5986fc63442538a6fae845e5d1b8afc78caec4f4bdd81ca3623eb1329ad562

  25. [root@prometheus ~]# docker ps
  26. CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS                    PORTS                                       NAMES
  27. 0b5986fc6344   grafana/grafana                   "/run.sh"                4 seconds ago    Up 2 seconds              0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   grafana
  28. a0ba5535f0ea   prom/prometheus:latest            "/bin/prometheus --c…"   33 minutes ago   Up 6 minutes              0.0.0.0:9090->9090/tcp, :::9090->9090/tcp   prometheus

  29. //查看端口
  30. [root@prometheus ~]# ss -anltu
  31. Netid     State      Recv-Q      Send-Q           Local Address:Port           Peer Address:Port     Process            
  32. tcp       LISTEN     0           128                    0.0.0.0:22                  0.0.0.0:*                    
  33. tcp       LISTEN     0           128                    0.0.0.0:3000                0.0.0.0:*                    
  34. tcp       LISTEN     0           128                    0.0.0.0:9090                0.0.0.0:*                             
  35. tcp       LISTEN     0           128                       [::]:22                     [::]:*                    
  36. tcp       LISTEN     0           128                       [::]:3000                   [::]:*                    
  37. tcp       LISTEN     0           128                       [::]:9090                   [::]:*                    
复制代码
使用prometheus主机IP地址192.168.129.205 + 端口号3000在浏览器中访问
默认账号:admin 密码:admin

修改密码


首页


添加数据源


数据源选择prometheus




导入仪表盘

模板地址

模板ID为9276



效果图


到此这篇关于Prometheus容器化部署的文章就介绍到这了,更多相关Prometheus容器化部署内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
                                                        
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
免责声明
1. 本论坛所提供的信息均来自网络,本网站只提供平台服务,所有账号发表的言论与本网站无关。
2. 其他单位或个人在使用、转载或引用本文时,必须事先获得该帖子作者和本人的同意。
3. 本帖部分内容转载自其他媒体,但并不代表本人赞同其观点和对其真实性负责。
4. 如有侵权,请立即联系,本网站将及时删除相关内容。
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表