Prometheus 插件mysql_exporter安裝過程
簡介
mysql_exporter是用來收集MysQL或者M(jìn)ariadb數(shù)據(jù)庫相關(guān)指標(biāo)的,mysql_exporter需要連接到數(shù)據(jù)庫并有相關(guān)權(quán)限。既可以用二進(jìn)制安裝部署,也可以通過容器形式部署,但為了數(shù)據(jù)收集的準(zhǔn)確性,推薦二進(jìn)制安裝。
一,下載安裝包并解壓
安裝包下載地址: https://github.com/prometheus/mysqld_exporter/releases
同樣物理機(jī)上下載,然后上傳到服務(wù)器,本次安裝使用的版本為:mysqld_exporter-0.14.0.linux-amd64
1,根據(jù)服務(wù)器情況選擇安裝目錄,上傳安裝包。
mkdir /mysqld_exporter cd /mysqld_exporter/ [root@jd-mysql mysqld_exporter]# ls mysqld_exporter-0.14.0.linux-amd64.tar.gz #解壓 [root@jd-mysql mysqld_exporter]# tar -xvzf mysqld_exporter-0.14.0.linux-amd64.tar.gz [root@jd-mysql mysqld_exporter]# cp mysqld_exporter-0.14.0.linux-amd64/* . [root@jd-mysql mysqld_exporter]# rm -rf mysqld_exporter-0.14.0.linux-amd64 [root@jd-mysql mysqld_exporter]# ls LICENSE mysqld_exporter mysqld_exporter-0.14.0.linux-amd64.tar.gz NOTICE
二,創(chuàng)建配置文件
創(chuàng)建配置文件.my.cnf
,填入如下內(nèi)容后保存:wq
[root@jd-mysql mysqld_exporter]# cat .my.cnf [client] user = exporter password = Jd123456 host = 192.168.1.150 port = 3306
mysql創(chuàng)建用戶并授權(quán),注意服務(wù)ip不要填錯
[root@jd-mysql mysqld_exporter]# mysql -uroot -pJiangda123# mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. root@(none) 11:06 mysql>create user 'exporter'@'%' identified by 'Jd123456'; Query OK, 0 rows affected (1.02 sec) root@(none) 11:07 mysql>GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%' WITH MAX_USER_CONNECTIONS 3; Query OK, 0 rows affected, 1 warning (0.00 sec) root@(none) 11:07 mysql>flush privileges; Query OK, 0 rows affected (0.00 sec) root@(none) 11:07 mysql>exit Bye
三,進(jìn)行系統(tǒng)service編寫
創(chuàng)建mysqld_exporter.service
配置文件
cd /usr/lib/systemd/system vim mysqld_exporter.service
mysqld_exporter.service 文件填入如下內(nèi)容后保存:wq
[Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/mysqld_exporter/mysqld_exporter --config.my-cnf=/mysqld_exporter/.my.cnf --web.listen-address=:9104 [Install] WantedBy=multi-user.target
查看配置文件
cat mysqld_exporter.service
刷新服務(wù)配置并啟動服務(wù)
systemctl daemon-reload systemctl start mysqld_exporter.service
查看服務(wù)運(yùn)行狀態(tài)
systemctl status mysqld_exporter.service
設(shè)置開機(jī)自啟動
systemctl enable mysqld_exporter.service
測試服務(wù)返回
curl localhost:9104/metrics
Docker部署
- 在Docker部署之前,首先要確保擁有Docker環(huán)境
- 拉取mysqld-exporter最新鏡像
docker pull prom/mysqld-exporter
創(chuàng)建mysql監(jiān)聽用戶并授權(quán),注意服務(wù)ip不要填錯
CREATE USER 'exporter'@'<安裝Prometheus的主機(jī)IP>' IDENTIFIED BY '<your password>'; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'<安裝Prometheus的主機(jī)IP>'; flush privileges;
啟動容器
注意:?? 若二進(jìn)制章節(jié)部署后,需要執(zhí)行systemctl stop mysqld_exporter.service
關(guān)閉服務(wù),否則會造成端口沖突,或者docker的端口映射改為-p 9194:9104
也可。注意環(huán)境變量DATA_SOURCE_NAME
的mysql帳號密碼與地址無誤
docker run -d --restart=always --name mysqld-exporter -p 9104:9104 -e DATA_SOURCE_NAME="exporter:<pass>(11x.xx.xx.7:13306)/" prom/mysqld-exporter
測試服務(wù)返回
curl localhost:9104/metrics
對接prometheus
打開prometheus.yml
添加以下內(nèi)容,并執(zhí)行:wq
,點(diǎn)擊回車保存
- job_name: "mysql" static_configs: - targets: ["192.168.1.150:9104"] labels: instance: mysqld-exporter
執(zhí)行prometheus配置刷新
curl -XPOST localhost:9090/-/reload
打開prometheus,搜索mysql,可以看到出現(xiàn)了很多的參數(shù)指標(biāo)
打開targets,可以看到節(jié)點(diǎn)狀態(tài)已經(jīng)UP
至此mysqld-exporter插件安裝完畢
用Grafana出圖
[root@nfs yum.repos.d]# mkdir /grafana [root@nfs yum.repos.d]# cd /grafana/ [root@nfs grafana]# ls grafana-enterprise-9.1.2-1.x86_64.rpm [root@nfs grafana]# yum install grafana-enterprise-9.1.2-1.x86_64.rpm -y
安裝好后
[root@nfs grafana]# service grafana-server start Starting grafana-server (via systemctl): [ 確定 ] [root@nfs grafana]# systemctl enable grafana-server Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service. [root@nfs grafana]# netstat -anplut|grep grafana tcp 0 0 192.168.1.130:56948 34.120.177.193:443 ESTABLISHED 8775/grafana-server tcp 0 0 192.168.1.130:48842 185.199.110.133:443 ESTABLISHED 8775/grafana-server tcp6 0 0 :::3000 :::* LISTEN 8775/grafana-server
訪問http://192.168.1.130:3000/
默認(rèn)的用戶名和密碼是
用戶名admin
密碼admin
配置數(shù)據(jù)源
成功效果:
到此這篇關(guān)于Prometheus插件安裝(mysql_exporter)的文章就介紹到這了,更多相關(guān)Prometheus mysql_exporter安裝內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
mysql如何創(chuàng)建數(shù)據(jù)庫并指定字符集
這篇文章主要介紹了mysql如何創(chuàng)建數(shù)據(jù)庫并指定字符集問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12MySQL 8.0 之索引跳躍掃描(Index Skip Scan)
這篇文章主要介紹了MySQL 8.0 之索引跳躍掃描(Index Skip Scan)的相關(guān)資料,幫助大家學(xué)習(xí)MySQL8.0的新特性,感興趣的朋友可以了解下2020-10-10mysql報錯:1406 Data too long for colu
這篇文章給大家介紹了多種解決mysql報錯:1406, Data too long for column的解決方法,如果有遇到相同問題的朋友可以參考閱讀本文,對解決問題有一定的幫助,需要的朋友可以參考下2023-09-09mysql數(shù)據(jù)庫中字段的注釋和類型長度獲取方式
這篇文章主要介紹了mysql數(shù)據(jù)庫中字段的注釋和類型長度獲取方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01解決MySQL登錄報錯1045-Access?denied?for?user?'root'@
這篇文章主要給大家介紹了關(guān)于解決MySQL登錄報錯1045-Access?denied?for?user?‘root‘@‘‘(using?password:YES)的相關(guān)資料,文中一步步將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07