0

I have a server with a zabbix agent installed, this is working fine.

I want to monitor a database on the server, I have followed the documentation of MySQL by Zabbix agent.

I have an error inside the log

mysqladmin: connect to server at '127.0.0.1' failed
error: 'Access denied for user 'zabbix'@'localhost' (using password: NO)'

Here is a longer part of the logs:

 15110:20220919:154820.657 In zbx_waitpid()
 15110:20220919:154820.657 zbx_waitpid() exited, status:0
 15110:20220919:154820.658 End of zbx_waitpid():15142
 15110:20220919:154820.658 Run remote command [ mysqladmin -h"127.0.0.1" -P"3306" ping] Result [0] []...
 15110:20220919:154820.658 Sending back []
 15110:20220919:154820.658 listener #2 [waiting for connection]
 15110:20220919:154820.719 listener #2 [processing request]
 15110:20220919:154820.719 Requested [system.cpu.util[,iowait]]
 15110:20220919:154820.719 Sending back [0.071416]
 15110:20220919:154820.719 listener #2 [waiting for connection]
 15111:20220919:154821.077 listener #3 [processing request]
 15111:20220919:154821.077 Requested [mysql.ping["127.0.0.1","3306"]]
 15111:20220919:154821.077 In zbx_popen() command:' mysqladmin -h"127.0.0.1" -P"3306" ping'
 15111:20220919:154821.078 End of zbx_popen():8
 15143:20220919:154821.078 zbx_popen(): executing script
mysqladmin: connect to server at '127.0.0.1' failed
error: 'Access denied for user 'zabbix'@'localhost' (using password: NO)'
 15111:20220919:154821.089 In zbx_waitpid()
 15111:20220919:154821.089 zbx_waitpid() exited, status:0
 15111:20220919:154821.089 End of zbx_waitpid():15143
 15111:20220919:154821.089 Run remote command [ mysqladmin -h"127.0.0.1" -P"3306" ping] Result [0] []...
 15111:20220919:154821.089 Sending back []
 15111:20220919:154821.090 listener #3 [waiting for connection]
 15112:20220919:154821.114 In send_buffer() host:'<ip>' port:10051 values:0/100
 15112:20220919:154821.114 End of send_buffer():SUCCEED
 15112:20220919:154821.114 active checks #1 [idle 1 sec]
 15108:20220919:154821.116 collector [processing data]
 15108:20220919:154821.116 In update_cpustats()
 15108:20220919:154821.116 End of update_cpustats()
 15108:20220919:154821.116 collector [idle 1 sec]
 15109:20220919:154821.543 listener #1 [processing request]

But my .my.cnf that is in /var/run/zabbix/ look like that:

[client]
user='zbx_monitor'
password='<password>'

The home directory of the zabbix user is /var/run/zabbix/ so it should work.

I have done it on other servers and it worked fine. But on this one the .my.cnf is not working and I can't find why.

The only things different between the server:

  • Home directory
  • Server date, so not the same linux version

Do you have any idea what could cause this problem ?

Edit:

namei -l /var/run/zabbix/.my.cnf

f: /var/run/zabbix/.my.cnf
drwxr-xr-x root   root   /
drwxr-xr-x root   root   var
lrwxrwxrwx root   root   run -> /run
drwxr-xr-x root   root     /
drwxr-xr-x root   root     run
drwxr-xr-x zabbix zabbix zabbix
-rw-r----- zabbix zabbix .my.cnf

If I try to run the command with the user zabbix it works:

sudo -u zabbix mysqladmin -h"127.0.0.1" -P"3306" ping
mysqld is alive

So the error is happening only when it's the zabbix agent that run the command.

Here is the home directory of my zabbix user

getent passwd zabbix
zabbix:x:109:115::/var/run/zabbix/:/bin/false

3 Answers3

1

Even so the home directory of my Zabbix user is /var/run/zabbix, it seem that it's not the directory that is used as a home by zabbix commands.

I changed /etc/zabbix/zabbix_agentd.conf.d/template_db_mysql.conf like that, I added the HOME=/var/run/zabbix before each command:

UserParameter=mysql.ping[*],HOME=/var/run/zabbix mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], HOME=/var/run/zabbix mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], HOME=/var/run/zabbix mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], HOME=/var/run/zabbix mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], HOME=/var/run/zabbix mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], HOME=/var/run/zabbix mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], HOME=/var/run/zabbix mysql -h"$1" -P"$2" -sNX -e "show slave status"
0

The permissions of your .my.cnf are too wide open.

$ ls -l .my.cnf
-rwxrwxrwx 1 user user 44 Sep 14 15:40 .my.cnf
$ mysqladmin ping
mysqladmin: [Warning] World-writable config file '/home/user/.my.cnf' is ignored.
mysqladmin: connect to server at 'localhost' failed

Set the proper permissions.

chmod 640 /var/run/zabbix/.my.cnf
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • I ran the chmod, but I still have the same error. Here is the permissions `-rw-r----- 1 zabbix zabbix 48 sept. 14 10:58 .my.cnf`. How do you get this error ? When I cd myself inside the `/var/run/zabbix`and do the same command I get `'Access denied for user 'root'@'localhost'`. I can't log in as `zabbix` since the shell is `/bin/false`. – Gregory Boutte Sep 14 '22 at 13:52
  • Please edit the output of `namei -l /var/run/zabbix/.my.cnf` into your question. – Gerald Schneider Sep 14 '22 at 13:53
  • Ok, I just added the infos you asked – Gregory Boutte Sep 14 '22 at 14:15
  • Are you sure about the location of the zabbix home directory? On my systems (installed via official packages) the home directory is in `/var/lib/zabbix/`. Please edit the output of `grep zabbix /etc/passwd` into your question. `/var/run` is usually linked to `/run`, which is usually a non permanent directory that is reset at reboot. – Gerald Schneider Sep 15 '22 at 09:12
  • Yes, I'm pretty sure it is. On other servers yes the home directory was `/var/lib/zabbix`. Maybe its because this server is older, and zabbix agent was installed some years ago. Should I change the zabbix home directory ? Inside `/var/run/zabbix/` there is a folder `.rpmdb`and a file `zabbix_agentd.pid` – Gregory Boutte Sep 15 '22 at 09:17
0

Do not put the single quotes around your values,

[client] 
user='zbx_monitor' 
password='<password>' 

Let us know how it works out.

Wilson Hauck
  • 472
  • 5
  • 11