Nagios is a mature Kaiyuan IT infrastructure monitoring system for monitoring the operating status and network information of Linux.nagios can monitor specified local or remote hosts and services,For example, http service, ftp service, etc., while providing functions such as exception notification and event processing,When a host or service fails,Nagios can also send notifications in the first time through email, mobile text messages, and other forms.Nagios can run on linux and unix platforms, and provides an optional browser-based web interface for system administrators to view the system's operating status, network status, various system problems, and log exceptions.

Environment: mysql host rhel6.4 nagios host rhel6.4

Install related packages:

 yum install httpd gcc make perl-extutils-embed.x86_64 -y
  yum localinstall gd-devel-2.0.35-11.el6.x86_64.rpm -y

Install nagios:

useradd nagios
usermod -g nagios apache
#Compile required packages
#Users running the nagios service
#Make apache user have write permission on the nagios directory,Otherwise the web page operation fails
tar jxf nagios-cn-3.2.3.tar.bz2
#nagios Software Installation
cd nagios-cn-3.2.3
./configure --enable-embedded-perl
make all //Complete the installation as prompted
make install
make install-init
make install-commandmode
make install-config
make install-webconf //This command can be quickly integrated under apache

Install nagios-plugins:

yum install mysql-devel openssl-devel -y
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-extra-opts --enable-libtap --enable-perl-modules
make install

Configure nagios:

vi /usr/local/nagios/etc/nagios.cfg
  #cfg_file =/usr/local/nagios/etc/objects/localhost.cfg #Comment out the localhost.cfg file
   cfg_file =/usr/local/nagios/etc/objects/services.cfg #Create a new services.cfg file to store service and service group definitions
   cfg_file =/usr/local/nagios/etc/objects/hosts.cfg #Create a new hosts.cfg file to store host and host group definitions

Configure hosts.cfg:

vi /usr/local/nagios/etc/objects/hosts.cfg
define host {//Host management
use linux-server //Use the default host rules
host_name vm2.example.com //host name
alias nagios vm2 //Host alias
address //Host IP address
icon_image switch.gif //icon
statusmap_image switch.gd2
2d_coords 100,200 //2d image coordinates
3d_coords 100,200,100 //3d image coordinates
define hostgroup {//management of host groups
hostgroup_name linux-servers //host group name
alias linux servers //
members * //* represents all hosts above

Configure mysql

---- Establish a special database for nagdb

mysql>create database nagdb default charset=utf8;
query ok, 1 row affected (0.01 sec)
mysql>grant select on nagdb. * to "nagios"@"%";
query ok, 0 rows affected (0.00 sec)
mysql>update mysql.user set "password"=password ("nagios") where "user"="nagios";
error 1064 (42000):you have an error in your sql syntax;check the manual that corresponds to your mysql server version for the right syntax to use near "" password "= password (" nagios ") where" user "=" nagios "" at line 1
mysql>update mysql.user set password=password ("nagios") where user="nagios";
query ok, 1 row affected (0.03 sec)
rows matched:1 changed:1 warnings:0
mysql>flush privileges;
query ok, 0 rows affected (0.00 sec)

---- Use the following command to verify it:

[[email protected] etc] #/usr/local/nagios/libexec/check_mysql -h -u nagios -d nagdb -p nagios
uptime:3374 threads:1 questions:11 slow queries:0 opens:33 flush tables:1 open tables:26 queries per second avg:0.003

Note:If it appears:/usr/local/nagios/libexec/check_mysql:error while loading shared libraries:libmysqlclient.so.18:cannot open shared object file:no such file or directory

See $mysql_home/lib

[[email protected] lib] #ln -s ./libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so.18

Configure nrpe.cfg

[[email protected] etc] #tail /usr/local/nagios/etc/nrpe.cfg
command [check_mysql] =/usr/local/nagios/libexec/check_mysql -h -u nagios -d nagdb -p nagios //Add this line

Configure nagios server

[[email protected] etc] #cat services.cfg //Add the following
define service {
    use local-service
    host_name node2
    service_description mysql
    check_command check_nrpe! check_mysql
    notifications_enabled 1

Finally restart nrpe and nagios on the server.

  • Previous Share php code to convert sqlite database file of favdb exported by 360 browser to html
  • Next Tutorial on basic creation and use of temporary tables in MySQL