温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

开源监控——nagios

发布时间:2020-06-25 18:13:01 来源:网络 阅读:682 作者:chh121018 栏目:移动开发

开源监控-ngios

Nagios是一款开源的免费网络监视工具,能有效监控WindowsLinuxUnix主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一间通知网站运维人员,在状态恢复后发出

正常的邮件或短信通知。



实验拓扑


开源监控——nagios

主机ngios安装过程

准备环境

挂载光驱 配置yum

[root@chh2 ~]# mount /dev/cdrom /mnt/cdrom

[root@chh2 ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo

开源监控——nagios

yum安装软件包

[root@chh2 ~]# yum install httpd php php-gd php-mbstring mysql-devel

[root@chh2 ~]# service httpd start

[root@chh2 ~]# chkconfig httpd on

安装NMS监管服务器所需要的软件包

开源监控——nagios

下面开始安装这些软件包

拆解 ngios的数据包

[root@chh2 ~]# tar -zxvf nagios-3\[1\].2.1.tar.gz -C /usr/local/src/

创建一个组 nagcmd

groupadd nagcmd

创建一个账号 nagios

useradd -m nagios

加入组

usermod -a -G nagcmd nagios

将apache 账号也添加竟来

usermod -a -G nagcmd apache

来到源码目录,开始配置nagios-3\[1\].2.1

[root@chh2 nagios-3.2.1]# ./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --sysconfdir=/etc/nagios --enable-event-broker

[root@chh2 nagios-3.2.1]# make all

[root@chh2 nagios-3.2.1]# make install

[root@chh2 nagios-3.2.1]# make install-init

[root@chh2 nagios-3.2.1]# make install-commandmode

[root@chh2 nagios-3.2.1]# make install-config

[root@chh2 nagios-3.2.1]# make install-webconf

创建一个登陆nagios web程序的用户 这个账号在以后通过web登陆nagios认证时使用

[root@chh2 conf.d]# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin 密码:123

添加nagios进行chkconfig管理

[root@chh2 conf.d]# chkconfig --add nagios

[root@chh2 conf.d]# chkconfig --list |grep nagios

nagios 0:off1:off2:off3:on4:on5:on6:off

安装插件

拆解插件包

[root@chh2 ~]# tar -zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src/

来进行插件的配置

[root@chh2 nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

安装

[root@chh2 nagios-plugins-1.4.15]# make && make install

对nagios的配置文件进行语法的检测

[root@chh2 libexec]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg

检测结果是这样就说明没有问题

开源监控——nagios

启动nagios

[root@chh2 libexec]# service nagios start

Starting nagios: done.

[root@chh2 libexec]# chkconfig nagios on

重启apache加载文件

[root@chh2 libexec]# service httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

下面我们访问一下试试

开源监控——nagios

开源监控——nagios

开源监控——nagios

开源监控——nagios

开源监控——nagios

在图上的各种服务都是在/etc/nagios/objects/commands.cfg中定义的,我们可以打开看看

下面给大家来看个小例子

打开/etc/nagios/objects/commands.cfg中命令的定义

我们找到check_ping

开源监控——nagios

那么上图中的那一行命令到底是什么意思呢?下面我给大家好好解释一下

首先看一下$USER1$:

开源监控——nagios

从上图我们可以看出在/etc/nagios/resource.cfg我们会找到$USER1$,其实就是调用了我们的插件库目录而已。

在来到我们的插件库看看/usr/local/nagios/ libexec,看看到底有没有check_ping

开源监控——nagios

结果我们可以找到check_ping,但是这个该怎么用呢,小编我也很郁闷,那我们再来看一下/etc/nagios/objects/commands.cfg中对check_ping的定义

command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5

那我们再来看看check_ping的用法吧

[root@chh2 libexec]# ./check_ping -h |less

开源监控——nagios

这下大家应该清楚那一行命令的意思了吧

下面来来个例子ping一下我们的主机试试吧。

开源监控——nagios

关于更多的插件的使用,大家可以使用帮助来查看,我就不一个个解释了。

接着我们来看一下主机文件在/etc/nagios/objects/localhost.cfg

开源监控——nagios

开源监控——nagios

开源监控——nagios

开源监控——nagios

在控制台上的服务都是在这里面定义的服务。在上面我看到了报警,但是报警需要联系人,下面我们就来看一下联系人文件/etc/nagios/objects/contacts.cfg

开源监控——nagios

开源监控——nagios

为了测试发送邮件,小编多登陆了几个用户。看看邮件日志

开源监控——nagios

到我的163邮箱看看

开源监控——nagios

相信看了这几个文件大家对nagios就有了一个比较清晰的了解吧。


下面我们开始监控一台windows主机试试。

开源监控——nagios

监控windows主机我们还可以采用NRPE,SNMP

首先我们需要在windows主机上安装NSCLient++

开源监控——nagios

开源监控——nagios

开源监控——nagios

开源监控——nagios

打开模块,引用他们

开源监控——nagios

开源监控——nagios

然后保存,重启我们的服务。

修改/etc/nagios/objects/windows.cfg

[root@chh2 objects]# vim windows.cfg

开源监控——nagios

修改nagios的配置文件让它监控windows

[root@chh2 nagios]# pwd

/etc/nagios

[root@chh2 nagios]# vim nagios.cfg

开源监控——nagios

检查语法参数。重启nagios

[root@chh2 nagios]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg

[root@chh2 nagios]# service nagios restart

打开页面看看,已经监控到了。

开源监控——nagios

下面我们再来看看监控linux主机试试。这次我们采用NRPE,但是我们的nagios是没有这个插件。所以我们需要自己安装。。。

我们需要监控mysqlApache。所以我们就安装一下他们

[root@chh2 ~]# yum install mysql-devel mysql mysql-server httpd

启动一下httpmysql

开源监控——nagios

mysql添加密码

[root@chh2 ~]# chkconfig mysqld on

[root@chh2 ~]# mysqladmin -u root -p password '123'

下面开始在我们的linux客户端上安装插件

先创建账号 nagios

[root@chh2 ~]# useradd nagios

拆解插件包

[root@chh2 ~]# tar -zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src/

来到拆解目录配置文件

[root@chh2 nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@chh2 nagios-plugins-1.4.15]# make && make install

在客户端上安装nrpe

[root@chh2 ~]# tar -zxvf nrpe-2.12.tar.gz -C /usr/local/src/

[root@chh2 nrpe-2.12]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl

安装

# make all

# make install-plugin

# make install-daemon

# make install-daemon-config

编辑客户端 nrpe配置文件

[root@chh2 nrpe-2.12]# vim /usr/local/nagios/etc/nrpe.cfg

开源监控——nagios

开源监控——nagios

启动nrpe

[root@chh2 nrpe-2.12]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios

[root@chh2 nrpe-2.12]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.d/rc.local

[root@chh2 nrpe-2.12]#

1. ngios服务器上安装插件。

[root@chh2 ~]# tar -zxvf nrpe-2.12.tar.gz -C /usr/local/src/

对拆解文件进行配置

./configure --with-nrpe-user=nagios \

--with-nrpe-group=nagios \

--with-nagios-user=nagios \

--with-nagios-group=nagios \

--enable-command-args \

--enable-ssl

安装

make all

安装插件

make install-plugin

2. commands.cfg 定义外部构件nrpe

[root@chh2 nrpe-2.12]# vim /etc/nagios/objects/contacts.cfg

增加

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

开源监控——nagios

3.创建监控linux主机的文件。

/usr/local/nagios/etc/objects 创建 mylinux.cfg

开源监控——nagios

开源监控——nagios

编辑客户端文件添加我们监控中没有命令

[root@chh2 ~]# vim /usr/local/nagios/etc/nrpe.cfg

开源监控——nagios

重启

[root@chh2 ~]# pkill -9 nrpe

[root@chh2 ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

4.为了监控linux系统 修改 nagios.cfg

[root@chh2 objects]# vim /etc/nagios/nagios.cfg

开源监控——nagios

做一下语法检测

[root@chh2 objects]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg

重启ngios服务。

开源监控——nagios

下面开始添加我们监控web的命令。

在客户端上

[root@chh2 ~]# cd /usr/local/nagios/etc/

[root@chh2 etc]# vim nrpe.cfg

开源监控——nagios

然后要重启nrpe

开源监控——nagios

来到服务器上

修改mylinux

[root@chh2 ~]# vim /etc/nagios/objects/mylinux.cfg

开源监控——nagios

重启一下

开源监控——nagios

那我们来到打开nagios看看(windows主机没有启动)

开源监控——nagios


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI