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

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).准备安装

[[email protected] mnt]# tar jxf nagios-cn-3.2.3.tar.bz2

[[email protected] mnt]# mv nagios-cn-3.2.3  /root/

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

    (2).编译安装

[[email protected] mnt]# cd /root/nagios-cn-3.2.3/

[[email protected] nagios-cn-3.2.3]# ./configure

[[email protected] nagios-cn-3.2.3]# useradd -u 900 -M -d /usr/local/nagios nagios

[[email protected] nagios-cn-3.2.3]# make all

[[email protected] nagios-cn-3.2.3]# make

[[email protected] nagios-cn-3.2.3]# make install-init

*** Init script installed ***

[[email protected] nagios-cn-3.2.3]# make install-commandmode

*** External command directory configured ***

[[email protected] nagios-cn-3.2.3]# make install-config

*** Config files installed ***

[[email protected] nagios-cn-3.2.3]# make install-webconf

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

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

[[email protected] nagios-cn-3.2.3]#  cat /usr/local/nagios/etc/htpasswd.users  ##查看密码

nagiosadmin:gCWSDnqEHR45c

[[email protected] 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)启动服务

[[email protected] nagios-cn-3.2.3]# /etc/init.d/httpd start

Starting httpd:                                            [  OK  ]

[[email protected] nagios-cn-3.2.3]# /etc/init.d/nagios start

Starting nagios: done.

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

2.排除故障

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

(1)[[email protected] 0722-监控-nagios]# cd /mnt/

[[email protected] mnt]# tar -zxf nagios-plugins-2.1.1.tar.gz

[[email protected] mnt]# mv nagios-plugins-2.1.1  /root/

[[email protected] mnt]# cd /root/nagios-plugins-2.1.1/

(2)编译插件

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

[[email protected] 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

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

[[email protected] libexec]# id apache

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

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

   (3).编辑配置文件

(3.1)

[[email protected] 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)

[[email protected] nagios-plugins-2.1.1]# cd /usr/local/nagios/etc/objects/

[[email protected] objects]# cp -p localhost.cfg hosts.conf

[[email protected] objects]# cp -p localhost.cfg services.cfg

[[email protected] objects]# cp -p localhost.cfg hosts.cfg

(3.3)

[[email protected] 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)[[email protected] 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)[[email protected] 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)

[[email protected] objects]# /etc/init.d/nagios reload

Running configuration check...done.

Reloading nagios configuration...done

浏览器刷新浏览:172.25.254.1/nagios

3.加个mysql服务

[[email protected] ~]# yum install mysql-server -y

[[email protected] ~]# /etc/init.d/mysqld restart

[[email protected] ~]# mysql

> show databases;

> grant select on test.* to [email protected] identified by ‘redaht‘;

[[email protected] ~]# cd /usr/local/nagios/libexec

[[email protected] 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;;;

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

[[email protected] libexec]cd /usr/local/nagios/etc/objects

[[email protected] 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        }

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

[[email protected] 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         }

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

[[email protected] 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         }

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

[[email protected] objects] /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检查

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

可以看到多了一个Mysql监控

时间: 2024-10-06 00:58:31

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

实战Nagios网络监控(2)—— Nagios+Nrpe监控其他主机

本次实验在上次实验的环境下进行:实战Nagios网络监控(1)--监控本机运行状态和Mysq主机 需要的包:nagios-plugins-2.1.1.tar.gz nrpe-2.15.tar.gz 服务器端:server1.example.com        172.25.254.1 新监控端:server2.example.com        172.25.254.2 实验前提: /etc/init.d/httpd start /etc/init.d/nagios start /etc/i

实战Nagios网络监控(3)——Nagios 微信报警

1. 下载微信公众平台私有接口 # yum install -y git # git clone https://github.com/lealife/WeiXin-Private-API 2. 修改微信公众平台私有接口代码,以配合 nagios 报警 # cp -r WeiXin-Private-API /usr/local/nagios/libexec/weixin # chown -R nagios.nagios /usr/local/nagios/libexec/weixin # cd

实战1 网络监控cacti的安装配置

一.cacti概述二.cacti工作流程三.cacti安装四.配置cacti监控本机 环境: 操作系统:CentOS 6.4 x86_64软件:Cacti-0.8.7e 官方网站:http://www.cacti.net 一.cacti概述Cacti 在英文中的意思是仙人掌的意思,Cacti是一套基于PHP.MySQL.SNMP及RRDTool开发的网络流量监测图形分析工具.它通过snmpget来获取数据,使用 RRDtool绘画图形,它的界面非常漂亮,能让你根本无需明白rrdtool的参数能轻

实战Cacti网络监控(2)——搭建Spine轻量级框架

本次实验接着上次实验的环境.实战Cacti网络监控(1)--基础安装配置     (1)在物理主机上:        <1>yum install net-snmp.x86_64  -y    ##安装snmp服务             yum install net-snmp-utils.x86_64 -y        <2>vim /etc/snmp/snmpd.conf 41 #com2sec notConfigUser  default       public 42

nagios网络监控

nagios网络监控

实战Nagios NSCA方式监控Linux系统资源使用情况 -- Nagios配置篇 -- 被监控端

Nagios要求被监控端按照约定格式定时将数据发送到Nagios端.监控包括节点和服务2种. 节点监控约定数据格式如下: [<timestamp>] PROCESS_HOST_CHECK_RESULT;<host_name>;<host_status>;<plugin_output> 格式很容易理解,数据提交时间戳,被监控节点名称,节点状态(UP/DOWN/UNREARCHABLE),插件自定义的额外数据.状态具体每个字段的解释如下: 1. timestam

Linux网络流量实时监控ifstat iftop命令详解(转载)

转自:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858923.html ifstat 介绍 ifstat工具是个网络接口监测工具,比较简单看网络流量 实例 默认使用 #ifstat eth0 eth1 KB/s in KB/s out KB/s in KB/s out 0.07 0.20 0.00 0.00 0.07 0.15 0.58 0.00 默认ifstat不监控回环接口,显示的流量单位是KB. 监控所有网络接口 # ifst

ifstat和iftop网络流量实时监控

ifstat 系统自带的网络接口流量检测工具,比较简单 [[email protected] ~]# ifstat -a #16202.1804289383 sampling_interval=1 time_const=60 Interface        RX Pkts/Rate    TX Pkts/Rate    RX Data/Rate    TX Data/Rate RX Errs/Drop    TX Errs/Drop    RX Over/Rate    TX Coll/Rat

Linux网络流量实时监控ifstat iftop命令详解

ifstat 介绍 ifstat工具是个网络接口监测工具,比较简单看网络流量 实例 默认使用 #ifstat eth0 eth1 KB/s in KB/s out KB/s in KB/s out 0.07 0.20 0.00 0.00 0.07 0.15 0.58 0.00 默认ifstat不监控回环接口,显示的流量单位是KB. 监控所有网络接口 # ifstat -a lo eth0 eth1 KB/s in KB/s out KB/s in KB/s out KB/s in KB/s ou