Detailed configuration of Nagios

Source: Internet
Author: User
Tags linux

The previous "automated installation Nagios" completed the Nagios server-side installation, now need to configure the Nagios to achieve basic monitoring functions.

Experimental environment:

CentOS 6.3 x86_64, VirtualBox 4.1.14

Turn off firewalls and SELinux

Nagios version nagios-3.4.1

Plug-in version nagios-plugins-1.4.16

Nrpe version nrpe-2.13

Implementation steps:

Add the machine name of the monitored server to the configuration file hosts.cfg

Add the machine name of the monitored server to the configuration file of the owning group Hostgrps.cfg

Add the service type of the monitored server to the configuration file services.cfg

Add Nrpe to the command configuration file commands.cfg

The path to the above configuration file is stated in the Nagios main configuration file nagios.cfg

Start configuration:

Declare a variable to Nagios installation path

Nagios_dir= "/usr/local/nagios"

One, add the monitored host to the hosts.cfg

CD $nagios _dir/etc/objects  #进入nagios配置文件所在目录
    [f new.host] && rm-f new.host  # To determine if the New.host file exists, delete the old host file
    exec < hosts.list  #hosts. List for manually created files for specifying host names and IP while
    read line  # extract hostname and IP from hosts.list and add to New.host file do
         echo "define host {" >> new.host 
         echo "           use Linux-server ">> new.host 
         echo"     host_name     ' echo $line |awk ' {print} ' ">> new.host 
         echo "     alias         ' echo $line |awk ' {print} '" ' >> new.host 
         echo "Address       ' echo $line |awk ' {print $} ' ">> New.host 
         Echo"} ">> New.host      
         echo >> new.host done 
    cat New.host >> hosts.cfg  #将做好的主机模板添加到hosts. cfg file

Hosts.list files need to be created manually, in the form of "host name IP Address", you can add multiple at once,

If a new host needs to be added later, clear the old content directly in the Hosts.list and add the new host information.

Test-machine1 192.168.0.100

Test-machine2 192.168.0.101

Test-machine3 192.168.0.102

New.host for the generated host template

Define host { 
     use           linux-server 
     host_name     test-machine1 
     alias         test-machine1
     Address       192.168.0.100
}

Finally, the generated host template is added to the host file Hosts.cfg, which is generated by the Nagios, which is a well defined and monitored host template.

Second, add the group that hosts belong to

The monitored host will be grouped into a monitoring group, where only one group is generated, others, etc.

CD $nagios _dir/etc/objects 
   newhosts= ' cat Hosts.list|awk ' {print} ' |tr ' \ n ', ', ', '  #提取host. List of hostname
   if [!-f hostgrps.cfg]; Then  #判断hostgrps. cfg file for
        echo "define HostGroup {" >> hostgrps.cfg  #添加hostgrps. cfg file Body
        Echo "     hostgroup_name     lnx-srvs" >> hostgrps.cfg 
        echo "     alias     Lnx-srvs" >> Hostgrps.cfg 
        echo "     members     $newhosts" >> hostgrps.cfg 
        Echo "}" >> hostgrps.cfg 
        sed-i.bak '/members/s/,$//' hostgrps.cfg  #去掉主机名结尾的逗号
   else
        sed-i.bak '/members/s/^.*$/&, ' $newhosts '/' hostgrps.cfg #若hostgrps文件已存在, only append the new hostname to the Members column
        Sed-i.bak '/members/s/,$//' hostgrps.cfg 
   fi

The resulting hostgrps.cfg file name format is

Define hostgroup{ 
        hostgroup_name  lnx_srvs 
        alias           lnx_srvs 
        members         Test-machine1, Test-machine2 
}

Third, add Nrpe to the command configuration file

echo " 
define command{ 
   command_name   Nrpe 
   command_line   $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ arg1$ 
   } ">> $natios _dir/etc/objects/commands.cfg

Four, add service files

Next is the more important Nagios monitoring service file Services.cfg

     CD $nagios _dir/etc/objects newhosts= ' cat Hosts.list|awk ' {print} ' |tr ' \ n ', ' #定义变量newhosts为提取的主机名 I f [!-F services.cfg];  
         Then #判断services. cfg file exists echo "#若不存在则新增模板正文 define service{use Remote-service Host_name ' $newhosts ' service_description current Users on Remote 
         System check_command nrpe!check_users #监控主机当前登录的用户数量} define Service{ Use Remote-service host_name ' $newhosts ' servi
         Ce_description Current System loads Check_command nrpe!check_load #监控系统的负载                        } define service{use Remote-service host_name ' $newhosts ' service_description Zombie processes on Remote System Check_coMmand Nrpe!check_zombie_procs #监控主机僵尸进程数量} define service{use              Remote-service host_name ' $newhosts ' service_description
         Total processes on Remote System Check_command Nrpe!check_total_procs #监控主机总进程数量                        } define service{use Remote-service host_name                    ' $newhosts ' service_description Disk Using the Remote System Check_command Nrpe!check_disk #监控磁盘空间} define service{use Remote-s Ervice host_name ' $newhosts ' service_description Swap Using of of Remo 
     
          Te System check_command nrpe!check_swap #监控交换分区空间} "> Serverces.cfg Sed-i.bak '/host_name/s/,$//' services.cfg #去掉host_name最后的逗号 else Sed-i.bak '/host_name/s/^.*$/&, ' $newhosts '/' Servi Ces.cfg #若services. CFG already exists, you can append the new host name directly Sed-i.bak '/host_name/s/,$//' services.cfg fi

Five, restart the Nagios service

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/soft/tools/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.