最新文章專(zhuān)題視頻專(zhuān)題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專(zhuān)題1關(guān)鍵字專(zhuān)題50關(guān)鍵字專(zhuān)題500關(guān)鍵字專(zhuān)題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專(zhuān)題關(guān)鍵字專(zhuān)題tag2tag3文章專(zhuān)題文章專(zhuān)題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專(zhuān)題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-09 19:51:12
文檔

Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL

Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL:1、NRPE介紹 NRPE是Nagios的一個(gè)功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過(guò)在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來(lái)向Nagios監(jiān)控平臺(tái)提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤(pán)使用等。這里將Nagios監(jiān)控端稱(chēng)為Nagio
推薦度:
導(dǎo)讀Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL:1、NRPE介紹 NRPE是Nagios的一個(gè)功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過(guò)在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來(lái)向Nagios監(jiān)控平臺(tái)提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤(pán)使用等。這里將Nagios監(jiān)控端稱(chēng)為Nagio

1、NRPE介紹

NRPE是Nagios的一個(gè)功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過(guò)在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來(lái)向Nagios監(jiān)控平臺(tái)提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤(pán)使用等。這里將Nagios監(jiān)控端稱(chēng)為Nagios服務(wù)器端,而將遠(yuǎn)程被監(jiān)控的主機(jī)稱(chēng)為Nagios客戶端。

Nagios監(jiān)控遠(yuǎn)程主機(jī)的方法有多種,其方式包括SNMP,NRPE,SSH,NCSA等。這里介紹其通過(guò)NRPE監(jiān)控遠(yuǎn)程Linux主機(jī)的方式。

NRPE(Nagios Remote Plugin Executor)是用于在遠(yuǎn)端服務(wù)器上運(yùn)行監(jiān)測(cè)命令的守護(hù)進(jìn)程,它用于讓Nagios監(jiān)控端基于安裝的方式觸發(fā)遠(yuǎn)端主機(jī)上的檢測(cè)命令,并將檢測(cè)結(jié)果返回給監(jiān)控端。而其執(zhí)行的開(kāi)銷(xiāo)遠(yuǎn)低于基于SSH的檢測(cè)方式,而且檢測(cè)過(guò)程不需要遠(yuǎn)程主機(jī)上的系統(tǒng)賬號(hào)信息,其安全性也高于SSH的檢測(cè)方式。

2、NRPE的工作原理

NRPE有兩部分組成

check_nrpe插件:位于監(jiān)控主機(jī)上

nrpe daemon:運(yùn)行在遠(yuǎn)程主機(jī)上,通常是被監(jiān)控端agent

注意:nrpe daemon需要Nagios-plugins插件的支持,否則daemon不能做任何監(jiān)控

當(dāng)Nagios需要監(jiān)控某個(gè)遠(yuǎn)程Linux主機(jī)的服務(wù)或者資源情況時(shí):

首先:Nagios會(huì)運(yùn)行check_nrpe這個(gè)插件,告訴它要檢查什么;

其次:check_nrpe插件會(huì)連接到遠(yuǎn)程的NRPE daemon,所用的方式是SSL;

然后:NRPE daemon 會(huì)運(yùn)行相應(yīng)的Nagios插件來(lái)執(zhí)行檢查;

最后:NRPE daemon 將檢查的結(jié)果返回給check_nrpe 插件,插件將其遞交給nagios做處理。

<版權(quán)所有,文章允許轉(zhuǎn)載,但必須以鏈接方式注明源地址,否則追究法律責(zé)任!>
原博客地址: http://blog.csdn.net/mchdba/article/details/46666229
原作者:黃杉 (mchdba)

3、被監(jiān)控端安裝Nagios-plugins插件和NRPE

去mysql客戶端安裝nrpe客戶端服務(wù)

3.1、添加nagios用戶

[root@localhost ~]# useradd -s/sbin/nologin nagios

3.2,安裝nagios插件

[root@localhost ~]# yum -yinstall gcc gcc-c++ make openssl openssl-devel

3.3,安裝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,去檢查nrpe配置

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/mysql.sock -Hlocalhost--password='nagiosq@0625' -d test -w 60 -c 100

[root@localhost ~]#

3.5,啟動(dòng)nrpe

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

4,制作啟動(dòng)腳本:

[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,設(shè)置啟動(dòng)

chmod +x /etc/init.d/nrped

chkconfig --add nrped

chkconfig nrped on

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

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

root 30442 3292 0 23:48 pts/0 00:00:00 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,監(jiān)控端安裝nrpe

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

#安裝完成后,會(huì)在Nagios安裝目錄的libexec下生成check_nrpe的插件,如下所示:

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

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

[root@test_db2 nagios]#

檢測(cè)報(bào)錯(cuò):

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

CHECK_NRPE: Error - Could not complete SSLhandshake.

[root@test_db2 libexec]#

去客戶端在allowed_hosts中添加監(jiān)控端IP地址

[root@localhost ~]# vim/usr/local/nagios/etc/nrpe.cfg

allowed_hosts=127.0.0.1,192.168.121.211

在mysql服務(wù)器上,報(bào)錯(cuò):

[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306 -S -s/usr/local/mysql/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 sharedobject 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 ~]#

添加mysql賬號(hào):

mysql> GRANT PROCESS, SUPER, REPLICATIONCLIENT ON *.* TO 'nagios'@'localhost' IDENTIFIED BY 'nagiosq@0625';

Query OK, 0 rows affected (0.05 sec)

mysql>

客戶端自己檢測(cè):

[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306 -s /usr/local/mysql/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=3116c;;; Open_files=19;;; Open_tables=116;;; Qcache_free_memory=61538880;;;Qcache_hits=176271c;;; Qcache_inserts=41370c;;; Qcache_lowmem_prunes=0c;;;Qcache_not_cached=331835c;;; Qcache_queries_in_cache=3373;;; Queries=684496c;;;Questions=681384c;;; Table_locks_waited=0c;;; Threads_connected=5;;;Threads_running=2;;; Uptime=1823238c;;;

[root@localhost ~]#

7,完善配置文件

7.1在command.cfg里面添加監(jiān)控command命令

將servers.cfg添加進(jìn)nagios.cfg里面,將command.cfg里面的check_host_alive以及check_mysql_status補(bǔ)充好,然后重啟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在servers.cfg里面添加check_mysql_status、 check_host_alive等服務(wù)監(jiān)控項(xiàng)。

[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

notification_interval 10

notification_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

notification_interval 10

notification_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

notification_interval 10

notification_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

notification_interval 10

notification_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

notification_interval 10

notification_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

notification_interval 10

notification_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

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups dba

}

7.3 在nagios.cfg加載servers.cfg等配置文件

在nagios.cfg里面配置

cfg_file=/usr/local/nagios/etc/servers.cfg

同時(shí)添加新的主機(jī)或者服務(wù)配置cfg文件,都需要在nagios.cfg里面配置一下,然后重啟nagios才能生效,如下所示:

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

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/contactgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/hosts.cfg

cfg_file=/usr/local/nagios/etc/servers.cfg

cfg_file=/usr/local/nagios/etc/hostgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

[root@test_db2 nagios]#

8,之后在頁(yè)面就可以看到監(jiān)控效果了

\

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL

Nagios監(jiān)控mysql服務(wù)器詳細(xì)實(shí)現(xiàn)過(guò)程_MySQL:1、NRPE介紹 NRPE是Nagios的一個(gè)功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過(guò)在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來(lái)向Nagios監(jiān)控平臺(tái)提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤(pán)使用等。這里將Nagios監(jiān)控端稱(chēng)為Nagio
推薦度:
  • 熱門(mén)焦點(diǎn)

最新推薦

猜你喜歡

熱門(mén)推薦

專(zhuān)題
Top