Ad Widget

Collapse

Zabbix Agent can't connect to local MySQL server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaveyKL
    Junior Member
    • Oct 2013
    • 2

    #1

    Zabbix Agent can't connect to local MySQL server

    Hello, We are trying to get Zabbix and MySQL monitoring working, but we ran into some problems. It did the following steps:

    1. Created a template
    2. Created a item in zabbix and added a key like mysql.uptime
    3. Added a include in the agent like this:
    Code:
    Include=/etc/zabbix/zabbix_agentd.userparams.conf
    4. Added in zabbix_agentd.userparams.conf te following lines:
    Code:
    UserParameter=mysql.uptime,mysqladmin -u zabbix --password=(Password) status | cut -f2 -d ":" | cut -f1 -d "T" | tr -d " "
    5. Added in $HOME/.my.cnf the following lines:
    Code:
    [client]
    user                           = zabbix
    password                       = (Password)
    port                           = 3306
    6. Added a graph based on the item.

    But I get the following error in /var/log/zabbix:
    Code:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/srv/mysql/data/mysql.sock' (13)
    This usually means that the mysql server can not be connect. But if I login on the MySQL and try to login like this: mysql -uzabbix -p(Password) I can connect to the MySQL server succesfully.

    Also if I run this command in the command line I get a valid response.
    Code:
    mysqladmin -u zabbix --password=(Password) status | cut -f2 -d ":" | cut -f1 -d "T" | tr -d " "
    Reponse:
    Code:
    5052
    Did I miss something? Thank you in advance.
  • jan.garaj
    Senior Member
    Zabbix Certified Specialist
    • Jan 2010
    • 506

    #2
    IMHO: you mix 2 DB connections:
    1.) Zabbix agent (maybe server)
    You can see in your zabbix log:
    Code:
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/srv/mysql/data/mysql.sock' (13)
    So check DB setting of your agent or server. It looks that you didn't configure DB.

    2.) UserParameter MySQL connection
    When you solve 1.), then I hope, that also your UserParameter items will be collected by Zabbix without problem
    Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
    My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

    Comment

    • DaveyKL
      Junior Member
      • Oct 2013
      • 2

      #3
      I resolved my problem. The zabbix local user (what the Zabbix Agent use) couldn't get access to /srv/mysql/data/ because of the permissions. You can fix this to set the right permission to this folder.

      Comment

      Working...