用zabbix监控mysql(源码安装)安装位置在/usr/local/zabbix/


  1. 监控端(server):

    在被监控端主机上关联该模板Template App MySQL

中文:组态->主机->名称一栏点击进去->模板,点击链接新模板->添加->Template App MySQL->存档

英文:Configuration->Hosts->Name->Templates,Link new templates->Add->Template App MySQL->Save


2. 被监控端(agent):

1)在源码包../zabbix-2.2.1/conf/zabbix_agentd/ 拷贝模板

cp zabbix-2.2.1/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/

2)授予监控mysql信息的用户权限

mysql> grant usage on *.* to zabbix@'localhost' identified by 'zabbix';

3)修改my.cnf

[mysqladmin]
host=localhost
user=zabbix
password=zabbix
[mysql]
host=localhost
user=zabbix
password=zabbix

4)修改

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -uzabbix -pzabbix -hlocalhost -N | awk '{print $$2}'
UserParameter=mysql.size[*],echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all"
 || ! "$1" ]] || echo " where table_schema='$1'")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name='$2'");" | HOME=/var/lib/zabbix mysql -uzabbix -pzabbix -hlocalhost -N
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin -uzabbix -pzabbix -hlocalhost ping | grep -c alive
UserParameter=mysql.version,mysql -uzabbix -pzabbix -hlocalhost -V

5)

# /etc/init.d/mysqld restart
# /etc/init.d/zabbix_agentd restart

6)在server上的查看图像数据

     Monitoring->Graphs->MySQL operations


nagios监控主从

ls /usr/local/nagios/etc/objects/commands.cfg

# vim /usr/local/nagios/etc/objects/commands.cfg
define command  {
         command_name    check_mysql_slave
         command_line  $USER1$/check_mysql -H $HOSTADDRESS$ -S -uzabbix -pzabbix
  }
修改被监控端的配置文件
# vim zabbix_agent.cfg
  
define service{
        use                             local-service
        host_name                       zabbix_agent
        service_description             MYSQL_SLAVE
        check_command                   check_mysql_slave                     
}

/etc/init.d/nagios restart