首頁>技術>

一、被監控端Mysql主機安裝Zabbix-agent

永久關閉防火牆

[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# systemctl disable firewalld     //永久關閉防火牆

注意: 如果下載的zabbix-agent 5.0安裝包使用rpm安裝時提示“錯誤:依賴檢測失敗:libpcre.so.0()(64bit)”,則可以使用zabbix 5.0 Yum源來安裝zabbix-agent 5.0軟體。 ----> 傳送門 安裝zabbix-agent5.0 報錯解決

1.安裝Zabbix Yum源倉庫

[root@localhost ~]# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm[root@localhost ~]# yum clean all

使用Zabbix 5.0 Yum原始檔安裝zabbix-agent 5.0軟體,並且將gpgcheck=1修改為gpgcheck=0,防止出現“獲取GPG金鑰失敗”報錯。

2.修改Zabbix 5.0 Yum源配置檔案

[root@localhost ~]# sed -i "s/gpgcheck=1/gpgcheck=0/g" /etc/yum.repos.d/zabbix.repo[root@localhost ~]# cat /etc/yum.repos.d/zabbix.repo[zabbix]name=Zabbix Official Repository - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/enabled=1gpgcheck=0          //修改gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591[zabbix-frontend]name=Zabbix Official Repository frontend - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontendenabled=1gpgcheck=0        //修改gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591[zabbix-debuginfo]name=Zabbix Official Repository debuginfo - $basearchbaseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591gpgcheck=0        //修改gpgcheck=0[zabbix-non-supported]name=Zabbix Official Repository non-supported - $basearchbaseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIXgpgcheck=0        //修改gpgcheck=0[root@localhost ~]# yum -y install zabbix-agent     //安裝zabbix-agent 5.0軟體...已安裝:  zabbix-agent.x86_64 0:5.0.0-1.el7完畢!

3.修改zabbix-agent配置檔案

[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf119 Server=127.0.0.1,192.168.2.128   //Zabbix-server地址,多個用","隔開160 ServerActive=192.168.2.128     //主動檢查本主機資料傳送給Zabbix-server171 #Hostname=Zabbix server172 Hostname=192.168.2.129     //客戶端IP地址[root@localhost ~]# systemctl start zabbix-agent[root@localhost ~]# systemctl enable zabbix-agent[root@localhost ~]# ss -antulp | grep :10050tcp    LISTEN     0      128       *:10050                 *:*                   users:(("zabbix_agentd",pid=3389,fd=4),("zabbix_agentd",pid=3388,fd=4),("zabbix_agentd",pid=3387,fd=4),("zabbix_agentd",pid=3386,fd=4),("zabbix_agentd",pid=3385,fd=4),("zabbix_agentd",pid=3384,fd=4))tcp    LISTEN     0      128      :::10050                :::*                   users:(("zabbix_agentd",pid=3389,fd=5),("zabbix_agentd",pid=3388,fd=5),("zabbix_agentd",pid=3387,fd=5),("zabbix_agentd",pid=3386,fd=5),("zabbix_agentd",pid=3385,fd=5),("zabbix_agentd",pid=3384,fd=5))
二、Zabbix-agent端配置

1.下載Mysql 5.7 Yum源

[root@localhost ~]# wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm[root@localhost ~]# ls mysql57-community-release-el7-11.noarch.rpm mysql57-community-release-el7-11.noarch.rpm

2.安裝Mysql 5.7 Yum源

[root@localhost ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm[root@localhost ~]# yum -y install mysql-server    //安裝Mysql

3.啟動Mysqld服務

[root@localhost ~]# systemctl start mysqld[root@localhost ~]# systemctl enable mysqld[root@localhost ~]# ss -antulp | grep :3306tcp    LISTEN     0      80     [::]:3306               [::]:*                   users:(("mysqld",pid=54086,fd=21))

4.檢視初始密碼

[root@localhost ~]# grep 'root@localhost:' /var/log/mysqld.log2020-03-20T00:57:34.072739Z 1 [Note] A temporary password is generated for root@localhost: hsQ(7(so_cgX

5.使用初始密碼登陸

[root@localhost ~]# mysql -hlocalhost -uroot -p'hsQ(7(so_cgX'mysql: [Warning] Using a password on the command line interface can be insecure....Server version: 5.7.29...mysql>

6.修改登陸密碼

mysql> alter user root@"localhost" identified by "123qqq...A";

7.使用新密碼登陸

[root@localhost ~]# mysql -uroot -p123qqq...A

8.授權Zabbix使用者,用於傳送資料

[root@localhost ~]# mysql -uroot -p123qqq...A...mysql> grant all on *.* to zabbix@"localhost" identified by "123qqq...A";Query OK, 0 rows affected, 1 warning (0.03 sec)mysql> flush privileges;Query OK, 0 rows affected (0.11 sec)

9.測試使用授權的zabbix使用者登入資料庫

[root@localhost ~]# mysql -uzabbix -p123qqq...A...mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || db1                || mysql              || performance_schema || sys                || test               |+--------------------+6 rows in set (0.00 sec)mysql> select user();+------------------+| user()           |+------------------+| zabbix@localhost |+------------------+1 row in set (0.00 sec)

10.檢視mysql的sock檔案路徑

[root@localhost ~]# find / -name *.sock.../var/lib/mysql/mysql.sock

11.查詢並複製Zabbix監控Mysql模板檔案

[root@test2 ~]# find / -name user*_mysql.conf/usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf[root@localhost ~]#cp /usr/share/doc/zabbix-agent-5.0.0/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/[root@localhost ~]#chown -R zabbix:zabbix /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

12.檢視Zabbix自帶的監控模板檔案

 由配置檔案可以知道,在Linux系統中需要在zabbix-agent home目錄中建立.my.cnf(預設情況下為/var/lib/zabbix),並且檔案必須以下有三個字串:

[client]user=zbx_monitorpassword=``
[root@test2 ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default)#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html#The file must have three strings:#[client]#user=zbx_monitor#password=<password>#UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" pingUserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" versionUserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"

13.在/var/lib/zabbix目錄下建立.my.cnf配置檔案

[root@localhost ~]# vim /var/lib/zabbix/.my.cnf[mysql]host=localhostuser=zabbix           //資料庫中授權的zabbix使用者password=123qqq...A     //授權使用者密碼socket=/var/lib/mysql/mysql.sock   [mysqladmin]host=localhostuser=zabbixpassword=123qqq...Asocket=/vsr/lib/mysql/mysql.sock

14.重啟Zabbix-agent服務

[root@localhost ~]# systemctl restart zabbix-agent
三、Zabbix-server Web端配置

1.新增Mysql監控模板

2.檢視監控資料

3.檢視所有監控項圖形資訊

8
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • VMware虛擬機器中Centos 6.x系統磁碟空間擴容實戰