陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

被監控MySQL主機

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

在需要監控的MySQL服務器上新建一個nagios庫、並授權給192.168.1.10來登錄

[root@juny-18 ~]# mysql -uroot -pwoDEmiMA01!

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database nagios; #創建nagios數據庫

Query OK, 1 row affected (0.05 sec)

mysql> grant select on nagios.* to nagios@'192.168.1.10' identified by 'Nagios01!'; #創建授權並設置密碼

Query OK, 0 rows affected, 1 warning (0.07 sec)

mysql>

mysql> flush privileges; #刷新權限表

Query OK, 0 rows affected (0.06 sec)

nagios監控主機

回到192.168.1.10 上去做配置

增加兩行配置

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

增加

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

寫hosts配置文件

[root@juny-10 nagios]# vim etc/objects/hosts.cfg

define host{

use linux-server

host_name juny-18

address 192.168.1.18

}

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

寫service.cfg 配置文件

[root@juny-10 nagios]# vim etc/objects/service.cfg

define service{

use local-service

host_name juny-18

service_description MySqlSev

check_command check_mysql

}

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

增加配置文件

[root@juny-10 nagios]# vim etc/objects/commands.cfg

define command{

command_name check_mysql

command_line $USER1$/check_mysql -H $HOSTADDRESS$ -unagios -pNagios01! -d nagios

}

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

手動測試

[root@juny-10 nagios]# cd libexec/

[root@juny-10 libexec]# ./check_mysql -H 192.168.1.18 -unagios -pNagios01! -d nagios

Uptime: 3996 Threads: 1 Questions: 11 Slow queries: 0 Opens: 114 Flush tables: 1 Open tables: 107 Queries per second avg: 0.002|Connections=6c;;; Open_files=22;;; Open_tables=108;;; Qcache_free_memory=1031832;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=2c;;; Qcache_queries_in_cache=0;;; Queries=12c;;; Questions=9c;;; Table_locks_waited=0c;;; Threads_connected=1;;; Threads_running=1;;; Uptime=3996c;;;

[root@juny-10 libexec]#

看到上面的信息,說明連接沒有問題

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

網頁測試

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

可以看到MySQL服務被成功的監控到

我們的nagios庫也被檢測到了

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

測試下 、在MySQL主機把MySQL停止

[root@juny-18 ~]# systemctl stop mysqld.service

[root@juny-18 ~]#

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

可以看到馬上就檢測到了

開啟試試、是不是被監控到的

[root@juny-18 ~]# systemctl start mysqld.service

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

下節介紹nagios監控web服務

評論

有什麼不懂或者疑問的地方請關注留言,評論

陳俊勇:教你用Nagios遠程監控MySQL,用得到的戳進去

相關推薦

推薦中...