• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Live Online Courses
  • Shop
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / nagios / Nagios Monitoring MySQL Servers

Nagios Monitoring MySQL Servers

October 25, 2013 by The Urban Penguin

Monitoring MySQL with Nagios Core

From what we have seen so far with Nagios, the configuration has been quite simple with none of the plugin requiring additional parameters. In this example where we monitor MySQL servers, we will need to pass through a username and password for MySQL when checking the service availability. Firstly we will create a MySQL user: We start on the MySQL user and we will log in to the database server and create a new user for Nagios to use. As added security, we will ensure that the user can only connect from the Nagios Monitoring Server.

CREATE USER 'nagios'@'192.168.0.7' IDENTIFIED BY 'password'

To be able to test the account we must move to the Nagios server as we have restricted the account to just the 192.168.0.7 host: in this case the Nagios server. To test the account from the Nagios server we could use the MySQL client alternatively we can run the plugin directly:

sudo -s -u nagios /usr/lib/nagios/plugins/check_mysql -H 192.168.0.2 -u nagios -p password

Nagios Configuration

We now will configure monitor of MySQL. The is a command already configured on my Ubuntu Nagios server. This is in the file: /etc/nagios-plugins/config/mysql.cfg

# 'check_mysql' command definition
define command{
        command_name    check_mysql
        command_line    /usr/lib/nagios/plugins/check_mysql -H '$HOSTADDRESS$'
}

# 'check_mysql_cmdlinecred' command definition
define command{
        command_name    check_mysql_cmdlinecred
        command_line    /usr/lib/nagios/plugins/check_mysql -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$'
}

# 'check_mysql_database' command definition
define command{
        command_name    check_mysql_database
        command_line    /usr/lib/nagios/plugins/check_mysql -d '$ARG3$' -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$'

We can see that there are three commands configured to use the MySQL plugin. For our example, we will use the check_mysql_cmdlinecred.

Moving into the main configuration directory on the Nagios server, /etc/nagios3/conf.d we will be working with three files

  • a new host file
  • hostgroups file
  • services file

Firstly we will edit the exiting services file: services_nagios2.cfg. We can add in a new service monitoring definition for MySQL

define service {
        hostgroup_name                  mysql-servers
        service_description             MYSQL
        check_command                   check_mysql_cmdlinecred!nagios!password
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}

Next we will create the hostgroup for MySQL, we are using a group as we are likely to have more than one MySQL server. The file we need to edit is:  hostgroups_nagios2.cfg

define hostgroup {
        hostgroup_name  mysql-servers
        alias           MySQL Servers
        members         mysql.tup.local
   }

Group membership can be defined in the group as we have done here or from the host definition. Finally we create a new definition for the MySQL host. We define this as mysql.cfg

define host {
  host_name mysql.tup.local
  alias mysql
  address 192.168.0.2
  max_check_attempts 3
  check_period 24x7
  check_command check-host-alive
  contacts root
  notification_interval 60
  notification_period 24x7
}

With the configuration in place ,we are now ready to test the setup with the pre-flight checks

nagios3 -v /etc/nagios3/nagios.cfg

And if all is correct we can restart the service. Now we can monitor MySQL from the web from end of Nagios

 

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: nagios, PHP-MySQL, Ubuntu

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Shop
    • Basket
    • Checkout
    • My Account
  • LPI Training from The Urban Penguin
    • Live and Pluralsight hosted courses
    • Complete Linux Essentials
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
    • LPIC-2 Certified Linux Engineer
    • LPIC-1 Linux Administrator
    • LPI Linux Essentials for Raspberry Pi
    • LPI Linux Essentials
  • Operating System Tutorials
    • Linux Foundation Training
    • Solaris 11 OCA 1ZO-821
    • Learning Ubuntu
    • Learning SUSE
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
  • Scripting – the power of repetition!
    • Java 7 OCA Exam 1ZO-803
    • General Java Tutorials
    • Learn C Programming using Linux and the Raspberry Pi
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • PERL Scripting in Linux
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
  • Linux Technologies
    • Learning PUPPET
    • openLDAP Directories on Linux
    • Monitoring with Nagios Core
    • Linux File-Systems
    • Learning SAMBA
    • Apache HTTPD Server
    • Learning PHP
    • MYSQL
  • OpenStack
    • Pluralsight
    • Udemy
    • Raspberry Pi Tutorials
    • Citrix Videos
  • Online Instructor-led Courses
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
    • Bash Scripting Masterclass
    • Nftables Masterclass

© 2021 The Urban Penguin · All Rights Reserved