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

本文涉及的产品
RDS AI 助手,专业版
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
简介:

    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,如需转载请自行联系原作者

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
5月前
|
机器学习/深度学习 PyTorch TensorFlow
卷积神经网络深度解析:从基础原理到实战应用的完整指南
蒋星熠Jaxonic,深度学习探索者。深耕TensorFlow与PyTorch,分享框架对比、性能优化与实战经验,助力技术进阶。
|
5月前
|
监控 Linux 测试技术
C++零拷贝网络编程实战:从理论到生产环境的性能优化之路
🌟 蒋星熠Jaxonic,技术宇宙中的星际旅人。深耕C++与零拷贝网络编程,从sendfile到DPDK,实战优化服务器性能,毫秒级响应、CPU降60%。分享架构思维,共探代码星辰大海!
|
5月前
|
网络协议 Linux 虚拟化
配置VM网络:如何设定静态IP以访问主机IP和互联网
以上就是设定虚拟机网络和静态IP地址的基本步骤。需要注意的是,这些步骤可能会因为虚拟机软件、操作系统以及网络环境的不同而有所差异。在进行设定时,应根据具体情况进行调整。
452 10
|
5月前
|
存储 机器学习/深度学习 监控
网络管理监控软件的 C# 区间树性能阈值查询算法
针对网络管理监控软件的高效区间查询需求,本文提出基于区间树的优化方案。传统线性遍历效率低,10万条数据查询超800ms,难以满足实时性要求。区间树以平衡二叉搜索树结构,结合节点最大值剪枝策略,将查询复杂度从O(N)降至O(logN+K),显著提升性能。通过C#实现,支持按指标类型分组建树、增量插入与多维度联合查询,在10万记录下查询耗时仅约2.8ms,内存占用降低35%。测试表明,该方案有效解决高负载场景下的响应延迟问题,助力管理员快速定位异常设备,提升运维效率与系统稳定性。
289 4
|
5月前
|
机器学习/深度学习 数据采集 人工智能
深度学习实战指南:从神经网络基础到模型优化的完整攻略
🌟 蒋星熠Jaxonic,AI探索者。深耕深度学习,从神经网络到Transformer,用代码践行智能革命。分享实战经验,助你构建CV、NLP模型,共赴二进制星辰大海。
|
6月前
|
机器学习/深度学习 人工智能 算法
卷积神经网络深度解析:从基础原理到实战应用的完整指南
蒋星熠Jaxonic带你深入卷积神经网络(CNN)核心技术,从生物启发到数学原理,详解ResNet、注意力机制与模型优化,探索视觉智能的演进之路。
600 11
|
6月前
|
传感器 数据采集 存储
【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)
【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)
182 0
|
8月前
|
机器学习/深度学习 人工智能 PyTorch
零基础入门CNN:聚AI卷积神经网络核心原理与工业级实战指南
卷积神经网络(CNN)通过局部感知和权值共享两大特性,成为计算机视觉的核心技术。本文详解CNN的卷积操作、架构设计、超参数调优及感受野计算,结合代码示例展示其在图像分类、目标检测等领域的应用价值。
477 7
|
SQL 安全 网络安全
网络安全与信息安全:知识分享####
【10月更文挑战第21天】 随着数字化时代的快速发展,网络安全和信息安全已成为个人和企业不可忽视的关键问题。本文将探讨网络安全漏洞、加密技术以及安全意识的重要性,并提供一些实用的建议,帮助读者提高自身的网络安全防护能力。 ####
379 17
|
SQL 安全 网络安全
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
随着互联网的普及,网络安全问题日益突出。本文将从网络安全漏洞、加密技术和安全意识三个方面进行探讨,旨在提高读者对网络安全的认识和防范能力。通过分析常见的网络安全漏洞,介绍加密技术的基本原理和应用,以及强调安全意识的重要性,帮助读者更好地保护自己的网络信息安全。
296 10

热门文章

最新文章