Detailed implementation of Nagios monitoring mysql server _ MySQL

Source: Internet
Author: User
1. NRPE introduction NRPE is a function extension of Nagios. it can execute plug-in programs on a remote LinuxUnix host. By installing the NRPE plug-in and Nagios plug-in on a remote server, you can provide the Nagios monitoring platform with local information about the server, such as CPU load and memory usage, 1. Introduction to NRPE

NRPE is a function extension of Nagios. it can execute plug-in programs on a remote Linux/Unix host. By installing the NRPE plug-in and Nagios plug-in on a remote server, you can provide the Nagios monitoring platform with local information about the server, such as CPU load, memory usage, and disk usage. Here, the Nagios monitoring side is called the Nagios server, and the remote monitored host is called the Nagios client.

Nagios provides multiple methods to monitor remote hosts, including SNMP, NRPE, SSH, and NCSA. This section describes how to use NRPE to monitor remote Linux hosts.

NRPE (Nagios Remote Plugin Executor) is a daemon process used to run monitoring commands on a Remote server. it is used to enable the Nagios monitoring terminal to trigger detection commands on the Remote host based on the installation method, and return the detection result to the monitoring end. The overhead of its execution is much lower than the SSH-based detection method, and the detection process does not require the system account information on the remote host, and its security is higher than the SSH detection method.

2. how NRPE works

NRPE consists of two parts:

Check_nrpe plug-in: Located on the monitoring host

Nrpe daemon: runs on a remote host, usually the monitored agent.

Note: nrpe daemon requires support from the Nagios-plugins plug-in. otherwise, daemon cannot perform any monitoring.

When Nagios needs to monitor the services or resources of a remote Linux host:

First, Nagios runs the check_nrpe plug-in to tell it what to check;

Second, the check_nrpe plug-in will connect to the remote NRPE daemon, using SSL;

Then, NRPE daemon runs the corresponding Nagios plug-in to perform the check;

Finally, NRPE daemon returns the check result to the check_nrpe plug-in, which submits it to nagios for processing.

<版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!>
Original blog address: http://blog.csdn.net/mchdba/article/details/46666229
Original Author: Huang Shan (mchdba)

3. install the Nagios-plugins and NRPE on the monitored side.

Go to the mysql client to install the nrpe Client Service

3.1 add a nagios user

[Root @ localhost ~] # Useradd-s/sbin/nologin nagios

3.2 install the nagios plug-in

[Root @ localhost ~] # Yum-yinstall gcc-c ++ make openssl-devel

3.3. install nrpe

Tar-xvf nrpe-2.15.tar.gz

Cd nrpe-2.15

. /Configure -- with-nrpe-user = nagios -- with-nrpe-group = nagios -- with-nagios-user = nagios -- with-nagios-group = nagios -- enable-command-args -- enable-ssl

Make all

Make install-plugin

Make install-daemon

Make install-daemon-config

3.4. check the nrpe configuration.

Grep-v '^ #'/usr/local/nagios/etc/nrpe. cfg | sed '/^ $/D'

[Root @ localhost ~] # Grep-v '^ #'/usr/local/nagios/etc/nrpe. cfg | sed '/^ $/D'

Log_facility = daemon

Pid_file =/var/run/nrpe. pid

Server_port = 5666

Nrpe_user = nagios

Nrpe_group = nagios

Allowed_hosts = 127.0.0.1, 192.168.121.211

Dont_blame_nrpe = 0

Allow_bash_command_substitution = 0

Debug = 0

Command_timeout = 60

Connection_timeout = 300

Command [check_users] =/usr/local/nagios/libexec/check_users-w 8-c 12

Command [check_load] =/usr/local/nagios/libexec/check_load-w15, 10, 5-c 30, 25, 20

Command [check_sda1] =/usr/local/nagios/libexec/check_disk-w20 %-c 10%-p/dev/sda3

Command [check_zombie_procs] =/usr/local/nagios/libexec/check_procs-w 5-c 10-s Z

Command [check_total_procs] =/usr/local/nagios/libexec/check_procs-w 750-c 800

Command [check-host-alive] =/usr/local/nagios/libexec/check_ping-H 10.254.3.72-w 3000.0, 80%-c 5000.0, 100%-p 5

Command [check_mysql_status] =/usr/local/nagios/libexec/check_mysql-unagios-P3306-s/usr/local/mysql. sock-Hlocalhost -- password = 'nagiosq @ 0625 '-d test-w 60-c 100

[Root @ localhost ~] #

3.5. start nrpe

/Usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe

4. create a startup script:

[Root @ localhost bin] # cat/etc/init. d/nrped

# Chkconfig: 2345 80 90

# Description: auto_run

NRPE =/usr/local/nagios/bin/nrpe

NRPECONF =/usr/local/nagios/etc/nrpe. cfg

Case "$1" in

Start)

Echo-n "Starting NRPE daemon ..."

$ NRPE-c $ NRPECONF-d

Echo "done ."

;;

Stop)

Echo-n "Stopping NRPE daemon ..."

Pkill-u nagios nrpe

Echo "done ."

;;

Restart)

$0 stop

Sleep 2

$0 start

;;

*)

Echo "Usage: $0 start | stop | restart"

;;

Esac

Exit 0

[Root @ localhost bin] #

5. set startup

Chmod + x/etc/init. d/nrped

Chkconfig -- add nrped

Chkconfig nrped on

[Root @ localhost bin] # ps-eaf | grep nrpe

Nagios 30440 1 0? 00:00:00/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe. cfg-d

Root 30442 3292 0 00:00:00 pts/0 grep nrpe

[Root @ localhost bin] #

[Root @ localhost bin] # netstat-tnlp | grepnrpe

Tcp 0 0 0.0.0.0: 5666 0.0.0.0: * LISTEN 30440/nrpe

Tcp 0 0: 5666: * LISTEN 30440/nrpe

[Root @ localhost bin] #

6. install nrpe on the monitoring terminal

Tar xf nrpe-2.15.tar.gz

Cd nrpe-2.15

. /Configure -- with-nrpe-user = nagios -- with-nrpe-group = nagios -- with-nagios-user = nagios -- with-nagios-group = nagios -- enable-command-args -- enable-ssl

Make all

Make install-plugin

# After the installation is complete, the check_nrpe plug-in will be generated under libexec in The Nagios installation directory, as shown below:

[Root @ test_db2 nagios] # ll/usr/local/nagios/libexec/check_nrpe

-Rwxrwxr-x 1 nagios 76777 Jun 2523: 53/usr/local/nagios/libexec/check_nrpe

[Root @ test_db2 nagios] #

Detection error:

[Root @ test_db2 libexec] #./check_nrpe-H192.168.121.210

CHECK_NRPE: Error-cocould not complete SSLhandshake.

[Root @ test_db2 libexec] #

Add the monitoring IP address in allowed_hosts from the client

[Root @ localhost ~] # Vim/usr/local/nagios/etc/nrpe. cfg

Allowed_hosts = 127.0.0.1, 192.168.121.211

On the mysql server, the following error occurs:

[Root @ localhost ~] #/Usr/local/nagios/libexec/check_mysql-unagios-P3306-S-s/usr/local/mysql. sock-Hlocalhost -- password = 'nagiosq @ 0512 '-d test-w 60-c 100

/Usr/local/nagios/libexec/check_mysql: error while loading shared libraries: libmysqlclient. so.18: cannot open your dobject file: No such file or directory

[Root @ localhost ~] #

[Root @ localhost ~] # Find/-namelibmysqlclient. so.18

/Usr/local/mysql/lib/libmysqlclient. so.18

/Root/mysql/mysql-5.6.12/libmysql/libmysqlclient. so.18

/Root/mysql-5.6.12/libmysql/libmysqlclient. so.18

[Root @ localhost ~] # Ln-s/usr/local/mysql/lib/libmysqlclient. so.18/usr/lib64/libmysqlclient. so.18

[Root @ localhost ~] #

Add a mysql account:

Mysql> grant process, SUPER, replicationclient on *. * TO 'nagios '@ 'localhost' identified by 'nagiosq @ 8080 ';

Query OK, 0 rows affected (0.05 sec)

Mysql>

Client self-detection:

[Root @ localhost ~] #/Usr/local/nagios/libexec/check_mysql-unagios-P3306-s/usr/local/mysql. sock-Hlocalhost -- password = 'nagiosq @ 0625 '-d test-w 60-c 100

Uptime: 1823238 Threads: 6 Questions: 684495 Slow queries: 0 Opens: 124 Flush tables: 1 Open tables: 116 Queries per second avg: 0.375 | Connections = 3366c ;;; open_files = 19; Open_tables = 116; Qcache_free_memory = 61538880; Qcache_hits = 176271c; Qcache_inserts = 41370c; cost = 0c ;;; qcache_not_cached = 331835c; Queries = 3373; Queries = 684496c; Questions = 681384c; Table_locks_waited = 0c; Threads_connected = 5 ;;; threads_running = 2; Uptime = 1823238c ;;;

[Root @ localhost ~] #

7. Complete configuration file 7.1 and add the monitoring command in command. cfg.

Add servers. cfg to nagios. cfg, add check_host_alive and check_mysql_status in command. cfg, and restart nagios.

# Add by timman on 20150512

Define command {

Command_name check_mysql_status

Command_line $ USER1 $/check_mysql_status-w $ ARG1 $-c $ ARG2 $

}

# 'Check _ nrpe 'command definition, add bytimman on 20140508

Define command {

Command_name check_nrpe

Command_line $ USER1 $/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $

}

Define command {

Command_name check_host_alive

Command_line $ USER1 $/check_ping-H $ HOSTADDRESS $-w 3000.0, 80%-c 5000.0, 100%-p 5

}

7.2 add service metrics such as check_mysql_status and check_host_alive to servers. cfg.

[Root @ test_db2 etc] # more servers. cfg

# Servicedefinition

Define service {

Host_name cactitest

Service_description check_load

Check_command check_nrpe! Check_load

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description check_host_alive

Check_command check_host_alive

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description Check Disksda1

Check_command check_nrpe! Check_sda1

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description TotalProcesses

Check_command check_nrpe! Check_total_procs

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description CurrentUsers

Check_command check_nrpe! Check_users

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description CheckZombie Procs

Check_command check_nrpe! Check_zombie_procs

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

Define service {

Host_name cactitest

Service_description CheckMysql Status

Check_command check_nrpe! Check_mysql_status

Max_check_attempts 5

Normal_check_interval 3

Retry_check_interval 2

Check_period 24x7

Icationication_interval 10

Icationication_period 24x7

Notification_options w, u, c, r

Contact_groups dba

}

7.3 load configuration files such as servers. cfg in nagios. cfg

Configure in nagios. cfg

Export _file =/usr/local/nagios/etc/servers. cfg

To add a new host or service configuration cfg file, you must configure it in nagios. cfg and restart nagios to make the configuration take effect, as shown below:

[Root @ test_db2 nagios] # grep-v '^ #'/usr/local/nagios/etc/nagios. cfg | sed '/^ $/d' | grep pai_file

Export _file =/usr/local/nagios/etc/objects/commands. cfg

Export _file =/usr/local/nagios/etc/objects/contacts. cfg

Export _file =/usr/local/nagios/etc/contactgroups. cfg

Export _file =/usr/local/nagios/etc/objects/timeperiods. cfg

Export _file =/usr/local/nagios/etc/objects/templates. cfg

Export _file =/usr/local/nagios/etc/hosts. cfg

Export _file =/usr/local/nagios/etc/servers. cfg

Export _file =/usr/local/nagios/etc/hostgroups. cfg

Export _file =/usr/local/nagios/etc/objects/localhost. cfg

[Root @ test_db2 nagios] #

8. then you can see the monitoring effect on the page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.