Search code examples
mysqlremote-accessremote-servericinga2

check Mysql with remote host - Icinga2


I'm using Icinga2 to monitor Mysql server on a remote host.Now, I'm trying to configure a mysql_check.

Here is the file service.conf :

apply Service "mysql8" {  
  import "generic-service"
 check_command = "mysql"

 vars.mysql_mode = "uptime"
 vars.mysql_hostname = "remote-host"
 vars.mysql_port = "3306"
 vars.mysql_username = "username"
 vars.myql_password = "password"
 command_endpoint = host.vars.client_endpoint
 assign where host.vars.mysql == true && host.vars.client_endpoint
}

Here is the file host.conf :

object Host "remote-host" {
import "generic-host"
address = "xxx.xxx.xx.xxx"
vars.os = "linux"
vars.mysql = true
host.vars.client_endpoint="remote-host"

When I try a check_MySQLfrom Icinga2, I got the following error :

Can't connect to MySQL server on 'remote-host' (111)

What can I do to resolve the check_MySQL with the remote-host.

Thanks.


Solution

  • Nice to find you here.

    I think that your mysql server doesn't allow the remote access.

    In this case :

    1. Open a command prompt and run the following command to open the SSH tunnel.

      $ ssh [email protected] -L 3307:127.0.0.1:3306 -N NB. Replace [email protected] with your ssh username and your ssh hostname or IP adress.

    -N : forwarding port

    -L : binds a local port to the remote host port 2. Try to connect with your mysql-client

    $ mysql --protocol TCP -h localhost -u YOUR_MYSQL_USER -P 3307 -p
    

    It's work? So, :)

    1. Just replace vars.mysql_port=3307 in your icinga service configuration.

    Great! great stuff! no ?