zabbix利用自带模板监控mysql
作者:互联网
步骤参考:zabbix使用自带模板监控MySQL - 木与风 - 博客园
先放出完整步骤:
1,创建数据库监控用户
mysql -uroot -proot
GRANT USAGE ON *.* TO 'mysqlcheck'@'localhost' IDENTIFIED BY 'mysqlcheck';
FLUSH PRIVILEGES;
注意:当出现错误:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
说明密码复杂度较低,可以调整mysql策略
1.1 SHOW VARIABLES LIKE 'validate_password%';
1.2 set global validate_password_policy=LOW;
1.3 重新执行新建用户
1.4 set global validate_password_policy=MEDIUM;
2,创建mysql,mysqladmin超链接
ln -fs /opt/mysql/bin/mysqladmin /usr/bin
ln -fs /opt/mysql/bin/mysql /usr/bin
3,/etc/zabbix/路径下新建.my.cnf文件
[mysql]
host=localhost
user=mysqlcheck
password=mysqlcheck
socket=/data/mysql/mysql.sock
[mysqladmin]
host=localhost
user=mysqlcheck
password=mysqlcheck
socket=/data/mysql/mysql.sock
4,重启zabbix_agent,文后附录重启脚本
5,进入zabbix主服务器,测试
cd /data/zabbix_server/bin/
./zabbix_get -s 10.200.56.60 -p 10050 -k mysql.ping
若一直报错Access denied for user 'root'@'localhost' (using password: NO),没有使用我们刚创建的mysqlcheck用户
则需要进入到/etc/zabbix/zabbix_agentd.d/目录下,修改userparameter_mysql.conf
修改 /var/lib/zabbix 为/etc/zabbix/
然后重启zabbix_agentd
下面主要记录其中会出现的问题:
1,创建mysql用户
mysql -uroot -proot
GRANT USAGE ON *.* TO 'mysqlcheck'@'localhost' IDENTIFIED BY 'mysqlcheck';
若出现ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,说明密码复杂度较低,可以调整mysql策略
1.1 SHOW VARIABLES LIKE 'validate_password%';
1.2 set global validate_password_policy=LOW;
1.3 重新执行新建用户
1.4 set global validate_password_policy=MEDIUM;
2,出现Access denied for user 'root'@'localhost' (using password: NO)
若一直报错Access denied for user 'root'@'localhost' (using password: NO),没有使用我们刚创建的mysqlcheck用户
则需要进入到/etc/zabbix/zabbix_agentd.d/目录下,修改userparameter_mysql.conf
修改 /var/lib/zabbix 为/etc/zabbix/
然后重启zabbix_agentd
cd /etc/zabbix/zabbix_agentd.d/
vi userparameter_mysql.conf
3,出现错误
mysql mysqladmin: command not found
这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
ln -fs /opt/mysql/bin/mysqladmin /usr/bin
ln -fs /opt/mysql/bin/mysql /usr/bin
4,重启脚本附录:
#!/bin/bash
pfurl='/usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf'
PID=0
kill_zabbix_agentd(){
ps aux | awk -r '/zabbix_agentd/{print $2}' | xargs -n1 -exec kill {} &> /dev/null
}
pfstart(){
num=`ps aux | awk -r '/zabbix_agentd/{print $2}' | wc -l`
if [ $num != "1" ];then
echo "zabbix_agentd is useing"
else
echo "zabbix_agentd is starting..."
$pfurl
echo "start done!"
fi
}
if [ "$1" == "-s" ];then
if [ "$2" == "stop" ];then
echo "zabbix_agentd is stopping...."
kill_zabbix_agentd
echo "stop done!"
elif [ "$2" == "start" ];then
pfstart
elif [ "$2" == "restart" ];then
echo "zabbix_agentd is stopping...."
kill_zabbix_agentd
echo "stop done!"
echo "zabbix_agentd is starting..."
$pfurl
echo "start done!"
fi
elif [ "$1" == "--help" ];then
echo "zabbix_agentd -s [start/stop/restart]"
else
pfstart
fi
标签:bin,agentd,echo,zabbix,mysql,password,模板 来源: https://blog.csdn.net/lpping90/article/details/122663300