Prometheus 容器化部署,配合Grafan画图工具监控节点
Prometheus 容器化部署,配合Grafan畫圖工具監(jiān)控節(jié)點(diǎn)
一、部署環(huán)境
| prometheus | 192.168.85.131 | prometheus、grafana |
| node-exporter | 192.168.85.132 | node_exporter |
二、部署 Prometheus
準(zhǔn)備工作
修改主機(jī)名
[root@localhost ~]# hostnamectl set-hostname prometheus [root@localhost ~]# bash關(guān)閉防火墻
[root@prometheus ~]# systemctl disable --now firewalld關(guān)閉selinux
[root@prometheus ~]# vim /etc/selinux/config [root@prometheus ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # disabled - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of disabled. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted[root@prometheus ~]# reboot [root@prometheus ~]# getenforce Disabled首先配置yum倉(cāng)庫(kù)
[root@prometheus ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo配置docker的yum源
[root@prometheus ~]# cd /etc/yum.repos.d/ [root@prometheus ~]# curl -o docker-ce.repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo [root@prometheus ~]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo安裝docker-ce以及docker組件
[root@prometheus ~]# yum -y install docker-ce啟動(dòng)docker
[root@prometheus ~]# systemctl start docker [root@prometheus ~]# systemctl status docker ● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2021-12-29 18:36:30 CST; 8min agoDocs: https://docs.docker.comMain PID: 1156 (dockerd)Tasks: 8Memory: 135.7MCGroup: /system.slice/docker.service└─1156 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock設(shè)置阿里云鏡像加速
[root@prometheus ~]# vim /etc/docker/daemon.json [root@prometheus ~]# cat /etc/docker/daemon.json {"registry-mirrors": ["https://in3617d8.mirror.aliyuncs.com"] } [root@prometheus ~]# systemctl restart docker [root@prometheus ~]# systemctl daemon-reload [root@prometheus ~]# docker info Client:Context: defaultDebug Mode: falsePlugins:app: Docker App (Docker Inc., v0.9.1-beta3)buildx: Docker Buildx (Docker Inc., v0.7.1-docker)scan: Docker Scan (Docker Inc., v0.12.0)Server:Containers: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 20.10.12Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5drunc version: v1.0.2-0-g52b36a2init version: de40ad0Security Options:seccompProfile: defaultKernel Version: 4.18.0-257.el8.x86_64Operating System: CentOS Stream 8OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 3.622GiBName: prometheusID: Z3JR:D5TL:NVZ7:DJWE:7FL3:EC74:6DKV:6HOB:IPXV:FCQ3:MF4B:R3BGDocker Root Dir: /var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Registry Mirrors:https://in3617d8.mirror.aliyuncs.com/Live Restore Enabled: false運(yùn)行promethues容器
拉取官方prometheus鏡像
[root@prometheus ~]# docker pull prom/prometheus Using default tag: latest latest: Pulling from prom/prometheus 3cb635b06aa2: Pull complete 34f699df6fe0: Pull complete 33d6c9635e0f: Pull complete f2af7323bed8: Pull complete c16675a6a294: Pull complete 827843f6afe6: Pull complete 3d272942eeaf: Pull complete 7e785cfa34da: Pull complete 05e324559e3b: Pull complete 170620261a59: Pull complete ec35f5996032: Pull complete 5509173eb708: Pull complete Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb Status: Downloaded newer image for prom/prometheus:latest docker.io/prom/prometheus:latest創(chuàng)建存放prometheus配置文件的目錄,并提供默認(rèn)配置文件
[root@prometheus ~]# mkdir -p /prometheus/config/ [root@prometheus ~]# cd /prometheus/config/ [root@prometheus config]# vim prometheus.yml [root@prometheus config]# cat 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).# Alertmanager configuration alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# 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:9090"]使用官方promethrus鏡像創(chuàng)建容器
[root@prometheus ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE prom/prometheus latest a3d385fc29f9 11 days ago 201MB [root@prometheus ~]# docker run --name prometheus -d --restart always -p 9090:9090 -v /prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:latest 7c224924088bc66c18f11549225e92677646ee5bbf5010340d9f57ddbd407cfc [root@prometheus ~]# [root@prometheus ~]# [root@prometheus ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7c224924088b prom/prometheus:latest "/bin/prometheus --c…" 5 seconds ago Up 4 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus查看端口號(hào)
[root@prometheus ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:9090 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:9090 [::]:* LISTEN 0 128 [::]:22 [::]:*使用本機(jī)IP地址192.168.85.131 + 端口號(hào)9090/targets在瀏覽器中訪問
三、部署 node_exporter
準(zhǔn)備工作
修改主機(jī)名
[root@localhost ~]# hostnamectl set-hostname node-exporter [root@localhost ~]# bash關(guān)閉防火墻
[root@node-exporter ~]# systemctl disable --now firewalld關(guān)閉selinux
[root@node-exporter ~]# vim /etc/selinux/config [root@node-exporter ~]# cat /etc/selinux/config# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # disabled - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of disabled. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted[root@node-exporter ~]# reboot [root@node-exporter ~]# getenforce Disabled部署node_exporter
下載node_exporter
[root@node-exporter ~]# cd /usr/src [root@node-exporter src]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz --2021-12-29 19:23:02-- https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz解壓并重命名
[root@node-exporter src]# ls debug kernels node_exporter-1.3.0.linux-amd64.tar.gz [root@node-exporter src]# tar -xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/ [root@node-exporter src]# cd /usr/local/ [root@node-exporter local]# ls bin etc games include lib lib64 libexec node_exporter-1.3.0.linux-amd64 sbin share src [root@node-exporter local]# mv node_exporter-1.3.0.linux-amd64/ node_exporter [root@node-exporter local]# ls bin etc games include lib lib64 libexec node_exporter sbin share src編寫service文件
[root@node-exporter ~]# cat > /usr/lib/systemd/system/node_exporter.service <<EOF [unit] Description=The node_exporter Server After=network.target[Service] ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure RestartSec=15s SyslogIdentifier=node_exporter[Install] WantedBy=multi-user.targetEOF啟動(dòng)服務(wù)
[root@node-exporter ~]# systemctl daemon-reload [root@node-exporter ~]# systemctl enable --now node_exporter Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /usr/lib/systemd/system/node_exporter.service. [root@node-exporter ~]# systemctl status node_exporter ● node_exporter.serviceLoaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2021-12-29 19:27:22 CST; 1min 2s agoMain PID: 89713 (node_exporter)Tasks: 4 (limit: 23485)Memory: 8.8MCGroup: /system.slice/node_exporter.service└─89713 /usr/local/node_exporter/node_exporter查看都口號(hào)
[root@node-exporter ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 *:9100 *:* LISTEN 0 128 [::]:22 [::]:*四、添加節(jié)點(diǎn)到prometheus中
修改/prometheus/config目錄下的prometheus配置文件prometheus.yml
[root@prometheus ~]# cd /prometheus/config/ [root@prometheus config]# vim prometheus.yml [root@prometheus config]# cat 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).# Alertmanager configuration alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# 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:9090"]- job_name: "node1" #添加節(jié)點(diǎn)工作名稱 static_configs:- targets: ["192.168.85.132:9100"] #添加node)exporter節(jié)點(diǎn)IP地址和端口號(hào)重啟prometheus容器
[root@prometheus ~]# docker restart prometheus prometheus [root@prometheus ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7c224924088b prom/prometheus:latest "/bin/prometheus --c…" 55 minutes ago Up 7 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus使用prometheus主機(jī)IP地址192.168.85.131 + 端口號(hào)9090/targets在瀏覽器中訪問
五、部署grafana畫圖工具
拉取grafan/grafan官方鏡像
[root@prometheus ~]# docker pull grafana/grafana Using default tag: latest latest: Pulling from grafana/grafana 97518928ae5f: Already exists 5b58818b7f48: Already exists d9a64d9fd162: Already exists 4e368e1b924c: Already exists 867f7fdd92d9: Already exists 387c55415012: Already exists 07f94c8f51cd: Pull complete ce8cf00ff6aa: Pull complete e44858b5f948: Pull complete 4000fdbdd2a3: Pull complete Digest: sha256:18d94ae734accd66bccf22daed7bdb20c6b99aa0f2c687eea3ce4275fe275062 Status: Downloaded newer image for grafana/grafana:latest docker.io/grafana/grafana:latest [root@prometheus ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE prom/prometheus latest a3d385fc29f9 11 days ago 201MB grafana/grafana latest 9b957e098315 2 weeks ago 275MB使用官方grafana鏡像運(yùn)行容器
[root@prometheus ~]# docker run -d --name grafan -p 3000:3000 grafana/grafana 39f8ffa8c45b8b57a61e4526118384c15b56539bd878154a0a129edf60393849 [root@prometheus ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 39f8ffa8c45b grafana/grafana "/run.sh" 5 seconds ago Up 4 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafan 7c224924088b prom/prometheus:latest "/bin/prometheus --c…" About an hour ago Up 20 minutes 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus [root@prometheus ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:3000 0.0.0.0:* LISTEN 0 128 0.0.0.0:9090 0.0.0.0:* LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:3000 [::]:* LISTEN 0 128 [::]:9090 [::]:* LISTEN 0 128 [::]:22 [::]:*使用prometheus主機(jī)IP地址192.168.85.131 + 端口號(hào)3000在瀏覽器中訪問
登錄用戶和密碼都是 admin,輸入后提示修改密碼
進(jìn)入首頁(yè)
配置數(shù)據(jù)源
導(dǎo)入儀表盤模板
儀表板模板下載地址
總結(jié)
以上是生活随笔為你收集整理的Prometheus 容器化部署,配合Grafan画图工具监控节点的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot+vue+eleme
- 下一篇: python3 输出中文、日文等等乱码问