美文网首页zabbix
zabbix监控mysql主从关系

zabbix监控mysql主从关系

作者: WFF_FFW | 来源:发表于2017-07-19 15:39 被阅读30次

环境

操作系统:Centos 6.* ( 双核4G、硬盘至少20G)
zabbix server :192.168.1.127
zabbix agentd :192.168.1.180
mysql slave : 192.168.1.180
mysql主从参考:http://www.jianshu.com/p/fd6ab5fd22e0

一:zabbix agentd 配置
1.mysql创建用户并赋予权限

grant select,REPLICATION CLIENT on *.* to zabbix@"localhost" identified by "zabbix";

2.刷新用户权限

flush privileges;

3.监控mysql主从同步状态脚本
vim chk_mysql-slave.sh

#!/bin/bash
/usr/local/mysql/bin/mysql   -e 'show slave status\G' |grep -E "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'|grep -c Yes

4.获取mysql从同步post值实时变化脚本
vim chk_post.sh

#!/bin/bash
/usr/local/mysql/bin/mysql   -e 'show slave status\G' |grep -E "Read_Master_Log_Pos"|cut -d":" -f2 |sed 's/ //g'

5.给脚本添加执行权限

chmod +x chk_post.sh
chmod +x chk_mysql-slave.sh
post-status.png

6.在agentd配置文件末尾添加zabbix获取key值
vim /etc/zabbix/zabbix_agentd.conf

UserParameter=mysql.replication,/etc/zabbix/chk_mysql-slave.sh $1
UserParameter=mysql.post,/etc/zabbix/chk_post.sh $1

7.重启服务

/etc/init.d/zabbix-agent restart

二:zabbix server端
1.zabbix server服务器端分别获取post及状态值

/usr/local/zabbix/bin/zabbix_get -s192.168.1.180 -p10050 -k mysql.replication
/usr/local/zabbix/bin/zabbix_get -s192.168.1.180 -p10050 -k mysql.post
post-server.png

2.zabbix server web端
在本地新建一个txt文档,将以下模板内容粘贴并将名字及后缀更改为master-slave.xml, 导入此模板添加到zabbix agentd主机里即可

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>3.2</version>
    <date>2017-07-19T06:29:36Z</date>
    <groups>
        <group>
            <name>Templates</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>master-slave</template>
            <name>master-slave</name>
            <description/>
            <groups>
                <group>
                    <name>Templates</name>
                </group>
            </groups>
            <applications/>
            <items>
                <item>
                    <name>mysql.post</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>mysql.post</key>
                    <delay>30</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                </item>
                <item>
                    <name>mysql-slave-master</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>mysql.replication</key>
                    <delay>30</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <units/>
                    <delta>0</delta>
                    <snmpv3_contextname/>
                    <snmpv3_securityname/>
                    <snmpv3_securitylevel>0</snmpv3_securitylevel>
                    <snmpv3_authprotocol>0</snmpv3_authprotocol>
                    <snmpv3_authpassphrase/>
                    <snmpv3_privprotocol>0</snmpv3_privprotocol>
                    <snmpv3_privpassphrase/>
                    <formula>1</formula>
                    <delay_flex/>
                    <params/>
                    <ipmi_sensor/>
                    <data_type>0</data_type>
                    <authtype>0</authtype>
                    <username/>
                    <password/>
                    <publickey/>
                    <privatekey/>
                    <port/>
                    <description/>
                    <inventory_link>0</inventory_link>
                    <applications/>
                    <valuemap/>
                    <logtimefmt/>
                </item>
            </items>
            <discovery_rules/>
            <httptests/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{master-slave:mysql.replication.last()}=0</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql_IO and RUN</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>5</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
        <trigger>
            <expression>{master-slave:mysql.replication.last()}=1</expression>
            <recovery_mode>0</recovery_mode>
            <recovery_expression/>
            <name>mysql_IO or RUN</name>
            <correlation_mode>0</correlation_mode>
            <correlation_tag/>
            <url/>
            <status>0</status>
            <priority>4</priority>
            <description/>
            <type>0</type>
            <manual_close>0</manual_close>
            <dependencies/>
            <tags/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <name>mysql.post</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>0</show_work_period>
            <show_triggers>0</show_triggers>
            <type>0</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>5</drawtype>
                    <color>99FFFF</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>master-slave</host>
                        <key>mysql.post</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
        <graph>
            <name>mysql IO RUN</name>
            <width>900</width>
            <height>200</height>
            <yaxismin>0.0000</yaxismin>
            <yaxismax>100.0000</yaxismax>
            <show_work_period>1</show_work_period>
            <show_triggers>1</show_triggers>
            <type>1</type>
            <show_legend>1</show_legend>
            <show_3d>0</show_3d>
            <percent_left>0.0000</percent_left>
            <percent_right>0.0000</percent_right>
            <ymin_type_1>0</ymin_type_1>
            <ymax_type_1>0</ymax_type_1>
            <ymin_item_1>0</ymin_item_1>
            <ymax_item_1>0</ymax_item_1>
            <graph_items>
                <graph_item>
                    <sortorder>0</sortorder>
                    <drawtype>5</drawtype>
                    <color>00EEEE</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>2</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>master-slave</host>
                        <key>mysql.replication</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

zabbix server端监控mysql post值


f1.png

zabbix server端监控mysql主从状态


f2.png

相关文章

网友评论

    本文标题:zabbix监控mysql主从关系

    本文链接:https://www.haomeiwen.com/subject/puyhkxtx.html