zabbix5.0监控mysql

网上搜到的基本是zabbix4.0的配置,照搬就会出现一堆不支持的监控项,按照模组信息下载官方的 Template_DB_MySQL.conf也会有一堆报错,记录一下处理方法

 

默认zabbix路径为/etc/zabbix,mysql为/usr/local/mysql,请按照自己的情况修改

首先在/etc/zabbix下创建.my.cnf

[client]
user='zbx_monitor'
password='<password>'

然后在/etc/zabbix/zabbix_agent.d下创建template_db_mysql.conf


#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default) 
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user=zabbix
#password=123456
#
UserParameter=mysql.ping[*], HOME=/etc/zabbix/ /usr/local/mysql/bin/mysqladmin -h"$1" -P"$2" ping
UserParameter
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 v8-stable 以上的 rsyslog.conf 中,可以将上述内容转化成新语法,具体如下: ``` template(name="NetworkDeviceLog" type="string" string="/var/log/%fromhost-ip%/%PROGRAMNAME%.log") if $fromhost-ip == '192.168.1.1' and $syslogfacility-text == 'local7' then { action(type="omfile" template="NetworkDeviceLog" fileCreateMode="0644" fileOwner="root" fileGroup="root" dirCreateMode="0755" dirOwner="root" dirGroup="root" dirOwnerFromFilename="on" dirGroupFromFilename="on" dirCreateModeFromFilename="on" fileCreateModeFromFilename="on" fileDiscardInterval="10" flushOnTXEnd="on" flushInterval="30" flushOnTXEndTimeout="5000" dirGroup="root" dirGroupFromFilename="on" dirCreateModeFromFilename="on" fileDiscardInterval="10" flushOnTXEnd="on" flushInterval="30" flushOnTXEndTimeout="5000") action(type="ommysql" server="localhost" serverport="3306" db="RSYSLOG_MYSQL_1" dbuser="root" dbpassword="password" template="RSYSLOG_MYSQL_1" sql="INSERT INTO NetworkDeviceLog (timegenerated, fromhost, programname, message) VALUES (FROM_UNIXTIME(:timegenerated), :fromhost-ip, :programname, :msg)") } if $fromhost-ip == '192.168.1.2' and $syslogfacility-text == 'local7' then { action(type="omfile" template="NetworkDeviceLog" fileCreateMode="0644" fileOwner="root" fileGroup="root" dirCreateMode="0755" dirOwner="root" dirGroup="root" dirOwnerFromFilename="on" dirGroupFromFilename="on" dirCreateModeFromFilename="on" fileCreateModeFromFilename="on" fileDiscardInterval="10" flushOnTXEnd="on" flushInterval="30" flushOnTXEndTimeout="5000" dirGroup="root" dirGroupFromFilename="on" dirCreateModeFromFilename="on" fileDiscardInterval="10" flushOnTXEnd="on" flushInterval="30" flushOnTXEndTimeout="5000") action(type="ommysql" server="localhost" serverport="3306" db="RSYSLOG_MYSQL_2" dbuser="root" dbpassword="password" template="RSYSLOG_MYSQL_2" sql="INSERT INTO NetworkDeviceLog (timegenerated, fromhost, programname, message) VALUES (FROM_UNIXTIME(:timegenerated), :fromhost-ip, :programname, :msg)") } template(name="NetworkDeviceLog" type="string" string="/var/log/%fromhost-ip%/%PROGRAMNAME%-%$year%-%$month%-%$day%.log") ``` 上述配置中,我们使用了 template 指令来定义模板,分别命名为 NetworkDeviceLog,并使用 type 和 string 参数来指定模板类型和模板字符串。 然后,我们使用 if 指令来进行条件过滤,根据来源 IP 和 syslog facility 过滤出需要处理的日志,并使用 action 指令将日志保存到指定的文件和 mysql 数据库中的指定库和表中。 在保存日志到文件时,我们使用了 action 指令的 type 参数指定为 omfile,并使用 template 参数来指定使用的模板名称,同时还可以设置文件权限、拥有者、组等信息,以及自动创建目录和文件、自动清理文件等功能。 在保存日志到 mysql 数据库时,我们使用了 action 指令的 type 参数指定为 ommysql,并设置了 mysql 服务器的地址、端口、数据库名称、用户名和密码,以及要执行的 SQL 语句,并使用 template 参数指定了模板名称。 最后,我们再次使用 template 指令来定义模板 NetworkDeviceLog,使用 type 和 string 参数指定模板类型和模板字符串,以实现按日保存日志的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值