实战Nagios网络监控(1)——监控本机运行状态和Mysq主机

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

    Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等。

    Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等


实验环境:

物理主机 redhat7.0 内核版本 3.10.0-123.el7.x86_64

虚拟机 redhat6.5 内核版本 2.6.32-431.el6.x86_64

服务器端: server1.example.com 172.25.254.1

所需软件包:

gd-devel-2.0.35-11.el6.x86_64.rpm

nagios-cn-3.2.3.tar.bz2

nagios-plugins-2.1.1.tar.gz


1.编译nagios

   (1).准备安装

        [root@server1 mnt]# tar jxf nagios-cn-3.2.3.tar.bz2 

        [root@server1 mnt]# mv nagios-cn-3.2.3  /root/

        [root@server1 mnt]# yum install gd-devel-2.0.35-11.el6.x86_64.rpm   gcc   -y                                            ##为./configure做准备       

    (2).编译安装

        [root@server1 mnt]# cd /root/nagios-cn-3.2.3/

        [root@server1 nagios-cn-3.2.3]# ./configure    

        [root@server1 nagios-cn-3.2.3]# useradd -u 900 -M -d /usr/local/nagios nagios

        [root@server1 nagios-cn-3.2.3]# make all

        [root@server1 nagios-cn-3.2.3]# make 

        [root@server1 nagios-cn-3.2.3]# make install-init

            *** Init script installed ***

        [root@server1 nagios-cn-3.2.3]# make install-commandmode            

            *** External command directory configured ***

        [root@server1 nagios-cn-3.2.3]# make install-config           

            *** Config files installed ***            

        [root@server1 nagios-cn-3.2.3]# make install-webconf

            *** Nagios/Apache conf file installed ***

    (3).修改登陆用户密码

        [root@server1 nagios-cn-3.2.3]#  cat /usr/local/nagios/etc/htpasswd.users  ##查看密码

        nagiosadmin:gCWSDnqEHR45c

        [root@server1 nagios-cn-3.2.3]# htpasswd /usr/local/nagios/etc/htpasswd.users nagiosadmin

        New password:                         ##更改密码

        Re-type new password: 

        Updating password for user nagiosadmin

    (4)启动服务

         [root@server1 nagios-cn-3.2.3]# /etc/init.d/httpd start

        Starting httpd:                                            [  OK  ]

        [root@server1 nagios-cn-3.2.3]# /etc/init.d/nagios start

        Starting nagios: done.

    (5)浏览器访问:172.25.254.6/nagios,用户为nagiosadmin,密码为自己刚改的密码。

wKioL1gQos2SrMi_AADLWm2btcA535.png

wKiom1gQos7z8Z6cAAKtC_IrFp4592.png

wKioL1gQo07R8mdwAAPKyHTXoRc185.png


2.排除故障

    可以看到刚安装的nagios不能监控到主机的状态,需要安装插件排除故障

    (1)[root@server1 0722-监控-nagios]# cd /mnt/

        [root@server1 mnt]# tar -zxf nagios-plugins-2.1.1.tar.gz 

        [root@server1 mnt]# mv nagios-plugins-2.1.1  /root/

        [root@server1 mnt]# cd /root/nagios-plugins-2.1.1/

    (2)编译插件           

        [root@server1 nagios-plugins-2.1.1]# yum install mysql-devel openssl-devel -y     #编译所需软件包                                                                     

        [root@server1 nagios-plugins-2.1.1]# ./configure 

*****************************************************************************************

config.status: creating po/Makefile

            --with-apt-get-command: 

              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s

               --with-ping-command: /bin/ping -n -U -w %d -c %d %s

                       --with-ipv6: yes

                      --with-mysql: /usr/bin/mysql_config ##不能为no,如果为no,则 yum install mysql-devel -y

                    --with-openssl: yes ##不能为no,如果为no,则 yum install openssh-devel -y

                     --with-gnutls: no

               --enable-extra-opts: yes

                       --with-perl: /usr/bin/perl

             --enable-perl-modules: no

                     --with-cgiurl: /nagios/cgi-bin

               --with-trusted-path: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

                   --enable-libtap: no

*****************************************************************************************

<2>make

<3>make install

(3)cd /usr/local/nagios/libexec/

<1>ll

<2>chown nagios.nagios * ##更改所有文件的所属用户和所属组为nagios

<3>id apache

   usermod -G nagios apache

       id apache

*********************************************

[root@server6 libexec]# id apache

uid=48(apache) gid=48(apache) groups=48(apache),900(nagios)

*********************************************

    (3).编辑配置文件

    (3.1)

        [root@server1 nagios-plugins-2.1.1]# vim /usr/local/nagios/etc/nagios.cfg 

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

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

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

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

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

          35 cfg_file=/usr/local/nagios/etc/objects/services.cfg

          36 

          37 # Definitions for monitoring the local (Linux) host

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

    (3.2)

        [root@server1 nagios-plugins-2.1.1]# cd /usr/local/nagios/etc/objects/

        [root@server1 objects]# cp -p localhost.cfg hosts.conf

        [root@server1 objects]# cp -p localhost.cfg services.cfg

        [root@server1 objects]# cp -p localhost.cfg hosts.cfg

    (3.3)

        [root@server1 objects]# vim hosts.cfg 

###############################################################################

# Define a host for the local machine


define host{

        use                     linux-server            ; 给网络设备用的

        host_name               监控主机

        alias                   MainSwitch

        address                 127.0.0.1

        icon_image              switch.gif

        statusmap_image         switch.gd2

        2d_coords               100,200

        3d_coords               100,200,100

        }

###############################################################################

#

# HOST GROUP DEFINITION

#

###############################################################################

###############################################################################


# Define an optional hostgroup for Linux machines


define hostgroup{

        hostgroup_name  linux-servers ; The name of the hostgroup

        alias           Linux Servers ; Long name of the group

        members         *     ; Comma separated list of hosts that belong to this group

        }

###############################################################################

    (3.4)[root@server1 objects]# vim services.cfg 

define servicegroup{

        servicegroup_name 系统状态检查

        alias 系统概况

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       *

        service_description             PING

        check_command                   check_ping!100.0,20%!500.0,60%

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             根分区

        check_command                   check_local_disk!20%!10%!/

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             登录用户数

        check_command                   check_local_users!20!50

        }


# Define a service to check the number of currently running procs

# on the local machine.  Warning if > 250 processes, critical if

# > 400 users.


define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             进程总数

        check_command                   check_local_procs!250!400!RSZDT

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             系统负荷

        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             交换空间利用率

        check_command                   check_local_swap!20!10

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             SSH

        check_command                   check_tcp!22!1.0!10.0

        notifications_enabled           0

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       监控主机

        service_description             HTTP

        check_command                   check_http

        notifications_enabled           0

        }


    (3.5)[root@server1 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

            ##检测有无错误          

            Total Warnings: 0

            Total Errors:   0

            Things look okay - No serious problems were detected during the pre-flight check

    (3.6)

            [root@server1 objects]# /etc/init.d/nagios reload

            Running configuration check...done.

            Reloading nagios configuration...done


   浏览器刷新浏览:172.25.254.1/nagios

wKiom1gQqXCDv-GvAAJLyINKN2g551.png

3.加个mysql服务

    [root@server1 ~]# yum install mysql-server -y

    [root@server1 ~]# /etc/init.d/mysqld restart

    [root@server1 ~]# mysql

> show databases;

> grant select on test.* to nagios@localhost identified by 'redaht';

    [root@server1 ~]# cd /usr/local/nagios/libexec

    [root@server1 libexec]# ./check_mysql -H localhost  -u nagios -p westos

Uptime: 12566  Threads: 10  Questions: 207453  Slow queries: 0  Opens: 130  Flush tables: 1  Open tables: 42  Queries per second avg: 16.509|Connections=421c;;; Open_files=80;;; Open_tables=42;;; Qcache_free_memory=0;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=0c;;; Qcache_queries_in_cache=0;;; Queries=207453c;;; Questions=207453c;;; Table_locks_waited=5c;;; Threads_connected=10;;; Threads_running=1;;; Uptime=12566c;;;


*********************************************************************************

    [root@server1 libexec]cd /usr/local/nagios/etc/objects

    [root@server1 objects] vim command.cfg

*********************************************************************************

212 # 'check_mysql' command definition

213 define command{

214         command_name    check_mysql

215         command_line    USER1/check_mysql -H HOSTADDRESS -u ARG1 -p ARG2

216        }

*********************************************************************************

    [root@server1 objects] vim hosts.cfg

*********************************************************************************

14 # Define a host for the mysql on server4.example.com

  15 define host{

  16         use                     linux-server

  17         host_name               server4.example.com

  18         alias                   mysql

  19 #       parents                 MainSwitch

  20         address               127.0.0.1

  21         icon_image              server.gif

  22         statusmap_image         server.gd2

  23         2d_coords               400,100 ##2D坐标位置

  24         3d_coords               400,200,100 ##3D坐标位置

  25         }

*********************************************************************************

    [root@server1 objects] vim services.cfg

*********************************************************************************

109 ################check_mysql##########################

110 define service{

111         use                             local-service         ; Name of service template to use

112         host_name                       server4.example.com

113         service_description             mysql

114         check_command                   check_mysql!nagios!westos

115         notifications_enabled           0

116         }

*********************************************************************************

    [root@server1 objects/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检查

(4)浏览器刷新浏览:172.25.254.1/nagios

wKiom1gQq5CRGoDqAAFE7aGyfDA940.png

    可以看到多了一个Mysql监控


本文转自willis_sun 51CTO博客,原文链接:http://blog.51cto.com/willis/1866079,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
69
分享
相关文章
解读 C++ 助力的局域网监控电脑网络连接算法
本文探讨了使用C++语言实现局域网监控电脑中网络连接监控的算法。通过将局域网的拓扑结构建模为图(Graph)数据结构,每台电脑作为顶点,网络连接作为边,可高效管理与监控动态变化的网络连接。文章展示了基于深度优先搜索(DFS)的连通性检测算法,用于判断两节点间是否存在路径,助力故障排查与流量优化。C++的高效性能结合图算法,为保障网络秩序与信息安全提供了坚实基础,未来可进一步优化以应对无线网络等新挑战。
HarmonyOS NEXT 实战系列10-网络通信
本文介绍了网络通信相关知识,包括HTTP协议的工作原理、鸿蒙系统中HTTP模块的使用方法、Promise异步操作处理机制及async/await语法糖的应用,以及JSON数据格式的语法规则与转换方法。重点讲解了HTTP请求响应流程、鸿蒙开发中的网络权限申请与代码实现、Promise三种状态及创建方式,并通过示例说明异步编程技巧和JSON在数据传递中的应用。
60 10
Hyper V上网实战:多虚拟机网络环境配置
在Hyper-V环境中配置多虚拟机网络以实现上网功能,需完成以下步骤:1. 确认Hyper-V安装与物理网络连接正常;2. 配置虚拟交换机(外部、内部或专用)以支持不同网络需求;3. 设置虚拟机网络适配器并关联对应虚拟交换机;4. 验证虚拟机网络连接状态;5. 根据场景需求优化多虚拟机网络环境。此外,还需注意网络隔离、性能监控及数据备份等事项,确保网络安全稳定运行。
Python 高级编程与实战:深入理解网络编程与异步IO
在前几篇文章中,我们探讨了 Python 的基础语法、面向对象编程、函数式编程、元编程、性能优化、调试技巧、数据科学、机器学习、Web 开发和 API 设计。本文将深入探讨 Python 在网络编程和异步IO中的应用,并通过实战项目帮助你掌握这些技术。
公司监控软件:SAS 数据分析引擎驱动网络异常精准检测
在数字化商业环境中,企业网络系统面临复杂威胁。SAS 数据分析引擎凭借高效处理能力,成为网络异常检测的关键技术。通过统计分析、时间序列分析等方法,SAS 帮助企业及时发现并处理异常流量,确保网络安全和业务连续性。
80 11
公司网络监控软件:Zig 语言底层优化保障系统高性能运行
在数字化时代,Zig 语言凭借出色的底层控制能力和高性能特性,为公司网络监控软件的优化提供了有力支持。从数据采集、连接管理到数据分析,Zig 语言确保系统高效稳定运行,精准处理海量网络数据,保障企业信息安全与业务连续性。
79 4
Docker容器性能调优的关键技巧,涵盖CPU、内存、网络及磁盘I/O的优化策略,结合实战案例,旨在帮助读者有效提升Docker容器的性能与稳定性。
本文介绍了Docker容器性能调优的关键技巧,涵盖CPU、内存、网络及磁盘I/O的优化策略,结合实战案例,旨在帮助读者有效提升Docker容器的性能与稳定性。
376 7
网络安全的盾与剑:漏洞防御与加密技术的实战应用
在数字化浪潮中,网络安全成为保护信息资产的重中之重。本文将深入探讨网络安全的两个关键领域——安全漏洞的防御策略和加密技术的应用,通过具体案例分析常见的安全威胁,并提供实用的防护措施。同时,我们将展示如何利用Python编程语言实现简单的加密算法,增强读者的安全意识和技术能力。文章旨在为非专业读者提供一扇了解网络安全复杂世界的窗口,以及为专业人士提供可立即投入使用的技术参考。
网络安全与信息安全:知识分享####
【10月更文挑战第21天】 随着数字化时代的快速发展,网络安全和信息安全已成为个人和企业不可忽视的关键问题。本文将探讨网络安全漏洞、加密技术以及安全意识的重要性,并提供一些实用的建议,帮助读者提高自身的网络安全防护能力。 ####
110 17
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
随着互联网的普及,网络安全问题日益突出。本文将从网络安全漏洞、加密技术和安全意识三个方面进行探讨,旨在提高读者对网络安全的认识和防范能力。通过分析常见的网络安全漏洞,介绍加密技术的基本原理和应用,以及强调安全意识的重要性,帮助读者更好地保护自己的网络信息安全。
78 10
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等