Zabbix运用自带模板监控MySQL
发布时间:2022-08-23 16:19 所属栏目:115 来源:互联网
导读:zabbix在监控mysql数据库时,会使用自带的模板Template App MySQL,是不能直接使用的,因为没有key,而获取不到数据,前端会出现如下报错Warning: Using a password on the command line interface can be insecure.报错原因是mysql 5.6以后的版本增加了密码
zabbix在监控mysql数据库时,会使用自带的模板Template App MySQL,是不能直接使用的,因为没有key,而获取不到数据,前端会出现如下报错“Warning: Using a password on the command line interface can be insecure.”报错原因是mysql 5.6以后的版本增加了密码安全策略,在命令行里加上密码就会强制报错,而5.6之前版本可以直接使用的。 zabbix_agentd客户端设置 1.在mysql数据上创建一个普通用户lqb [root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 756 Server version: 5.5.58-log MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> grant all PRIVILEGES on *.* to lqb@'localhost' identified by '123456'; ###创建一个有权限的访问用户lqb密码设置123456 Query OK, 0 rows affected (0.04 sec) mysql> update mysql.user set authentication_string=password('123456') where user='lqb' and Host = 'localhost'; ###更新下改用户的密码 Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> exit Bye 2.修改/etc/my.cnf文件创建无密码登录 [root@localhost ~]# vim /etc/my.cnf [client] user=lqb password=123456 [mysqladmin] host=localhost user=lqb password=123456 3.测试是否可以直接访问,如果输入命令mysql -ulqb直接进去说明已OK。 [root@localhost ~]# mysql -ulqb Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 761 Server version: 5.5.58-log MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 4.创建mysql监控脚本在目录/usr/local/zabbix/scripts/chk_mysql.sh并赋予相关的权限。 # 获取数据 case $1 in Uptime) result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` echo $result ;; Com_update) result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` echo $result ;; Slow_queries) result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` echo $result ;; Com_select) result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` echo $result ;; Com_rollback) result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` echo $result ;; Questions) result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` echo $result ;; Com_insert) result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` echo $result ;; Com_delete) result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` echo $result ;; Com_commit) result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` echo $result ;; Bytes_sent) result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` echo $result ;; Bytes_received) result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` echo $result 5.修改zabbix_agentd.conf添加以下参数: UserParameter=mysql.version,mysql -V UserParameter=mysql.status[*], /usr/local/zabbix/scripts/chk_mysql.sh $1 UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -ulqb ping | grep -c alive [root@localhost scripts]# grep '^[a-Z]' /usr/local/zabbix/etc/zabbix_agentd.conf LogFile=/tmp/zabbix_agentd.log Server=172.20.66.110 Hostname=172.21.100.12 RefreshActiveChecks=120 Timeout=20 UserParameter=mysql.version,mysql -V UserParameter=mysql.status[*], /usr/local/zabbix/scripts/chk_mysql.sh $1 UserParameter=mysql.ping,/usr/local/mysql/bin/mysqladmin -ulqb ping | grep -c alive 6.重启zabbix_agentd客户端服务,查看有没有报错。 (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读