How to configuring Nagios to monitor your MySQL server. Before we begin, there are a few prerequisites that you have to fulfill
Prerequisites
- Operating System - CentOS.
- Nagios Core - Installed and configured.
- Nagios Plugins should be installed.
- MySQL server(or MariaDB) should be installed on your server.
- Log in to your MySQL server with the following command.
- Type in the following commands.
# mysql -u root -p |
mysql>
CREATE USER 'nagios'@'localhost' IDENTIFIED BY 'nagiospasswd'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'nagios'@'localhost'; mysql> CREATE USER 'nagios'@'%' IDENTIFIED BY 'nagiospasswd'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'nagios'@'%'; mysql> flush privileges; |
These commands create a user "nagios" that can be used by local host as well as remotely. We have also granted all privileges to the user.
Install of the perl-modules DBI and DBD::mysql
Log in to nagios server use the following command to install perl-modules DBI and DBD::mysql
# yum -y
install perl-DBI # yum -y install "perl(DBD::mysql)" |
MySQL Plugin Installation
- Run the following command to download the "check_mysql_health-2.2.2.tar.gz" package.
- Extract the downloaded package.
- Change into the check_mysql_health-2.2.2 directory.
- Run the following commands to configure and install the plugin.
# wget https://labs.consol.de/assets/downloads/nagios/check_mysql_health-2.2.2.tar.gz |
# tar -zxvf check_mysql_health-2.2.2.tar.gz |
# cd check_mysql_health-2.2.2 |
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
--with-nagios-group=nagios --with-perl=/usr/bin/perl # make # make install |
Nagios Configuration for MySQL Monitoring
- "check_mysql_health" Command Definition
- "check_mysql_health" Service Definition
- Restart the Nagios server.
The following file contains all the commands pertaining to Nagios. Open it in any text editor of your choice("vi" in this case).
# vi /usr/local/nagios/etc/objects/commands.cfg |
Edit the file and add the "check_mysql_health" command block.
define
command{ command_name check_mysql_health command_line $USER1$/check_mysql_health -H $ARG1$ --username $ARG2$ --password $ARG3$ --port $ARG4$ --mode $ARG5$ } |
Open the file "hosttomonitor.cfg" to add the service definition to the host that will be monitored.
# vi /usr/local/nagios/etc/servers/hosttomonitor.cfg |
Add the following service blocks of Connection-time, io thread and sql thread. This will perform different tasks.
define service{ use local-service host_name hosttomonitor service_description MySQL connection-time check_command check_mysql_health!192.168.30.10!nagios!nagiospasswd!3306!connection-time! } define service{ use local-service host_name hosttomonitor service_description MySQL slave-io-running check_command check_mysql_health!192.168.30.10!nagios!nagiospasswd!3306!slave-io-running! } define service{ use local-service host_name hosttomonitor service_description MySQL slave-sql-running check_command check_mysql_health!192.168.30.10!nagios!nagiospasswd!3306!slave-sql-running! } |
# service nagios restart |
https://labs.consol.de/nagios/check_mysql_health/index.html
Tidak ada komentar:
Posting Komentar