192.168.254.127 (zabbix)
192.168.254.128 (mysql)
zabbix_agentd客户端设置
在mysql数据上创建一个普通用户zabbix,密码zabbix
[root@mysql1 scripts]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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 zabbix@'192.168.254.128' identified by 'zabbix'; ###创建一个有权限的访问用户zabbix密码设置zabbix
Query OK, 0 rows affected (0.04 sec)
mysql> update mysql.user set authentication_string=password('zabbix') where user='zabbix' and Host = '192.168.254.128'; ###更新下改用户的密码
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> select Host,User,authentication_string from mysql.user;
+-----------------+---------------+-------------------------------------------+
| Host | User | authentication_string |
+-----------------+---------------+-------------------------------------------+
| localhost | root | 182EA09A38F1141B2D7916812BD097D51167C3E4 |
| localhost | mysql.session | THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| % | root | 182EA09A38F1141B2D7916812BD097D51167C3E4 |
| 192.168.254.% | slave_cp | 196BDEDE2AE4F84CA44C47D54D78478C7E2BD7B7 |
| 192.168.254.128 | zabbix | DEEF4D7D88CD046ECA02A80393B7780A63E7E789 |
+-----------------+---------------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> exit
Bye
修改/etc/my.cnf文件创建无密码登录(把下面的配置添加进入)
[client]
user=zabbix
password=zabbix
[mysqladmin]
host=192.168.254.128
user=zabbix
password=zabbix
测试是否可以直接访问不需要输入密码,如果输入命令 直接进去说明已OK。
[root@mysql1 scripts]# mysql -uzabbix -h192.168.254.128
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 189
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
现在数据库端 测试 是否可以查看到相关数据
mysqladmin extended-status |grep -w "Bytes_received" |cut -d"|" -f3 ###有数据返回说明正常
[root@mysql1 scripts]# mysqladmin extended-status |grep -w "Bytes_received" |cut -d"|" -f3
58691
创建mysql监控脚本在目录/etc/zabbix/scripts/chk_mysql.sh并赋予相关的权限。
#!/bin/bash