您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页zabbix监控mysql

zabbix监控mysql

来源:二三娱乐

在mysql中创建用户

首先我们在 Mysql 数据库中创建一个用户,用于从Mysql中获取数据,将数据发送到zabbix,这样就是现实了 zabbix 监控 mysql。

# systemctl start mariadb
# mysql -u root -p
mysql> GRANT USAGE ON *.* to "zabbix"@"localhost" IDENTIFIED BY "zabbix";
mysql> FLUSH PRIVILEGES;
mysql> exit

测试一下刚刚创建的用户

# mysql -uzabbix -p
password: 
mysql> \q

修改zabbix-agent的mysql配置文件

# find / -name *.sock -print
/var/lib/mysql/mysql.sock
# mkdir -p /opt/zabbix/etc
# vim  

# 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

我们需要修改zabbix-agentd 的配置文件

# cp -v /usr/local/src/zabbix-2.2.16/conf/zabbix_agentd/userparameter_mysql.conf /usr/local/etc/zabbix_agentd.conf.d/
`/usr/local/src/zabbix-2.2.16/conf/zabbix_agentd/userparameter_mysql.conf' -> `/usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf'
# vim /usr/local/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

 For all the following commands HOME should be set to the directory that has  file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
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=/var/lib/zabbix mysql -N'

UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

把文件中 HOME 变量后的目录替换为刚才我们创建 mysql配置文件的所在目录。也就是把 /var/lib/zabbix 替换为 /opt/zabbix/etc,有两个位置需要修改,请注意!

这个配置文件修改完成之后,我们还需要修改 /usr/local/etc/zabbix_agentd.conf 配置文件

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

需要将上面那行配置取消注释。
所有修改的文件和目录中,都是zabbix_agentd,不是 zabbix_agent。

  • zabbix_agent 是在xinted(超级服务)方式来启动的,对应的配置文件为 zabbix_agent.conf
  • zabbix_agentd 是独立进程的方式启动的,对应的配置文件为 zabbix_agentd.conf

zabbix 服务器操作

  • 使用zabbix_agent测试客户机mysql连通
# /usr/local/bin/zabbix_get -s 192.168.0.61 -p 10050 -k mysql.ping
1

显示值为1,表示可以连通mysql。

  • 找到"组态-主机",点击主机名称进入


    Mysql添加监控
  • 点击"模板",在搜索框中输入"mysql",选择"Template App MySQL",点击添加。


    添加mysql模板
  • 点击"监控中-图形",查看Mysql图形信息。


    监控mysql图形

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务