普罗米修斯监控mysql数据库实战
目錄
前言
一 實驗環(huán)境
1.1 前期準備
1.2 確認IP地址
1.3 關(guān)閉SELinux和防火墻
二 配置prometheus監(jiān)控
2.1 使用rz上傳prometheus壓縮包
2.2 解壓包并進入目錄
三 安裝MySQL數(shù)據(jù)庫
3.1配置網(wǎng)絡(luò)源
3.2 刪除mariadb相關(guān)文件
3.3 安裝MySQL
四 配置MySQL數(shù)據(jù)庫
4.1啟動數(shù)據(jù)庫并查找舊密碼
4.2 設(shè)置MySQL新密碼
五 配置mysqld_exporter
5.1上傳軟件包并解壓
5.2 進入該目錄并設(shè)置數(shù)據(jù)庫賬戶
5.3 創(chuàng)建配置文件將賬戶密碼寫入
5.4 啟動mysqld_exporter
六、啟動prometheus監(jiān)控
6.1 配置prometheus文件
6.2 啟動監(jiān)控服務(wù)
6.3 在官網(wǎng)打開prometheus
總結(jié)
前言
? ? ? ? 前前文講了如何在Linux服務(wù)器上安裝mysql數(shù)據(jù)庫,那么,今天就用prometheus來監(jiān)控mysql數(shù)據(jù)庫服務(wù)。
一 實驗環(huán)境
1.1 前期準備
? ? ? ? 本實驗需要準備兩臺服務(wù)器
第一臺服務(wù)器配置prometheus監(jiān)控;
第二臺服務(wù)器配置mysql和mysqld_exporter,給prometheus提供監(jiān)控樣本數(shù)據(jù);
1.2 確認IP地址
[root@localhost ~]# hostname -I #第一臺IP 192.168.212.166 192.168.122.1 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) #系統(tǒng)centos 7.9[root@mysql_export ~]# hostname -I 192.168.212.23 192.168.122.1 172.17.0.1 #第二臺IP [root@mysql_export ~]# hostnamectl set-hostname mysql_23 [root@mysql_export ~]# bash [root@mysql_23 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) #系統(tǒng)centos 7.91.3 關(guān)閉SELinux和防火墻
????????兩臺服務(wù)器均是此操作
setenforce 0 iptables -F systemctl stop firewalld.service二 配置prometheus監(jiān)控
????????到這里開始操作是在第一臺服務(wù)器上開始
2.1 使用rz上傳prometheus壓縮包
? ? ? ? 若在VM虛擬機上,rz命令無法使用,要連接Xshell上遠程登錄后方可用rz命令,沒有rz命令可下載lrzsz軟件包。
下面繼續(xù)開始上傳程序壓縮包
等待片刻......
2.2 解壓包并進入目錄
[root@localhost ~]# ll prometheus-2.37.2.linux-amd64.tar.gz -rw-r--r--. 1 root root 83879445 11月 9 19:54 prometheus-2.37.2.linux-amd64.tar.gz [root@localhost ~]# tar xf prometheus-2.37.2.linux-amd64.tar.gz #使用xf參數(shù)解壓,也可以顯示執(zhí)行過程-zxvf參數(shù) [root@localhost ~]# mv prometheus-2.37.2.linux-amd64 prometheus到這里prometheus已經(jīng)配置好一大半了,接下來./prometheus就可以直接啟動了,然后在瀏覽器上輸入IP+端口即可訪問,可參考上上上個文章-?prometheus監(jiān)控本地主機及監(jiān)控遠程主機;
現(xiàn)在先不啟動,開始第二臺配置安裝MySQL數(shù)據(jù)庫。
三 安裝MySQL數(shù)據(jù)庫
????????由于centos7以上的版本安裝MySQL會與mariadb之間有沖突,想要成功安裝MySQL數(shù)據(jù)庫,必須先卸載與mariadb相關(guān)的服務(wù)和文件。
3.1配置網(wǎng)絡(luò)源
提前備份自帶的repo源,下載阿里網(wǎng)絡(luò)源替換掉當(dāng)前軟件源。
[root@mysql_23 ~]# cd /etc/yum.repos.d/ [root@mysql_23 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak阿里云網(wǎng)絡(luò)源地址--阿里源下載點
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum clean all #清理緩存 yum makecache #重新生成緩存下載MySQL5.7?rpm包
wget -c https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm[root@mysql_23 ~]# ll mysql57-community-release-el7-9.noarch.rpm -rw-r--r--. 1 root root 9224 9月 12 2016 mysql57-community-release-el7-9.noarch.rpm3.2 刪除mariadb相關(guān)文件
搜索與mariadb相關(guān)的軟件包?
[root@mysql_23 ~]# rpm -qa | grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 [root@mysql_23 ~]# rpm -qa | grep mysql [root@mysql_23 ~]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64 錯誤:依賴檢測失敗:libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要刪除軟件若提示依賴檢測失敗,那就需要加上--nodeps,表示強制刪除。
[root@mysql_23 ~]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps [root@mysql_23 ~]# echo $? 0?搜索與mariadb相關(guān)的文件
[root@mysql_23 ~]# find / -name mariadb [root@mysql_23 ~]# find / -name mysql /etc/selinux/targeted/active/modules/100/mysql /usr/lib64/mysql [root@mysql_23 ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql [root@mysql_23 ~]# rm -rf /usr/lib64/mysql3.3 安裝MySQL
安裝含有mysql5.7的源
rpm -ivh mysql57-community-release-el7-9.noarch.rpm?有這兩個repo文件表示安裝成功
?使用yum安裝mysql-57和相關(guān)依賴包
yum install mysql-community-server -y?若安裝完后顯示公鑰尚未安裝,有兩個解決思路
1 將要下載的mysql包的gpgcheck的1改成0
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo? [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=0 ? ?#這個 1改成0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [root@localhost ~]# cat /etc/yum.repos.d/mysql-community.repo2 把gpgkey改成mysql的gpgkey
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022重新安裝就可以了
[root@localhost ~]# yum install mysql-community-server -y四 配置MySQL數(shù)據(jù)庫
4.1啟動數(shù)據(jù)庫并查找舊密碼
[root@mysql_23 ~]# systemctl start mysqld [root@mysql_23 ~]# grep "password" /var/log/mysqld.log 2023-02-19T08:59:32.117275Z 1 [Note] A temporary password is generated for root@localhost: )yjbkb=jp9GY4.2 設(shè)置MySQL新密碼
[root@mysql_23 ~]# mysql -uroot -p Enter password: #輸入舊密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.41Copyright (c) 2000, 2023, 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.mysql> alter user 'root'@'localhost' identified by 'GUANzhu123//'; #修改新密碼 Query OK, 0 rows affected (0.00 sec)五 配置mysqld_exporter
5.1上傳軟件包并解壓
[root@mysql_23 ~]# rz[root@mysql_23 ~]# ll mysqld_exporter-0.14.0.linux-amd64.tar.gz -rw-r--r--. 1 root root 7450991 11月 9 19:53 mysqld_exporter-0.14.0.linux-amd64.tar.gz [root@mysql_23 ~]# tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz [root@mysql_23 ~]# mv mysqld_exporter-0.14.0.linux-amd64 mysqld_exporter5.2 進入該目錄并設(shè)置數(shù)據(jù)庫賬戶
[root@mysql_23 ~]# cd mysqld_exporter/ [root@mysql_23 mysqld_exporter]# ll 總用量 14824 -rw-r--r--. 1 3434 3434 11357 3月 5 2022 LICENSE -rwxr-xr-x. 1 3434 3434 15163162 3月 5 2022 mysqld_exporter -rw-r--r--. 1 3434 3434 65 3月 5 2022 NOTICE [root@mysql_23 mysqld_exporter]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.41 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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.mysql> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by 'GUANzhu123//'; Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql> exit Bye5.3 創(chuàng)建配置文件將賬戶密碼寫入
[root@mysql_23 mysqld_exporter]# vim .my.cnf [root@mysql_23 mysqld_exporter]# cat .my.cnf [client] user=mysql_monitor password=GUANzhu123//5.4 啟動mysqld_exporter
[root@mysql_23 mysqld_exporter]# nohup ./mysqld_exporter --config.my-cnf=/root/mysqld_exporter/.my.cnf & [1] 4961?nohup表示即使當(dāng)前終端關(guān)閉也不會影響服務(wù)的運行。
[root@mysql_23 ~]# netstat -antup | grep mysqld tcp6 0 0 :::3306 :::* LISTEN 3052/mysqld tcp6 0 0 :::9104 :::* LISTEN 4961/./mysqld_expor查看服務(wù)mysqld_expor端口為9104,到這里mysqld_exporter已經(jīng)配置完成了。
六、啟動prometheus監(jiān)控
回到第一臺服務(wù)器上修改配置文件
6.1 配置prometheus文件
[root@localhost prometheus]# vim prometheus.yml [root@localhost prometheus]# tail prometheus.yml - job_name: "prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:- targets: ["localhost:9090"]- job_name: "mysql"static_configs:- targets: ["192.168.212.23:9104"]6.2 啟動監(jiān)控服務(wù)
[root@localhost prometheus]# ./prometheus & [1] 3351 ...... ts=2023-02-19T09:35:07.323Z caller=main.go:1177 level=info msg="Loading configuration file" filename=prometheus.yml ts=2023-02-19T09:35:07.324Z caller=main.go:1214 level=info msg="Completed loading of configuration file" filename=prometheus.yml totalDuration=1.22585ms db_storage=670ns remote_storage=3.01μs web_handler=380ns query_engine=800ns scrape=864.824μs scrape_sd=47.44μs notify=30.411μs notify_sd=8.26μs rules=2.67μs tracing=39.131μs ts=2023-02-19T09:35:07.324Z caller=main.go:957 level=info msg="Server is ready to receive web requests." ts=2023-02-19T09:35:07.324Z caller=manager.go:941 level=info component="rule manager" msg="Starting rule manager..."6.3 在官網(wǎng)打開prometheus
使用ip+端口進行訪問:192.168.212.166:9090 ,這里的IP修改為配置prometheus的那一臺機器。
總結(jié)
以上就是prometheus+MySQL的所有內(nèi)容了,寫了這么多內(nèi)容真的不容易;如果這篇文章對你有幫助,覺得還行的,可以點贊支持一下!
總結(jié)
以上是生活随笔為你收集整理的普罗米修斯监控mysql数据库实战的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Swagger3.0与Swagger2对
- 下一篇: 流体的流量特性曲线