日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

普罗米修斯监控mysql数据库实战

發布時間:2024/1/1 数据库 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 普罗米修斯监控mysql数据库实战 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

前言

一 實驗環境

1.1 前期準備

1.2 確認IP地址

1.3 關閉SELinux和防火墻

二 配置prometheus監控

2.1 使用rz上傳prometheus壓縮包

2.2 解壓包并進入目錄

三 安裝MySQL數據庫

3.1配置網絡源

3.2 刪除mariadb相關文件

3.3 安裝MySQL

四 配置MySQL數據庫

4.1啟動數據庫并查找舊密碼

4.2 設置MySQL新密碼

五 配置mysqld_exporter

5.1上傳軟件包并解壓

5.2 進入該目錄并設置數據庫賬戶

5.3 創建配置文件將賬戶密碼寫入

5.4 啟動mysqld_exporter

六、啟動prometheus監控

6.1 配置prometheus文件

6.2 啟動監控服務

6.3 在官網打開prometheus

總結

前言

? ? ? ? 前前文講了如何在Linux服務器上安裝mysql數據庫,那么,今天就用prometheus來監控mysql數據庫服務。

一 實驗環境

1.1 前期準備

? ? ? ? 本實驗需要準備兩臺服務器

第一臺服務器配置prometheus監控;

第二臺服務器配置mysql和mysqld_exporter,給prometheus提供監控樣本數據;

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) #系統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) #系統centos 7.9

1.3 關閉SELinux和防火墻

????????兩臺服務器均是此操作

setenforce 0 iptables -F systemctl stop firewalld.service

二 配置prometheus監控

????????到這里開始操作是在第一臺服務器上開始

2.1 使用rz上傳prometheus壓縮包

? ? ? ? 若在VM虛擬機上,rz命令無法使用,要連接Xshell上遠程登錄后方可用rz命令,沒有rz命令可下載lrzsz軟件包。

下面繼續開始上傳程序壓縮包

等待片刻......

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參數解壓,也可以顯示執行過程-zxvf參數 [root@localhost ~]# mv prometheus-2.37.2.linux-amd64 prometheus

到這里prometheus已經配置好一大半了,接下來./prometheus就可以直接啟動了,然后在瀏覽器上輸入IP+端口即可訪問,可參考上上上個文章-?prometheus監控本地主機及監控遠程主機;

現在先不啟動,開始第二臺配置安裝MySQL數據庫。

三 安裝MySQL數據庫

????????由于centos7以上的版本安裝MySQL會與mariadb之間有沖突,想要成功安裝MySQL數據庫,必須先卸載與mariadb相關的服務和文件。

3.1配置網絡源

提前備份自帶的repo源,下載阿里網絡源替換掉當前軟件源。

[root@mysql_23 ~]# cd /etc/yum.repos.d/ [root@mysql_23 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

阿里云網絡源地址--阿里源下載點

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.rpm

3.2 刪除mariadb相關文件

搜索與mariadb相關的軟件包?

[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相關的文件

[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/mysql

3.3 安裝MySQL

安裝含有mysql5.7的源

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

?有這兩個repo文件表示安裝成功

?使用yum安裝mysql-57和相關依賴包

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.repo

2 把gpgkey改成mysql的gpgkey

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

重新安裝就可以了

[root@localhost ~]# yum install mysql-community-server -y

四 配置MySQL數據庫

4.1啟動數據庫并查找舊密碼

[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=jp9GY

4.2 設置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_exporter

5.2 進入該目錄并設置數據庫賬戶

[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 Bye

5.3 創建配置文件將賬戶密碼寫入

[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表示即使當前終端關閉也不會影響服務的運行。

[root@mysql_23 ~]# netstat -antup | grep mysqld tcp6 0 0 :::3306 :::* LISTEN 3052/mysqld tcp6 0 0 :::9104 :::* LISTEN 4961/./mysqld_expor

查看服務mysqld_expor端口為9104,到這里mysqld_exporter已經配置完成了。

六、啟動prometheus監控

回到第一臺服務器上修改配置文件

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 啟動監控服務

[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 在官網打開prometheus

使用ip+端口進行訪問:192.168.212.166:9090 ,這里的IP修改為配置prometheus的那一臺機器。

總結

以上就是prometheus+MySQL的所有內容了,寫了這么多內容真的不容易;如果這篇文章對你有幫助,覺得還行的,可以點贊支持一下!

總結

以上是生活随笔為你收集整理的普罗米修斯监控mysql数据库实战的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。