我的 Monit 配置存在“问题”。监控工作正常,但/var/log/mysql/error.log
每次运行监控脚本时,mysql 错误文件上都会出现以下错误:
190821 10:47:49 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:48:19 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:48:49 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:49:19 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:49:49 [Warning] Access denied for user ''@'localhost' (using password: NO)
这是我的监控配置文件:
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
group mysql
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host localhost port 3306 protocol mysql then alert
depend mysql_bin
depend mysql_rc
check file mysql_bin with path /usr/sbin/mysqld
group mysql
include /etc/monit/templates/rootbin
check file mysql_rc with path /etc/init.d/mysql
group mysql
include /etc/monit/templates/rootbin
有没有办法为监控检查指定用户名和密码,以防止错误日志中出现那些警告?
答案1
这是 monit 尝试以匿名用户身份连接到您的 MySQL 实例。您可以创建一个匿名用户(不推荐),或者按照官方文档:
MYSQL
句法:
PROTOCOL MYSQL [USERNAME string PASSWORD string]
用户名MySQL 用户名(最多 16 个字符)。
密码MySQL 密码(可以使用特殊字符,但非字母数字的密码必须用引号引起来)。
用户名和密码(凭证)是选修的如果未设置,Monit 将使用匿名登录执行测试。这可能会导致身份验证错误记录在您的 MySQL 日志中,具体取决于您的 MySQL 配置。
如果设置了凭据,Monit 将登录并执行 MySQL ping 测试。Monit 不需要任何数据库权限,它只需要数据库用户。您可能希望为 Monit 创建独立用户以供测试时使用,例如:
CREATE USER 'monit'@'host_from_which_monit_performs_testing' IDENTIFIED BY 'mysecretpassword'; FLUSH PRIVILEGES;
例子:
check process mysql with pidfile /var/run/mysqld/mysqld.pid start program = "/sbin/start mysql" stop program = "/sbin/stop mysql" if failed port 3306 protocol mysql username "foo" password "bar" then alert