天天看點

zabbix8 ---- template mysql

zabbix8 ---- template mysql

zabbix

zabbix template mysql

zabbix8 ---- template mysql

使用bash建立zabbix模闆

1、配置Mysql主從

master

vim /etc/my.cnf
[mysqld]
server_id=1
log_bin
innodb_file_per_table=1

systemctl restart mariadb

grant  replication slave on *.* to 'repluser'@'192.168.10.%'  identified by 'pass123';
#revoke all on *.* from repluser@'192.168.10.%';
show variables like 'server_id';
show master logs;

mysqldump  -B zabbix -F -E -R --single-transaction --master-data=1 --flush-privileges --triggers --default-character-set=utf8 --hex-blob > zabbix_all.sql

show processlist;           

slave

cat /etc/my.cnf
[mysqld]
server_id=16
read_only=ON
innodb_file_per_table=1
replicate-do-db=zabbix		#設定需要複制的資料庫(多資料庫使用逗号,隔開)
#replicate-ignore-db=zabbix_proxy_active,zabbix_proxy_passive  #設定需要忽略的複制資料庫 (多資料庫使用逗号,隔開)

systemctl restart mariadb

mysql < zabbix_all.sql 

CHANGE MASTER TO MASTER_HOST='192.168.10.11', MASTER_USER='repluser', MASTER_PASSWORD='pass123', MASTER_PORT=3306, MASTER_LOG_FILE='mariadb-bin.000003', MASTER_LOG_POS=245;

start slave;           

2、配置zabbix_agent

grep ^[a-Z] zabbix_agentd.conf  
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.10.0/24
ServerActive=192.168.10.3
Hostname=192.168.10.16
Include=/etc/zabbix/zabbix_agentd.d/*.conf

/etc/zabbix/zabbix_agentd.d/userparameter_mysqld.conf
UserParameter=mysql_status[*],/etc/zabbix/zabbix_agentd.d/mysql_monitor.sh "$1"           

3、監控腳本驗證

/etc/zabbix/zabbix_agentd.d/mysql_monitor.sh
Seconds_Behind_Master(){
    NUM=`mysql -uroot -hlocalhost   -e "show slave status\G;"  | grep "Seconds_Behind_Master:" | awk -F: '{print $2}'`
    echo $NUM
}

master_slave_check(){
    NUM1=`mysql -uroot -hlocalhost   -e "show slave status\G;"  | grep "Slave_IO_Running" | awk -F:  '{print $2}' | sed 's/^[ \t]*//g'`
    #echo $NUM1
    NUM2=`mysql -uroot -hlocalhost   -e "show slave status\G;"  | grep "Slave_SQL_Running:" | awk -F:  '{print $2}' | sed 's/^[ \t]*//g'`
    #echo $NUM2

    if [[ $NUM1 =~ "Yes" ]] && [[ $NUM2 =~ "Yes" ]];then
        echo 200
    else
        echo 404
    fi
}

main(){
    case $1 in
        Seconds_Behind_Master)
           Seconds_Behind_Master;
           ;;
        master_slave_check)
           master_slave_check
           ;;
        *)
            echo "$0 Seconds_Behind_Master|master_slave_check"
    esac
}

main $1

[root@zabbix-server ~]# zabbix_get -s 192.168.10.16 -k mysql_status["master_slave_check"]
200
[root@zabbix-server ~]# zabbix_get -s 192.168.10.16 -k mysql_status["master_slave_check"]
404           

4、zabbix web添加模闆

zabbix8 ---- template mysql
zabbix8 ---- template mysql

監控項

zabbix8 ---- template mysql
zabbix8 ---- template mysql

圖形

zabbix8 ---- template mysql
zabbix8 ---- template mysql

觸發器

zabbix8 ---- template mysql
zabbix8 ---- template mysql

5、zabbix web添加主機監控

zabbix8 ---- template mysql
zabbix8 ---- template mysql

6、驗證

zabbix8 ---- template mysql

基于percona-monitoring-plugins建立模闆

官方文檔:https://www.percona.com/software/documentation

https://www.percona.com/doc/percona-monitoring-plugins/1.1/index.html

軟體包擷取:https://www.percona.com/downloads/percona-monitoring-plugins/

https://downloads.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm

1、基于php的方式實作,需要安裝php和php- mysql

yum install php php-mysql

2、安裝模闆.https://www.percona.com/downloads/percona-monitoring-plugins/

wget https://downloads.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm 
以下有腳本及配置檔案,模闆需要修改時區及SNMP相關設定,功能性可參考此xml檔案
[root@localhost ~]# rpm -ql percona-zabbix-templates 
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml           

3、複制con配置檔案/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf到 zabbix agent目錄

cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/.           

4、建立php賬戶密碼檔案,/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf

<?php
$mysql_user = 'root';
$mysql_pass = '';

驗證參數
[root@localhost ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
0
[root@localhost ~]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh lh
81892921           

5、導入模闆并關聯主機

導入模闆失敗

zabbix8 ---- template mysql
zabbix8 ---- template mysql

修改時間區域及snmp相關設定