docker 安裝部署 Prometheus 與grafana的詳細(xì)過程
0. centos 7 安裝后的操作
# 禁用selinux 以防兼容性問題 setenforce 0 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 關(guān)閉防火墻服務(wù) systemctl disable firewalld &>/dev/null systemctl stop firewalld # 更新yum源、epel源 mkdir /etc/yum.repos.d/old/ &>/dev/null mv /etc/yum.repos.d/* /etc/yum.repos.d/old/ &> /dev/null curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo &>/dev/null curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo &> /dev/null # 安裝docker服務(wù) yum clean all &>/dev/null yum makecache &>/dev/null yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install docker-ce docker-ce-cli containerd.io
1. 準(zhǔn)備環(huán)境
確保你已經(jīng)安裝了 Docker 和 Docker Compose。如果沒有安裝,可以參考以下命令:
# 安裝 Docker sudo yum install -y docker sudo systemctl start docker sudo systemctl enable docker # 安裝 Docker Compose sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose --version # 驗(yàn)證安裝
2. 創(chuàng)建工作目錄
創(chuàng)建一個(gè)目錄來存放相關(guān)配置文件:
mkdir prometheus-grafana cd prometheus-grafana
3. 配置 Prometheus
3.1 創(chuàng)建 Prometheus 配置文件
新建 prometheus.yml:
nano prometheus.yml
內(nèi)容如下:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
static_configs:
- targets: ['node_exporter:9100']3.2 創(chuàng)建存儲(chǔ)配置
創(chuàng)建一個(gè)目錄用來保存 Prometheus 數(shù)據(jù):
mkdir prometheus_data
4. 創(chuàng)建 Docker Compose 配置
新建 docker-compose.yml:
nano docker-compose.yml
內(nèi)容如下:
version: '3.7'
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./prometheus_data:/prometheus
restart: unless-stopped
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
restart: unless-stopped
node_exporter:
image: prom/node-exporter:latest
container_name: node_exporter
ports:
- "9100:9100"
restart: unless-stopped
volumes:
grafana_data:5. 啟動(dòng)服務(wù)
運(yùn)行以下命令啟動(dòng)容器:
docker-compose up -d
檢查服務(wù)狀態(tài):
docker ps
6. 訪問 Prometheus 和 Grafana
- Prometheus:訪問
http://<your_server_ip>:9090。 - Grafana:訪問
http://<your_server_ip>:3000。- 默認(rèn)用戶名:
admin - 默認(rèn)密碼:
admin
- 默認(rèn)用戶名:
7. 配置 Grafana 數(shù)據(jù)源
- 登錄 Grafana 后,進(jìn)入 Configuration > Data Sources。
- 點(diǎn)擊 Add data source,選擇 Prometheus。
- 在 URL 欄輸入
http://prometheus:9090,點(diǎn)擊 Save & Test。
8. 添加監(jiān)控面板
在 Grafana 中:
- 點(diǎn)擊 + > Import。
- 輸入面板的 ID,例如:
- Node Exporter Full:1860
- 點(diǎn)擊 Load,選擇數(shù)據(jù)源后保存。
9. 驗(yàn)證監(jiān)控效果
- 在 Prometheus 中,可以通過
http://<your_server_ip>:9090查看監(jiān)控目標(biāo)狀態(tài)。 - 在 Grafana 中,可以通過導(dǎo)入的面板查看實(shí)時(shí)圖表。
注意事項(xiàng)
- 數(shù)據(jù)持久化:Prometheus 和 Grafana 數(shù)據(jù)通過
docker-compose.yml中的掛載路徑實(shí)現(xiàn)持久化。 - 安全性:生產(chǎn)環(huán)境建議修改 Grafana 默認(rèn)用戶名密碼。
- 擴(kuò)展性:可以通過修改
prometheus.yml添加其他監(jiān)控目標(biāo),例如數(shù)據(jù)庫、應(yīng)用程序等。
這套方案簡(jiǎn)單易用,非常適合快速部署監(jiān)控環(huán)境。
到此這篇關(guān)于docker 安裝部署 Prometheus 與grafana的文章就介紹到這了,更多相關(guān)docker 部署 Prometheus 與grafana內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
docker靈活的構(gòu)建PHP環(huán)境的實(shí)現(xiàn)
這篇文章主要介紹了docker靈活的構(gòu)建PHP環(huán)境的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Docker Buildx構(gòu)建多平臺(tái)鏡像的實(shí)現(xiàn)
本文主要介紹了Docker Buildx構(gòu)建多平臺(tái)鏡像的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07
Docker Compose一鍵部署LNMP環(huán)境詳細(xì)過程
LNMP通常包括Nginx作為Web服務(wù)器,MySQL作為數(shù)據(jù)庫,PHP處理動(dòng)態(tài)內(nèi)容,可能還需要phpMyAdmin進(jìn)行數(shù)據(jù)庫管理,今天給大家介紹下Docker Compose一鍵部署LNMP環(huán)境的詳細(xì)過程,感興趣的朋友一起看看吧2025-04-04
CentOS7如何修改Docker鏡像默認(rèn)存儲(chǔ)位置
這篇文章主要介紹了CentOS7如何修改Docker鏡像默認(rèn)存儲(chǔ)位置問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Docker+DockerCompose封裝web應(yīng)用的方法步驟
這篇文章會(huì)介紹如何將后端、前端和網(wǎng)關(guān)通通使用 Docker 容器進(jìn)行運(yùn)行,并最終使用 DockerCompose 進(jìn)行容器編排,感興趣的可以了解一下2021-08-08
淺談Docker 容器數(shù)據(jù)卷掛載小結(jié)
本篇文章主要介紹了淺談Docker 容器數(shù)據(jù)卷掛載小結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11

