[Z3001] connection to database ‘zabbix‘ failed: [1045] Access denied for user ‘zabbix‘@‘localhost‘

文章讲述了在监控系统Zabbix中遇到的数据库访问权限问题,通过检查服务器端状态、日志文件和MySQL权限设置,解决了ZabbixServer无法连接数据库的问题,包括配置文件修改和权限授予等步骤。

1.1排查问题所在

首先看zabbix网页端的状态在,发现:“zabbix server is running”的值是不,但是通过如下指令在服务器端查看zabbixserver是正常运行。

[root@Teledb zabbix]# systemctl status zabbix-server

通过看日志文件继续排查,通过如下指令找到安装zabbix时的日志文件所在。 

[root@Teledb zabbix]# find / -name zabbix_server.log
/var/log/zabbix/zabbix_server.log

查看一下

101570:20230913:170354.772 Cannot connect to the database. Exiting...
101853:20230913:170354.794 Starting Zabbix Server. Zabbix 4.0.48 (revision 832b83c76af).
101853:20230913:170354.794 ****** Enabled features ******
101853:20230913:170354.794 SNMP monitoring:           YES
101853:20230913:170354.794 IPMI monitoring:           YES
101853:20230913:170354.794 Web monitoring:            YES
101853:20230913:170354.794 VMware monitoring:         YES
101853:20230913:170354.794 SMTP authentication:       YES
101853:20230913:170354.794 Jabber notifications:      YES
101853:20230913:170354.794 Ez Texting notifications:  YES
101853:20230913:170354.794 ODBC:                      YES
101853:20230913:170354.794 SSH support:               YES
101853:20230913:170354.794 IPv6 support:              YES
101853:20230913:170354.794 TLS support:               YES
101853:20230913:170354.794 ******************************
101853:20230913:170354.794 using configuration file: /etc/zabbix/zabbix_server.conf
101853:20230913:170354.799 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'Teledb' (using password: YES)
101853:20230913:170354.799 database is down: reconnecting in 10 seconds
101853:20230913:170404.801 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'Teledb' (using password: YES)
101853:20230913:170404.801 database is down: reconnecting in 10 seconds
101853:20230913:170414.806 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'Teledb' (using password: YES)
101853:20230913:170414.807 database is down: reconnecting in 10 seconds
101853:20230913:170424.811 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'Teledb' (using password: YES)

大致意思是连接数据库失败

1.2问题解决

首先先使用账号密码进入mysql,如果可以正常进入,则表示配置文件中的用户名和密码错误,如果不能进入,使用root账号进入mysql后执行如下指令:

mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option;
mysql>flush privileges;

通过上述指令将密码设置为zabbix后,再次进入,如果成功则查看配置文件密码是否一致,然后重启服务,即可,修改配置文件的指令:

vim /etc/zabbix/zabbix_server.conf

[root@Teledb zabbix]# systemctl restart zabbix-server
[root@Teledb zabbix]# systemctl status zabbix-server

重启服务即可 

1.3可能遇到的问题

如果重启服务后,查看zabbix-server的状态是正常运行,但是在网页端登录ip地址/zabbix发现报错Error connecting to database: Access denied for user ‘zabbix’ @ ‘localhost’ to database ‘zabbix’(PASSWORD:YES)

由于上文刚配置过zabbix_server.conf文件,因为大概率应该不是此配置文件的问题,于是通过find / -name指令先查找到zabbix.conf.php文件,将此文件中的网页端登录密码设置为上述设置的zabbix(根据自己设置的来)。:wq保存后重启服务后刷新网页即可。

[root@localhost ~]# vi /var/log/zabbix/zabbix_server.log 29773:20250725:145659.307 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145659.307 database is down: reconnecting in 10 seconds 29773:20250725:145709.308 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145709.308 database is down: reconnecting in 10 seconds 29773:20250725:145719.309 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145719.309 database is down: reconnecting in 10 seconds 29773:20250725:145729.310 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145729.310 database is down: reconnecting in 10 seconds 29773:20250725:145739.310 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 29773:20250725:145739.310 database is down: reconnecting in 10 seconds 29773:20250725:145749.311 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145749.311 database is down: reconnecting in 10 seconds 29773:20250725:145752.039 Got signal [signal:15(SIGTERM),sender_pid:30435,sender_uid:0,reason:0]. Exiting ... 29773:20250725:145752.040 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 29773:20250725:145752.040 Cannot connect to the database. Exiting... 30441:20250725:145752.049 Starting Zabbix Server. Zabbix 4.0.50 (revision c40ad3289ad). 30441:20250725:145752.050 ****** Enabled features ****** 30441:20250725:145752.050 SNMP monitoring: YES 30441:20250725:145752.050 IPMI monitoring: YES 30441:20250725:145752.050 Web monitoring: YES 30441:20250725:145752.050 VMware monitoring: YES 30441:20250725:145752.050 SMTP authentication: YES 30441:20250725:145752.050 Jabber notifications: YES 30441:20250725:145752.050 Ez Texting notifications: YES 30441:20250725:145752.050 ODBC: YES 30441:20250725:145752.050 SSH support: YES 30441:20250725:145752.050 IPv6 support: YES 30441:20250725:145752.050 TLS support: YES 30441:20250725:145752.050 ****************************** 30441:20250725:145752.050 using configuration file: /etc/zabbix/zabbix_server.conf 30441:20250725:145752.052 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145752.052 database is down: reconnecting in 10 seconds 30441:20250725:145802.053 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145802.053 database is down: reconnecting in 10 seconds 30441:20250725:145812.053 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145812.054 database is down: reconnecting in 10 seconds 30441:20250725:145822.055 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145822.055 database is down: reconnecting in 10 seconds 30441:20250725:145832.056 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145832.056 database is down: reconnecting in 10 seconds 30441:20250725:145842.057 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145842.057 database is down: reconnecting in 10 seconds 30441:20250725:145852.058 [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: NO) 30441:20250725:145852.058 database is down: reconnecting in 10 seconds
07-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值