Ad Widget

Collapse

.my.cnf file for MySQL monitoring is ignored or inaccessible on AlmaLinux 9

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shepard
    Junior Member
    • Dec 2024
    • 6

    #1

    .my.cnf file for MySQL monitoring is ignored or inaccessible on AlmaLinux 9

    Hello,

    .my.cnf file for MySQL (Percona 8) monitoring is ignored or inaccessible by Zabbix Agent 2 (6.0) on AlmaLinux 9 with SELinux enabled.

    zabbix's home directory in /etc/passwd is /var/lib/zabbix

    What was done:
    Code:
    mkdir /var/lib/zabbix
    /var/lib/zabbix/.my.cnf file was created
    Code:
    [client]
    protocol=tcp
    user='zbx_monitor'
    password='<password>'
    MySQL user specified in /var/lib/zabbix/.my.cnf can log in and view databases, it was confirmed.

    Code:
    chown -R zabbix. /var/lib/zabbix
    chmod 400 /var/lib/zabbix/.my.cnf
    SELinux policy added:
    Code:
    cat <<EOF > zabbix_home.te
    module zabbix_home 1.0;
    
    require {
            type zabbix_agent_t;
            type zabbix_var_lib_t;
            type mysqld_etc_t;
            type mysqld_port_t;
            type mysqld_var_run_t;
            class file { open read };
            class tcp_socket name_connect;
            class sock_file write;
    }
    
    allow zabbix_agent_t zabbix_var_lib_t:file read;
    allow zabbix_agent_t zabbix_var_lib_t:file open;
    allow zabbix_agent_t mysqld_etc_t:file read;
    allow zabbix_agent_t mysqld_port_t:tcp_socket name_connect;
    allow zabbix_agent_t mysqld_var_run_t:sock_file write;
    EOF
    
    checkmodule -M -m -o zabbix_home.mod zabbix_home.te
    semodule_package -o zabbix_home.pp -m zabbix_home.mod
    semodule -i zabbix_home.pp
    restorecon -R /var/lib/zabbix
    Finally:
    Code:
    systemctl restart zabbix-agent2
    zabbix_agent2 -t mysql.version
    Result:
    Code:
    mysql.version  [m|ZBX_NOTSUPPORTED] [Cannot fetch data: Cannot fetch data: Error 1045 (28000):
    Access denied for user 'root'@'localhost' (using password: NO).]

    Any ideas what may be the reason?
  • Answer selected by tim.mooney at 02-09-2025, 21:31.
    Shepard
    Junior Member
    • Dec 2024
    • 6

    Oh, stupid me. I just have realized that I had read the documentation for Zabbix Agent 1, not for Zabbix Agent 2.

    It seems that .my.cnf file support was withdrawn from Zabbix Agent 2 in favor of 'named sessions'.




    Comment

    • kz3
      Junior Member
      • Jul 2025
      • 20

      #2
      Hey . i had a problem like this some time ago and at the end it was because the config of the data base was missing on

      /etc/zabbix/web/zabbix.conf.php
      ubuntu
      after adding the correct user , database , port ..etc
      Click image for larger version

Name:	image.png
Views:	46
Size:	7.6 KB
ID:	506670

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #3
        Access denied for user 'root'@'localhost' (using password: NO).]
        You are testing as user root? Should switch to "zabbix" ...

        Comment

        • Shepard
          Junior Member
          • Dec 2024
          • 6

          #4
          Originally posted by cyber
          You are testing as user root? Should switch to "zabbix" ...
          Thank you for replying.
          No, I'm testing as 'zabbix' linux user, but the error message says that the agent wants to connect to MySQL as root, that is the problem.

          Comment

          • Shepard
            Junior Member
            • Dec 2024
            • 6

            #5
            Originally posted by kz3
            Hey . i had a problem like this some time ago and at the end it was because the config of the data base was missing on

            /etc/zabbix/web/zabbix.conf.php
            ubuntu
            after adding the correct user , database , port ..etc
            Click image for larger version

Name:	image.png
Views:	46
Size:	7.6 KB
ID:	506670
            Thanks for your reply. It seems you are talking about connecting to Zabbix database, and what I need is to monitor another database by using Zabbix agent 2.

            Comment

            • Shepard
              Junior Member
              • Dec 2024
              • 6

              #6
              Oh, stupid me. I just have realized that I had read the documentation for Zabbix Agent 1, not for Zabbix Agent 2.

              It seems that .my.cnf file support was withdrawn from Zabbix Agent 2 in favor of 'named sessions'.




              Comment

              Working...