Ubuntu Server 14.04 安装nagios,nrpe

0、安装软件

1、设置主机及相关关系

2、设置主机组

3、设置监控的服务

4、nrpe设置

0、安装软件及初始化

sudo apt-get install apache2 -y

sudo apt-get install nagios3 nagios-plugins nagios-images -y

更改管理员账户

sudo sed -i ‘s/nagiosadmin/ywz/g’ /etc/nagios3/cgi.cfg 

sudo htpasswd /etc/nagios3/htpasswd.users ywz

添加用户

sudo htpasswd /etc/nagios3/htpasswd.users user1

联系人设置

define contact{

        contact_name                    ywz

        alias                           ywz

        service_notification_period     24x7

        host_notification_period        24x7

        service_notification_options    w,u,c,r

        host_notification_options       d,r

        service_notification_commands   notify-service-by-email

        host_notification_commands      notify-host-by-email

        email                           ywz_306@163.com

        }

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 ywz

        }

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------

 

1、设置主机及用户组

设置名称,地址,及相互连接方式

sudo nano /etc/nagios3/conf.d/hosts.cfg

define host{

        host_name Baidu

        alias   IC

        address www.baidu.coom

        use     generic-host

}

define host{

        host_name WAN

        alias   pppoe

        address  172.24.214.44

        parents Baidu

        use     generic-host

}

define host{

        host_name Lan

        alias   route

        address 192.168.3.1

        parents WAN

        use     generic-host

}

define host{

        host_name haproxy1

        alias   haproxy1

        address 192.168.3.17

        parents Lan

        use     generic-host

}

define host{

        host_name haproxy2

        alias   haproxy2

        address 192.168.3.18

        parents Lan

        use     generic-host

}

define host{

        host_name www1

        alias   www1

        address 192.168.3.33

        parents Lan

        use     generic-host

}

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------

 

2、设置主机组

sudo nano /etc/nagios3/conf.d/hostgroups_nagios2.cfg

# Some generic hostgroup definitions

# A simple wildcard hostgroup

define hostgroup {

        hostgroup_name  all

alias           All Servers

members         *

        }

# A list of your Debian GNU/Linux servers

define hostgroup {

        hostgroup_name  debian-servers

alias           Debian GNU/Linux Servers

members         localhost,haproxy1,haproxy2,www1

        }

# A list of your web servers

define hostgroup {

        hostgroup_name  http-servers

alias           HTTP servers

members         localhost,www1

        }

# A list of your ssh-accessible servers

define hostgroup {

        hostgroup_name  ssh-servers

alias           SSH servers

members         localhost, haproxy1, haproxy2,www1

        }

define hostgroup {

hostgroup_name all-gateways

aliasAll Gateways

membersLan, WAN

}

define hostgroup {

hostgroup_name ubuntu-servers

aliasUbuntu servers

members localhost, haproxy1, haproxy2, www1

}

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------

 

2.1设置设备图标

sudo nano /etc/nagios3/conf.d/extinfo_nagios2.cfg

##

## Extended Host and Service Information

##

define hostextinfo{

        hostgroup_name   debian-servers

        notes            Debian GNU/Linux servers

#       notes_url        http://webserver.localhost.localdomain/hostinfo.pl?host=netware1

        icon_image       base/debian.png

        icon_image_alt   Debian GNU/Linux

        vrml_image       debian.png

        statusmap_image  base/debian.gd2

        }

define hostextinfo{

hostgroup_name all-gateways

icon_image base/ng-switch40.png

statusmap_image base/ng-switch40.png

}

define hostextinfo{

hostgroup_name ubuntu-servers

icon_image base/ubuntu.png

statusmap_image base/ubuntu.png

}

3、设置需要监控服务

sudo nano /etc/nagios3/conf.d/services_nagios2.cfg

# check that web services are running

define service {

        hostgroup_name                  http-servers

        service_description             HTTP

 check_command                   check_http

        use                             generic-service

notification_interval           0 ; set > 0 if you want to be renotified

}

# check that ssh services are running

define service {

        hostgroup_name                  ssh-servers

        service_description             SSH

check_command                   check_ssh

        use                             generic-service

notification_interval           0 ; set > 0 if you want to be renotified

}

define service {

hostgroup_nameall-gateways

service_descriptionPING

check_commandcheck_ping!100.0,20%!500.0,60%

usegeneric-service

notification_interval0

}

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------

 

3.1 nagios-plugins 安装

http://nagios-plugins.org/

https://www.nagios.org/download/plugins/

4、nrpe相关设置

被控端

sudo apt-get install nagios-nrpe-server -y

更改配置文件

sudo nano /etc/nagios/nrpe.cfg

allowed_hosts=192.168.1.50

command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -e

sudo service nagios-nrpe-server restart

主控端

新建单独的配置文件

sudo nano /etc/nagios3/conf.d/www1.cfg

define service{
usegeneric-service
host_name www1
service_descriptionDisk space
check_commandcheck_nrpe_1arg!check_all_disks
}

define service{ 
        use     generic-service
        host_name       www1       
        service_description     Current Users
        check_command   check_nrpe_1arg!check_users
}

define service{ 
        use     generic-service
        host_name       www1       
        service_description     Total Processes
        check_command   check_nrpe_1arg!check_total_procs
}

define service{ 
        use     generic-service
        host_name       www1       
        service_description     Current Load
        check_command   check_nrpe_1arg!check_load
}

说明

1、插件的命令全部放在/usr/lib/nagios/plugins/下面

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------

 

2、check_nrpe_1arg 命令定义在/etc/nagios-plugins/config/check_nrpe.cfg

Ubuntu Server 14.04 安装nagios,nrpe - leaf - ------勤解万难------