nagios安装及配置

注意80端口是否被占用netstat-ntlp 因为apache默认为80端口,如被占用会导致页面无法访问的情况。

1.Nagios的主程序

https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz

2.nagios-plugins-1.4.13.tar.gz Nagios 的插件

https://www.nagios.org/downloads/nagios-plugins/nagios-plugins-2.2.1.tar.gz

3.nrpe-3.2.0.tar.gz 代理检测程序

https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.2.0/nrpe-3.2.0.tar.gz

 直接使用wget +下载地址 下载

在此演示安装版本为nagios-4.3.2nagios-plugins-2.2.1nrpe-3.2.0

 

一、n agios-4.3.2  安装

1.安装前的依赖检查

[root@localhost ~]# yum install httpd php gcc glibcglibc-common gd gd-devel

[root@localhost ~]# useradd -m nagios

[root@localhost ~]# groupadd nagcmd

[root@localhost ~]# usermod -a -G nagcmd nagios

[root@localhost ~]# usermod -a -G nagcmd apache

2.解压

[root@localhost ~]# cd usr/local/src/

[root@localhost src]# tar xvf nagios-4.3.2.tar.gz

[root@localhost src]# cd nagios-4.3.2

3.安装

[root@localhost nagios-4.3.2]# ./configure--prefix=/usr/local/nagios --with-command-group=nagcmd --with-nagios-user=nagios--with-nagios-group=nagios

 

 

[root@localhost nagios-4.3.2]# make all

[root@localhost nagios-4.3.2]# make install

[root@localhost nagios-4.3.2]# make install-init (生成init启动脚本)

[root@localhost nagios-4.3.2]# make install-config (生成一些模板配置文件)

[root@localhost nagios-4.3.2]# make install-commandmode (设置相应的权限)

[root@localhost nagios-4.3.2]# make install-webconf (生成Apache配置文件nagios.conf

 

4.Nagios设置Web验证的密码。(注意第一次添加用户用-c选项,以后再添加千万别在用这个选项了,会覆盖以前的所有用户的。)

[root@localhost nagios-4.3.2]# htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

 

 

5.设置nagios的开机启动

[root@localhost nagios-4.3.2]# chkconfig --add nagios

[root@localhost nagios-4.3.2]# chkconfig nagios on

[root@localhost nagios-4.3.2]# chkconfig httpd on

 

6.关闭SELinux

[root@localhost nagios-4.3.2]# vi /etc/sysconfig/selinux

 

SELINUX=disabled

 

二、安装Nagios的插件nagios-plugin

[root@localhost src]# pwd

/usr/local/src

[root@localhost src]# tar xvf nagios-plugins-2.2.1.tar.gz

[root@localhost src]# cd nagios-plugins-2.2.1

[root@localhost nagios-plugins-2.2.1]# ./configure--prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios

[root@localhost nagios-plugins-2.2.1]# make && makeinstall

 

 

三、验证Nagios的样例配置文件

[root@localhost nagios-plugins-2.2.1]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

Nagios Core 4.3.2

Copyright (c) 2009-present Nagios Core Development Team andCommunity Contributors

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 2017-05-09

License: GPL

 

Website: https://www.nagios.org

Reading configuration data...

   Read main config file okay...

   Read object config files okay...

 

Running pre-flight check on configuration data...

 

Checking objects...

Checked 8 services.

Checked 1 hosts.

Checked 1 host groups.

Checked 0 service groups.

Checked 1 contacts.

Checked 1 contact groups.

Checked 24 commands.

Checked 5 time periods.

Checked 0 host escalations.

Checked 0 service escalations.

Checking for circular paths...

Checked 1 hosts

Checked 0 service dependencies

Checked 0 host dependencies

Checked 5 timeperiods

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

 

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected duringthe pre-flight check

 

如果没有报错,可以启动Nagios服务

service nagios start

使用http://localhost/nagios/来访问

 

ps:如果遇到问题!!!!

如果遇到关于cgi什么权限问题!察看下/usr/local/nagios的属主组权限,

包括里面的内容,

尤其是/usr/local/nagios/etc/htpasswd.users这个文件的权限!都应该是nagios:nagios

另外尝试编辑

vi /usr/local/nagios/etc/cgi.cfg

use_authentication=1

修改为

use_authentication=0

 cd /usr/local/nagios/etc/

修改主配置文件nagios.cfg
#cfg_file=/usr/local/nagios/etc/localhost.cfg   #
注释或删掉这行
cfg_file=/usr/local/nagios/etc/hosts.cfg     #主机配置文件路径
cfg_file=/usr/local/nagios/etc/hostgroups.cfg  #主机组配置文件路径
cfg_file=/usr/local/nagios/etc/contacts.cfg      #去掉注释联系人配置文件路径
cfg_file=/usr/local/nagios/etc/contactgroups.cfg   #去掉注释,联系组配置文件路径 
 cfg_file=/usr/local/nagios/etc/services.cfg      #去掉注释,服务配置文件路径    
 cfg_file=/usr/local/nagios/etc/timeperiods.cfg     #去掉注释,监视时段配置文件路径


 check_external_commands=1  #
在web界面下重启nagios、停止主机/服务检查等操作,.默认值是0.
 command_check_interval=10s   #根据自己的情况定这个命令检查时间间隔.默认值是1秒.
 
修改cgi配置文件cgi.cfg.跟修改nagios.cfg一样,修改的地方如下:
   #如有多个用户,中间用逗号隔开

  authorized_for_system_information=lee
   authorized_for_configuration_information=lee
   authorized_for_system_commands=lee
   authorized_for_all_services=lee
   authorized_for_all_hosts= lee
   authorized_for_all_service_commands=lee
   authorized_for_all_host_commands=lee


在这里指定的用户”lee”可以通过浏览器操纵nagios服务的关闭、重启等各种操作
 增加其他的配置文件
1、增加主机配置文件

#vi hosts.cfg
define host {
      host_name                nagios-server   #
监控机的主机名
      alias                     nagios server
       address                   192.168.2.47   #
监控机的ip地址
      contact_groups             sagroup
      check_command            check-host-alive   #主机检查使用命令
      max_check_attempts         3      #最大尝试次数
      notification_interval         10       #通知时间间隔
      notification_period          24x7
      notification_options         d,u,r  #d-down, u-unreacheable, r-recovery.
       }
#被监控主机的定义
define host {
      host_name                 mysql
      alias                     mysql
      address                   192.168.2.154
      contact_groups             sagroup
      check_command            check-host-alive
      max_check_attempts          3
      notification_interval          10
      notification_period          24x7
       notification_options         d,u,r
       }


创建联系组contact_group配置文件
 2、定义主机组配置文件hostgroups.cfg
 

    define hostgroup {
      hostgroup_name  sa-servers
     alias            saservers
     members        nagios-server
      }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值