编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

陈俊勇:教你用Nagios远程监控MySQL,用得到的戳进去

wxchong 2024-06-13 22:48:08 开源技术 21 ℃ 0 评论

被监控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 上去做配置

增加两行配置

增加

写hosts配置文件

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

define host{

use linux-server

host_name juny-18

address 192.168.1.18

}

写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

}

增加配置文件

[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

}

手动测试

[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]#

看到上面的信息,说明连接没有问题

网页测试

可以看到MySQL服务被成功的监控到

我们的nagios库也被检测到了

测试下 、在MySQL主机把MySQL停止

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

[root@juny-18 ~]#

可以看到马上就检测到了

开启试试、是不是被监控到的

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

下节介绍nagios监控web服务

评论

有什么不懂或者疑问的地方请关注留言,评论

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表