當(dāng)前位置:首頁 > IT技術(shù) > 數(shù)據(jù)庫 > 正文

zabbix監(jiān)控mysql
2021-10-07 11:19:47

zabbix監(jiān)控mysql

關(guān)閉防火墻,防止出現(xiàn)zabbix與mysql連接異常

setenforce 0
systemctl stop firewalld

在被監(jiān)控端,安裝zabbix監(jiān)控客戶端

下載客戶端

wget https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.15-1.el7.x86_64.rpm

安裝客戶端

rpm -ivh zabbix-agent-5.0.15-1.el7.x86_64.rpm

修改配置

vim /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.31.158
ServerActive=192.168.1.31.158
Hostname=192-168-31-157
Include=/etc/zabbix/zabbix_agentd.d/*.conf

啟動(dòng)客戶端

systemctl start zabbix-agent.service

創(chuàng)建zabbix的mysql賬號(hào)

mysql> create user zabbix@'%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant usage,replication client,process,show databases,show view on *.* to zabbix@'%';
Query OK, 0 rows affected (0.00 sec)

在/etc/zabbix/目錄下創(chuàng)建.my.cnf文件,vim .my.cnf

[client]
host=localhost
user='root'
password='123456'

復(fù)制userparameter_mysql.conf文件到/etc/zabbix/zabbix_agentd.d目錄下

cp /usr/share/doc/zabbix-agent-5.0.15/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

編輯修改參數(shù),增加.my.cnf的環(huán)境變量,指定mysqladmin等命令的位置vim 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,BASEDIRmy.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[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*],HOME=/etc/zabbix /usr/local/mysql/bin/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[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*],HOME=/etc/zabbix /usr/local/mysql/bin/mysql -h"$1" -P"$2" -sNX -e "show slave status"

在zabbix服務(wù)端頁面增加配置模板


本文摘自 :https://www.cnblogs.com/

開通會(huì)員,享受整站包年服務(wù)立即開通 >