Ad Widget

Collapse

Newbie question: Why won't zabbix "see" the .my.cnf file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James5mith
    Junior Member
    • Sep 2013
    • 7

    #1

    Newbie question: Why won't zabbix "see" the .my.cnf file?

    So I'm working on my first zabbix installation.

    One of the things I would like zabbix to monitor is it's own mysql database.


    Reading through documentation it seems pretty straightforward.

    I ensure that the HOME= parameters in the /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf match the location of my .my.cnf file. (For me I put it in /etc/zabbix, chmod 400, chown zabbix:zabbix).

    I tested the file by using the following command:

    Code:
    mysql --defaults-file=/etc/zabbix/.my.cnf
    Sure enough it connects to mysql as the zabbix user I have defined. Works great! So I restarted my zabbix agent, and I immediately see the following errors in the agent log:

    Code:
    mysqladmin: connect to server at 'localhost' failed
    error: 'Access denied for user 'root'@'localhost' (using password: NO)'
    So despite following (from what I can tell) the steps I need to get zabbix to connect to mysql for it's monitoring information, it's trying to login to the mysql database as root without entering a password. (Despite the zabbix agent running as the zabbix user)

    Help?
  • Pada
    Senior Member
    • Apr 2012
    • 236

    #2
    I just specify the credentials inline, eg.
    Code:
    mysql -u<user> -p<password> -e "<mysql query>"
    I've never specified a config file for my MySQL client before, so I cannot help you there...

    Comment

    • tchjts1
      Senior Member
      • May 2008
      • 1605

      #3
      Check this thread: https://www.zabbix.com/forum/showthread.php?t=41659

      Comment

      • James5mith
        Junior Member
        • Sep 2013
        • 7

        #4
        Originally posted by tchjts1
        Thank you for the recommendation, but I have already read through that thread and others several times before I ever even joined the forums.

        There are problems in each thread, and none of them ever come to an actual conclusion.

        1st problem: They all are directly manipulating their /etc/my.cnf file rather than using a .my.cnf file as suggested in the zabbix documentation and even within the /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf itself! So either Zabbix's internal documentation is flawed, or they are doing it incorrectly.

        2nd problem: Most of them end up using root access to the database. Which is incorrect from a security perspective. I do not want my zabbix system to have more access than needed to my other mysql servers.

        3rd problem: I can easily grant access by using root user with no password. But that is not a long term solution. I want zabbix to access database(s) as the zabbix user I specify within the configuration file.


        So I will ask again, how do I get the zabbix agent to honor/recognize the .my.cnf file placed within the HOME directory specified on the configuration (per the instructions within the config file)?

        Has anyone ever actually gotten zabbix working with a .my.cnf file?

        Have you been able to get it working tchjts1?

        Comment

        • teppo.kauppinen
          Junior Member
          • Jan 2014
          • 1

          #5
          Bit old but...

          set the HOME=/etc/zabbix

          create new file /etc/zabbix/.my.cnf

          Code:
          [client]
          user=your_database_username
          password=your_database_password
          it should work now.

          Comment

          • RexKang
            Junior Member
            • Sep 2013
            • 11

            #6
            Maybe the rights of the my.cnf.

            sudo setfacl -m user:zabbix:r-- /etc/my.cnf

            Comment

            • theWoosh
              Junior Member
              • Nov 2015
              • 20

              #7
              I wonder if the poster ever got this working? I have never yet managed to get the mysql zabbix monitoring working (or any other mysql zabbix templates including the percona ones).

              Nobody actually responded to the question in this thread...

              I have a similar situation but I don't even get the error message...

              I've spent bloody days on it! I love zabbix apart from the fact that out of the box it's virtually useless and i can never get mysql monitoring working.

              Maybe somebody could write a comprehensive guide?

              Comment

              • FrankB
                Junior Member
                • Feb 2009
                • 19

                #8
                .mylogin.cnf not found

                Hi,

                after upgrade to mysql 5.6 i had to deal with the same problem because the mysql warning about the "unsecure password on commandline" destroyed my sql-results.

                so i created a .mylogin.cnf inside /home/zabbix with mysql_config_editor

                and put HOME=/home/zabbix in front of the mysql command

                e.g:
                UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/home/zabbix mysql --login-path=mypath -A database

                this works for me

                Frank

                Comment

                • roberdaniel
                  Junior Member
                  • Apr 2019
                  • 22

                  #9
                  The problem is that user "zabbix" which runs the agent does not have defined the home directory.
                  cat /etc/passwd
                  Click image for larger version  Name:	2020-12-29_090758.png Views:	0 Size:	4.6 KB ID:	415976
                  So edit your passwd file like this
                  Click image for larger version  Name:	2020-12-29_164429.png Views:	0 Size:	984 Bytes ID:	415977
                  then go to the path /var/lib and check if this folder exist, ifnot create it
                  sudo mkdir /var/lib/zabbix
                  sudo nano /var/lib/zabbix/.my.cnf



                  [client]
                  user=your_database_username
                  password=your_database_password


                  These extra steps are not documented but in most of the systems hast to be configured.
                  I don't know why le zabbix installer did not create zabbix folder and setup correctly the home environment.
                  Maybe developers sometime improve it.
                  Last edited by roberdaniel; 29-12-2020, 21:55.

                  Comment

                  • darkfire
                    Junior Member
                    • May 2023
                    • 6

                    #10
                    @roberdaniel​ Thank you. I had the same problem.

                    Comment

                    Working...