zabbix监控mysql

安装mysql

[root@test3 /]# yum -y install mysql mysql-server

初始化数据库

[root@test3 /]# /etc/init.d/mysqld start

[root@test3 /]# mysqladmin -uroot -h 127.0.0.1 password 123456

[root@test3 /]# mysql -u root -p
Enter password:

创建一个登陆mysql的用户

mysql> GRANT USAGE ON*.*TO'zabbix'@'localhost'IDENTIFIED BY'zabbix';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql> quit

Bye

通过find / -name mysql.sock找出mysql.sock文件路径

[root@test3 /]# find / -name *sock -print/usr/sbin/mksock/var/lib/mysql/mysql.sock

新建文件

[root@test3 /]# vim /usr/local/zabbix/etc/.my.cnf

#zabbix Agent

[mysql]

host=localhost

user=zabbix

password=zabbix

socket=/var/lib/mysql/mysql.sock

[mysqladmin]

host=localhost

user=zabbix

password=zabbix

socket=/var/lib/mysql/mysql.sock

找到userparameter_mysql.conf

[root@oracle zabbix_agentd.conf.d]# find / -name userparameter_mysql.conf

/root/zabbix-3.0.4/conf/zabbix_agentd/userparameter_mysql.conf

root@test3 etc]# cd /root/zabbix-3.0.4/conf/zabbix_agentd

[root@test3 zabbix_agentd]# ls

userparameter_examples.conf  userparameter_mysql.conf

[root@test3 zabbix_agentd]# cp userparameter_mysql.conf  /usr/local/zabbix/etc/zabbix_agentd.conf.d

[root@mysql zabbix_agentd.d]# vim userparameter_mysql.conf 

UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix /usr/bin/mysql -N | awk '{print $$2}'

UserParameter=mysql.size[*],bash -c '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=/etc/zabbix /usr/bin/mysql -N'

 

UserParameter=mysql.ping,HOME=/etc/zabbix /usr/bin/mysql ping | grep -c alive

UserParameter=mysql.version,/usr/bin/mysql -V

注释:/etc/zabbix zabbix的安装目录  /usr/bin/mysqlmysql的安装目录

[root@mysql zabbix_agentd.d]# chown zabbix:zabbix userparameter_mysql.conf

 

[root@test3 zabbix_agentd]# cd  /usr/local/zabbix/etc/zabbix_agentd.conf.d

 

[root@test3 zabbix_agentd.conf.d]# cd /usr/local/zabbix/etc/
修改zabbix_agentd.conf文件,添加下面一行

[root@test3 etc]#pwd

/usr/local/zabbix/etc/

[root@test3 etc]# vim zabbix_agentd.conf

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/

[root@test3 etc]# /etc/init.d/zabbix_agentd restart

Shutting down zabbix_agentd:                               [  OK  ]

Starting zabbix_agentd:                                    [  OK  ]

Web界面配置省略

 

posted @ 2017-04-27 15:38  yy迷迭香  阅读(182)  评论(0编辑  收藏  举报