温馨提示×

温馨提示×

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

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

nagios安装及监控

发布时间:2020-06-21 04:27:26 来源:网络 阅读:697 作者:Vfast_贺柏寒 栏目:移动开发

一、如何安装nagios

 

 

[root@server1 nagios]# 1 安装yum install gd-devel -y

[root@server1 nagios]# 2 部署lamp环境yum install httpd mysql mysql-server php php-mysql -y

[root@server1 nagios]# 3 安装主程序nagios

[root@server1 nagios]# tar fvxz nagios.tar.gz(进入目录解压)

[root@server1 nagios]# cd nagios-3.2.0

[root@server1 nagios]# ./configure --prefix=/usr/local/nagios(这一步运行如果未装gcc,先yum install gcc* 一下就可以了)

[root@server1 nagios]# useradd nagios

[root@server1 nagios]# make all

[root@server1 nagios]# make install

make install

     - This installs the main program, CGIs, and HTML files

 

  make install-init

     - This installs the init script in /et c/rc.d/init.d

 

   make install-commandmode

     - This installs and configures permissions on the

       directory for holding the external command file

 

  make install-config

     - This installs *SAMPLE* config files in /usr/local/nagios/etc

       You'll have to modify these sample files before you can

       use Nagios.  Read the HTML documentation for more info

       on doing this.  Pay particular attention to the docs on

       object configuration files, as they determine what/how

       things get monitored!

 

 

 

  make install-webconf

     - This installs the Apache config file for the Nagios

       web interface

 

vim /etc/httpd/conf/httpd.conf(修改UserGroupnagios

User nagios

Group nagios

 

重新启动apache(如果在编译nagios的时候,步骤不对,会无法启动服务。)

service httpd restart

service nagios start

生成用户

[root@server1 nagios-3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios(为用户设置密码,密码随意)

New password:

Re-type new password:

Adding password for user nagios

 

修改nagios的第一个配置文件,可以看到谁的分区控制台连上来,以谁的身份连上来,看到什么,是在这个文件里控制的。

 [root@server1 nagios-3.2.0]# vim /usr/local/nagios/etc/cgi.cfg

所有nagiosadmin后面添加nagios

nagios用户开权限,让他能够查看信息!

 

root@server1 nagios-

3.2.0]#/etc/init.d/nagios reload

修改好了以后重新载入一下。

进入nagios

192.168.18.126/nagios

 

本机为什么是down的状态???

 


nagios安装及监控

监控分析控制台   ---------------主程序

                                           插件

                --------------被监控主机

如果想让nagios监控别人,需要安装一个插件才可以监控。

 

[root@server1 libexec]# pwd

/usr/local/nagios/libexec

[root@server1 libexec]# ls

[root@server1 libexec]#

进入插件目录下我们看到什么没有阿!

所以需要安装插件

 

安装插件

[root@server1 nagios-plugins-1.4.13]cd /nagios-plugins-1.4.13

[root@server1 nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios/ (编译)

可选的选项--with-gnutls --with-openssl --enable-extra-opts --enable-perl-modules

 

make

 

make install

 



nagios安装及监控

二、如何监控别人

我们先看监控时间的配置文件,默认不用改。

cd /usr/local/nagios/etc/objects

vim timeperiods.cfg

这个文件是时间段的文件,24*7监视时间段24小时每天每时。


nagios安装及监控

这个文件默认不用改。

 

设置监控的是谁,修改时注意扩高成对。首先增加想要监控的对象,对象名字可随意,ip写好。

 

vim localhost.cfg

配置文件内的选项含义。

host_name 主机名可以随便写

alias       别名可以随便写

address    监控的主机IP地址(这里我们要监控的是192.168.18.124

check_command  check-host-alive 一会通过这条命令检查监控的对象的情况,这条命令是在一个配置文件定义好的

notification_options  d,u,r  什么样的情况对给你通知,down,未知,恢复这三个状态会通知给你监控对象的信息

check_interval 1  代表多长时间检查一次 (1分钟)

max_check_attempts 2  检查什么样的情况发送报警,超过2次以上的情况会发送tact

contact_groups admin 代表有情况的时候找admin

notification_interval 10 第二次通知的时间为10分钟

notification_period   代表什么时间发送通知呢 24*7,只要出了问题就会通知你

ps:(大括号要成对)。


nagios安装及监控

vim commands.cfg 定义命令的配置文件

$USR1$代表check-host-alive这条命令会执行  /usr/local/libxec/check_ping -H HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

通过命令的阀值来判断是否有问题。


nagios安装及监控


三、和谁联系

现在来定义发送信息给谁,默认的是给admin

vim contacts.cfg

admin组是事先定义好的,成员只有一个是nagiosadmin,然后我们添加一个联系人,

contact_name这个人的名字可以随便写,这里我们写source

alias 别名 随便写

host_notification_period 24*7 代表什么时间会接收信息

host_notification_option 接收报警的状态,down,未知,恢复这三个状态

host_notification_conmands


nagios安装及监控

修改好以后先检查一下错误,用这条命令

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

他会告诉你你的配置文件是否有问题

total Errors 0 没有问题


nagios安装及监控

说明已经添加好了。然后我们让我们监控的主机断开网络,会出现如图的结果


nagios安装及监控

查看日志我们发现18.124这台主机已经找不到了。 并且有报错信息


nagios安装及监控

发送报警信息是给nagiosadmin,source这两个人的,如果要不想给nagiosadmin发送可以在contacts.cfg

首先删除这几行


nagios安装及监控

然后在组员里(members)把nagiosadmin除名就可以了。


nagios安装及监控

修改了以后注意/etc/init.d nagios reload 重新读取一下

 

这样就可以监控主机了。

 

 

 

四、让监控的信息能发送到手机上

 

要求是

192.168.18.126为监控服务器

这台机器能够上网

ifconfig eth0:1 192.168.1.159

route add default gw 192.168.1.1 定义网关

ping 8.8.8.8



 

1 install

rpm -ivh /tmp/nagios/!msmtp-1.4.6-1.el5.scopserv.i386.rpm

nagios安装及监控

2 config

[187 tmp]#cd  /etc/

[187 tmp]#vim msmtprc

 

account default

host smtp.163.com

port 25

from 18611383332@163.com

tls off

auth login

user 18611383332

password 123456

logfile /tmp/msmtp.log

复制信息并修改成如图,用户名和密码是自己邮箱的。


nagios安装及监控

3 test

#####msmtp email

 

 

 

 

 

4 mutt

vim /etc/Muttrc

2753 set sendmail="/usr/bin/msmtp"

2754 set from="1861183332@163.com"

2755 set realname="iori"




nagios安装及监控

修改好

5 mutt+msmtp

echo "hello" |  mutt -s "test" hebaihan456@163.com

 

6         vim /etc/resolv.conf

修改DNS


nagios安装及监控

然后测试网络

ping www.baidu.com

 

echo "hello" |  mutt -s "test" hebaihan456@163.com

发送信息,这时手机会收到nagios报警信息。

发送的信息为hellohebaihan456@163.com

请大家支持原创。

向AI问一下细节

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

AI