资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

nagios安装及监控-创新互联

一、如何安装nagios

 

 

创新互联建站-专业网站定制、快速模板网站建设、高性价比福鼎网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式福鼎网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖福鼎地区。费用合理售后完善,十年实体公司更值得信赖。

[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(修改User和Group为nagios)

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报警信息。

发送的信息为hello到hebaihan456@163.com

请大家支持原创。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:nagios安装及监控-创新互联
网站URL:http://cdkjz.cn/article/psgph.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220