Nagios 远程监控 (Linux)

 

1.  监控机 ( 10.10.10.145 ubuntu 14.04 已配置好 nagios )

2.  被监控机 ( 10.10.10.146 ubuntu server 14.04  64bit )

 

被监控端 ( 146 )

 

写道
1. 安装 nagios-plugins

sudo apt-get install nagios-plugins

2. 安装 nagios-nrpe-server

sudo apt-get install nagios-nrpe-server
写道
3. 修改 /etc/nagios/nrpe.cfg  二处修改
3.1
找到

allowed_hosts=127.0.0.1

修改为

allowed_hosts=127.0.0.1,10.10.10.145       #10.10.10.145 即为控制端IP
3.2  dont_blame_nrpe=0 修改为 dont_blame_nrpe=1  
3.3 
然后重启服务

sudo /etc/init.d/nagios-nrpe-server restart

 

监控端 (145)

写道
1. 安装 nagios-nrpe-plugin

sudo apt-get install nagios-nrpe-plugin
写道
2. 测试是否能连上


xiaofei@xiaofei-O-E-M:/usr/lib/nagios/plugins$ ./check_nrpe -H 10.10.10.146
NRPE v2.15

 

 -----------------     安静的美男子分割线  ---------------------

 

正常情况下, 在  /etc/nagios-plugin/config 下已存在 check_nrpe.cfg文件 , 该文件对 check_nrpe 命令进行了定义,如果没有,可以按以下方式进行添加 

 

添加 check_nrpe 命令

 

写道
sudo vim /etc/nagios3/commands.cfg

## check_nrpe
define command{
        command_name      check_nrpe
        command_name      $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

 

好了,让我们来试试怎么对 146 机器 进行一些监控吧

 

写道
cd /etc/nagios3/conf.d/

sudo vim u146.cfg

添加以下代码

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

# Zombie Processes
define service{
    use                              generic-service
    host_name                  10.10.10.146
    service_description     Zombie Processes
    check_command         check_nrpe_1arg!check_zombie_procs
}


# Disk
define service{
    use                            generic-service
    host_name                10.10.10.146
    service_description   Disk vda1
    check_command       check_nrpe_1arg!check_vda1
}


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

 

注意上面的命令  check_load , check_vda1 , check_total_procs  ..... 它们在哪里定义了的呢...

 

我们去到被控端  146 这台机器    

写道
cd /etc/nagios/

vim nrpe.cfg

# Note: Any plugins that are used in the command lines must reside
# on the machine that this daemon is running on! The examples below
# assume that you have plugins installed in a /usr/local/nagios/libexec
# directory. Also note that you will have to modify the definitions below
# to match the argument format the plugins expect. Remember, these are
# examples only!


# The following examples use hardcoded command arguments...

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_vda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/vda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

 

 

 

 **   check_mysql 可以监控mysql状态  ,  check_tcp , check_udp可以监控端口状态 ** 就不一一举例了

 

-------------   再次的华丽的美男子分割线   ----------------------------

 

nagios-plugin 自带了很多的服务,但我们发现,有些关键服务并没有提供,比如cpu使用情况 ,内存使用情况 , memcached缓存使用情况 等 等 ,这时候就需要我们自己来创建 了

 

 http://exchange.nagios.org/directory/Plugins  这里有各种各样的监控插件,选择合适的

 

放到被监控机的 /usr/lib/nagios/plugins下即可,记得要修改一下文件权限...

 

然后回到 /etc/nagios/nrpe.cfg中,添加 [command] 命令即可....

 

如:

command[check_mem]=/usr/lib/nagios/plugins/check_mem.pl -w 10 -c 5 -f -U

command[check_memcached]=/usr/lib/nagios/plugins/check_memcached.py -H localhost -p 11211 

猜你喜欢

转载自xiaolin0199.iteye.com/blog/2158579