【参赛作品42】openGauss/MogDB数据库完美适配Grafana及Prometheus
作者:彭沖
Grafana是一個(gè)跨平臺(tái)、開源的度量分析和可視化工具,可以通過(guò)對(duì)接各種數(shù)據(jù)源并作可視化展示。
Prometheus是著名開源監(jiān)控項(xiàng)目,其監(jiān)控任務(wù)由具體的exporter實(shí)現(xiàn),exporter到目標(biāo)端抓取監(jiān)控?cái)?shù)據(jù),然后保存在TSDB時(shí)序數(shù)據(jù)庫(kù)中。Prometheus也支持PromQL查詢語(yǔ)言進(jìn)行自定義的查詢組合。
openGauss/MogDB數(shù)據(jù)庫(kù)可以通過(guò)opengauss_exporter完美適配Grafana及Prometheus。
下面是效果圖:
下面在麒麟arm測(cè)試環(huán)境下演示部署過(guò)程,x86環(huán)境需要替換相關(guān)下載安裝包。
1.Prometheus部署
1.1. 安裝包下載
軟件下載地址:https://prometheus.io/download/
下載文件prometheus-2.31.1.linux-arm64.tar.gz
1.2. 創(chuàng)建prometheus用戶
# useradd prometheus # password prometheus1.3. 創(chuàng)建prometheus相應(yīng)目錄并解壓安裝包
# mkdir /appdata/prometheus # mkdir /appdata/prometheus/etc # mkdir /appdata/prometheus/log # mkdir /appdata/prometheus/datatar -zxvf prometheus-2.31.1.linux-arm64.tar.gz -C /appdata/prometheus
chown -R prometheus: /appdata/prometheus
chmod -R 755 /appdata/prometheus
1.4. 使用prometheus用戶檢查安裝版本
$ /appdata/prometheus/prometheus-2.31.1.linux-arm64/prometheus --version1.5. 使用prometheus用戶編輯配置文件
$ vi /appdata/prometheus/etc/prometheus.yml內(nèi)容如下
# 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: # 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:
- job_name: ‘prometheus’
static_configs:- targets: [‘x.x.x.x:50090’]
- targets: [‘x.x.x.x:50090’]
1.6. 使用root用戶配置prometheus開機(jī)啟動(dòng)
# vi /usr/lib/systemd/system/prometheus.service內(nèi)容如下
[Unit] Description= Prometheus After=network.target[Service]
Type=simple
User=prometheus
ExecStart=/appdata/prometheus/prometheus-2.31.1.linux-arm64/prometheus --web.listen-address="0.0.0.0:50090" --config.file=/appdata/prometheus/etc/prometheus.yml --storage.tsdb.path=/appdata/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
# systemctl daemon-reload # systemctl enable prometheus # systemctl start prometheus1.7. 使用web瀏覽器測(cè)試prometheus服務(wù)
打開 http://x.x.x.x:50090/ 如下如所示,說(shuō)明prometheus服務(wù)正常。
2. node_exporter部署
2.1. 安裝包下載
軟件下載地址:https://github.com/prometheus/node_exporter/releases
下載文件node_exporter-1.2.2.linux-arm64.tar.gz
2.2. 使用root用戶解壓安裝包
root用戶解壓安裝包到prometheus用戶,測(cè)試環(huán)境部署在prometheus用戶下。
# tar -zxvf node_exporter-1.2.2.linux-arm64.tar.gz -C /appdata/prometheus/ # chown -R prometheus: /appdata/prometheus/node_exporter-1.2.2.linux-arm642.3. 使用prometheus用戶檢查安裝版本
$ /appdata/prometheus/node_exporter-1.2.2.linux-arm64/node_exporter --version2.4. 使用root用戶配置node_exporter開機(jī)啟動(dòng)
# vi /usr/lib/systemd/system/node_exporter.service內(nèi)容如下:
[Unit] Description= node exporter After=network.target[Service]
Type=simple
User=prometheus
ExecStart=/appdata/prometheus/node_exporter-1.2.2.linux-arm64/node_exporter --web.listen-address=":9100" --no-collector.softnet
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
2.5. 查看node_exporter服務(wù)
# systemctl status node_exporter2.6. prometheus配置exporter
prometheus配置文件prometheus.yml增加下面的內(nèi)容
- job_name: 'node_exporter'static_configs:- targets: ['110.128.131.16:9100']2.7. 使用root用戶重啟prometheus服務(wù)
# systemctl restart prometheus3. opengauss_exporter部署
3.1. 安裝包下載
下載地址:https://github.com/enmotech/opengauss_exporter
下載文件node_exporter-1.2.2.linux-arm64.tar.gz
3.2. 使用root用戶解壓安裝包
root用戶解壓安裝包到prometheus用戶,測(cè)試環(huán)境部署在prometheus用戶下。
# unzip opengauss_exporter_0.0.9_linux_arm64.zip -d /appdata/prometheus/opengauss_exporter # chown -R prometheus: /appdata/prometheus/opengauss_exporter3.3. 使用prometheus用戶檢查安裝版本
$ /appdata/prometheus/opengauss_exporter/opengauss_exporter --version3.4. 上傳yaml文件
文件存放路徑:/appdata/prometheus/opengauss_exporter
修改權(quán)限
# chown prometheus: queries.yaml3.5. MogDB數(shù)據(jù)庫(kù)端配置
3.5.1. 創(chuàng)建監(jiān)控用戶
密碼復(fù)雜度要符合數(shù)據(jù)庫(kù)的要求,默認(rèn)要求大小寫+特殊字符,不少于8位
$ gsql -Uomm postgres -rCREATE USER db_exporter WITH PASSWORD ‘XXXXXXXX’ MONADMIN;
grant usage on schema dbe_perf to db_exporter;
grant select on pg_stat_replication to db_exporter;
3.5.2. 配置pg_hba.conf
以md5的加密方式添加mogdbmonitor監(jiān)控機(jī)白名單
$ gs_guc set -I all -N all -h "host postgres db_exporter 110.128.131.16/32 md5"3.6. 使用root用戶配置服務(wù)開機(jī)啟動(dòng)
# vi /usr/lib/systemd/system/mogdb_exporter.service內(nèi)容如下:
[Unit] Description=Prometheus MogDB Exporter Server[Service]
User=prometheus
Environment="DATA_SOURCE_NAME=postgresql://db_exporter:password@ip:port/postgres?sslmode=disable"
ExecStart=/appdata/prometheus/opengauss_exporter/opengauss_exporter --web.listen-address=":51007" --config="/appdata/prometheus/opengauss_exporter/queries.yaml"
[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
# systemctl daemon-reload # systemctl enable mogdb_exporter # systemctl start mogdb_exporter3.7. 查看exporter服務(wù)
# systemctl status mogdb_exporter3.8. prometheus配置exporter
prometheus配置文件prometheus.yml增加下面的內(nèi)容
- job_name: ' mogdb_exporter 'static_configs:- targets: ['110.128.131.16: 51007']3.9. 使用root用戶重啟prometheus服務(wù)
# systemctl restart prometheus4. Grafana部署
4.1. 安裝包下載
下載地址:https://grafana.com/grafana/download
下載文件grafana-enterprise-8.2.4.linux-arm64.tar.gz
4.2. 使用root用戶解壓安裝包
root用戶解壓安裝包到prometheus用戶,測(cè)試環(huán)境部署在prometheus用戶下。
# tar -zxvf grafana-enterprise-8.2.4.linux-arm64.tar.gz -C /appdata/prometheus/ # chown -R prometheus: /appdata/prometheus/grafana-8.2.44.3. 使用prometheus用戶檢查安裝版本
$ /appdata/prometheus/grafana-8.2.4/bin/grafana-server -v4.4. 使用prometheus用戶配置grafana
$ vi /appdata/prometheus/grafana-8.2.4/conf/defaults.ini例如修改http_port = 51009
修改內(nèi)置數(shù)據(jù)庫(kù)3306端口等
4.5. 使用root用戶配置服務(wù)開機(jī)啟動(dòng)
# vi /usr/lib/systemd/system/grafana.service內(nèi)容如下
[Unit] Description=Grafana Server[Service]
User=prometheusExecStart=/appdata/prometheus/grafana-8.2.4/bin/grafana-server -homepath /appdata/prometheus/grafana-8.2.4/ -config /appdata/prometheus/grafana-8.2.4/conf/defaults.ini
[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
# systemctl daemon-reload # systemctl enable grafana.service # systemctl start grafana.service4.6. 查看grafana服務(wù)狀態(tài)
# systemctl status grafana.service4.7. 使用web瀏覽器測(cè)試grafana
打開 http://x.x.x.x:51009/ ,默認(rèn)賬號(hào):admin 默認(rèn)密碼:admin
然后配置prometheus,加載dashboard即可。
總結(jié)
以上是生活随笔為你收集整理的【参赛作品42】openGauss/MogDB数据库完美适配Grafana及Prometheus的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 14晶体三极管的三个工作区域
- 下一篇: SQL学习笔记(06)_SELECT I