天天看点

Nagios3.3.1配置文档

               Nagios3.3.1 安装文档

##安装php apache sendmail

yum install  httpd gd gd-devel php php-devel sendmail –y

service sendmail start

添加用户和组,把用户加入组

usermod nagios

passwd nagios

groupadd nagcmd

usermod  -g  nagcmd nagios

usermod  -G  nagcmd apache

##安装nagios

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz

tar xvf nagios-3.3.1.tar.gz

cd nagios

./configure --prefix=/usr/local/nagios  --with-command-group=nagcmd

make all

      
make install

      
make install-init   

      
make install-config

      

make install-commandmode

make install-webconf

###检测配置文件

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

#### 设置管理员密码

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

####安装插件

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

tar xvf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

make

make install

Wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz

tar xzf nagios-snmp-plugins.1.1.1.tgz

cd nagios_plugins

安装perl 安装模块cpanm

wget --no-check-certificate http://bit.ly/cpanm

chmod u+x cpanm

mv cpanm /usr/bin

##安装所需模块,此处所需时间较长

cpanm  Crypt::DES Digest::MD5 Digest::SHA1 Digest::HMAC  Net::SNMP

. /install.sh

### 添加,设置服务

chkconfig --add nagios

chkconfig –level 35 httpd on

chkconfig –level 35 nagios on

###关闭SELINUX或者配置SELINUX安全上下文 建议关闭SELINUX

Setenforce 0

vim /etc/sysconfig/selinux 

SELINUX=disabled

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/

chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

chown –r nagios:nagcmd /usr/local/nagios

service httpd restart

service nagios start

##配置nagios

##contacts.cfg  报警联系人配置

配置警报发送目标邮箱

vim contacts.cfg

email  [email protected]

##commands.cfg  监控命令定义

##templates.cfg   主机,服务模板配

##tempaltes.cfg参数:

service_description                            #监控页面显示的服务名字

check_period            24x7                  监控周期设置            

max_check_attempts      4                     最大检测尝试次数

normal_check_interval   3                       正常检测间隔时间

retry_check_interval    2                        重试检测间隔时间

contact_groups          admins                  报警联系组

notification_interval   10                         通知间隔                        

notification_period     24x7                      通知周期设置

notification_options    w,u,c,r                    定义什么状态时报警

## 添加监控命令 监控内存和交换分区使用情况

vim  commands.cfg

define command{

command_name check_snmp_memory

command_line $USER1$/check_snmp_mem.pl  –H $HOSTADDRESS$  -C public –w 90,5 –c 100,99

##添加被监控主机:

echo  cfg_file=/usr/local/nagios/etc/objects/web-123.cfg >>nagios.cfg

vim /usr/local/nagios/etc/objects/web-123.cfg

define host{

        use             windows-server      ##定义使用的模板

        host_name       web-123              ##定义主机名为web-123

        alias           web-123-web       ##主机别名

        address         192.168.1.2      ##主机IP地址

        hostgroups      linuxweb          ##将该主机归到linuxweb这个组,如果要归到多个组里,用逗号分隔组名

}

define hostgroup{

        hostgroup_name  linuxweb

        alias           linux web servers

        members       web-123   #设置该组的成员,需要是在host中定义的主机名,多个成员请用逗号分隔

##这样就定义了一个linuxweb组,将主机归为一个组有两种方法,一种是我们这种在主机的定义中去设置,另外一种是在组的设置中定义members。如下define hostgroup{

        alias           linuxweb

        members       web-123  ###设置该组的成员,需要是在host中定义的主机名,多个成员请用逗号分隔

        alias           linux web server

define service{

        use                            generic-service #使用的模板,此处使用通用模板        

hostgroup_name               linuxweb  ###将linuxweb所有成员都添加该服务

host_name                       web-123          #主机名

        service_description                check_snmp_memory     #监控页面显示的名字

        check_command                  check_snmp_memory     #监控服务命令

        ###关于监控参数,可在模板定义,也可以在此处单独定义。优先主机配置文件中定义的参数。

service nagios restart

关于nagios-snmp-plugins插件的用法和功在http://nagios.manubulon.com/ 有详细介绍。

到此处还没有全部完毕。应根据实际更改

正常检测时间

错误重复检测时间

最大检测次数

什么状态才报警

邮件报警频率

计划用perl来写一个网页,来添加主机和服务。