使用zabbix5.2监控mariadb--第七步

2023-11-12

困难点:zabbix5.2可用的userparameter_mysql.conf问题,一般不成功是因为监控脚本和数据库账号授权。

01 前言

zabbix内置Mysql的监控模版,因为mariadb和Mysql两者的相关性,所以这个模版也能用在mariadb services上。

02 Mysql

登陆mysql

#mysql -uroot -p

首先要在mariadb新建一个账户,这个账户不需要有任何权限。这个账户只是用来登入mariadb获取服务状态。

GRANT ALL PRIVILEGES ON *.* TO 'zabbix'@'10.255.255.62' IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;

请将以下内容根据实际情况进行替换:

  • user name >>mariadb账户名
  • server ip >>mariadb服务器IP
  • passwd >>mariadb密码

03  Zabbix Agent

完成mariadb的用户添加后,还要在mariadb服务器安装Zabbix Agent。通过以下文件可以得知还需要新建一个文件,并在这个文件内填入mariadb的信息:

# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf

# For all the following commands HOME should be set to the directory that has .my.cnf 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

然后新建以下文件并进行修改,要注意的是 /var/lib/zabbix 这个路径可能并不存在,需要手动新建:

#新建文件夹

mkdir -p /var/lib/zabbix

#修改文件

vim /etc/my.cnf

#填入内容

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

[mysqld]

#skip-grant-tables

[mysql]

host=10.255.255.62

user=zabbix

password=zabbix

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

[mysqladmin]

host=10.255.255.62

user=zabbix

password=zabbix

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

[client]

host=10.255.255.62

user=zabbix

password=zabbix

 

#修改文件

vim /var/lib/zabbix/.my.cnf

[mysql]

user=zabbix

password=zabbix

host=10.255.255.62

 

[mysqladmin]

user=zabbix

password=zabbix

host=10.255.255.62

 

 

[client]

user=zabbix

password=zabbix

host=10.255.255.62

完成后需要通过以下命令手动重启mariadb services和zabbix agent services:

#重启mariadb

systemctl restart mariadb.service

#重启zabbix agent

systemctl restart zabbix-agent.service

 

04 Zabbix平台配置

注意,我这里以代理的方式监控

创建mysql监控组

 

添加监控主机

 

添加监控模板

查看

 

 

 

 

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用zabbix5.2监控mariadb--第七步 的相关文章

  • ACLR指标

    文章目录 一 ACLR含义 二 ACLR来源 一 ACLR含义 ACLR Adjacent Channel Leakage Power Ratio 测试目的 避免对邻近信道产生干扰 LTE和ACLR测试除了需要测试自身带宽相同的邻信道泄漏功
  • okGo详细使用步骤(一)

    OkGo的使用 一 详细使用方式可以直接观看源文档wiki 这里不再说明 本文档也是依赖于源文档进行代码测试和理解写的 写此文档时okgo版本 compile com lzy net okgo 3 0 4 几个库的介绍 library名 简

随机推荐