nagios安装配置

1.安装篇

我使用的yum安装,

nagios服务器:

  807  yum install trace
  808  yum install trace -y
  822  yum search nagios
  823  yum install gcc glibc glibc-common gd gd-devel xinetd openssl-devel
  824  yum search nagios
  825  yum install nagios
  835  yum search nagios-plugins
  836  yum install -y  nagios-plugins
  837  yum install -y  nagios-plugins-all
  839  yum install httpd
  840  yum install php
  841  yum install mysql
  842  yum search  mysql
  843  yum install mysql-server  mysql
  884  yum install nrpe -y
  912  yum install nagios-plugins-all -y
  913  yum search nagios
  918  yum install *nrpe*
nagios客户端:

246  yum search nrpe
  247  yum install nrpe -y
  328  yum install nagios-plugin
  329  yum search nagios
  330  yum install nagios-plugins-all -y
  341  yum install nrpe*
  356  yum install *nrpe*
  406  yum install gcc glibc glibc-common gd gd-devel xinetd openssl-devel
  453  history |grep yum
2.配置:

nagios 服务端配置

找到nagios.cfg ,我的是在/etc/nagios/目录下面,其实这里不需要配置什么

nagios服务器本身也是自己的客户端,在/etc/nagios下面有一个nrpe.cfg,可以修改下他

# ALLOWED HOST ADDRESSES
# This is an optional comma-delimited list of IP address or hostnames 
# that are allowed to talk to the NRPE daemon. Network addresses with a bit mask
# (i.e. 192.168.1.0/24) are also supported. Hostname wildcards are not currently 
# supported.
#
# Note: The daemon only does rudimentary checking of the client's IP
# address.  I would highly recommend adding entries in your /etc/hosts.allow
# file to allow only the specified host to connect to the port
# you are running this daemon on.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd

allowed_hosts=127.0.0.1,192.168.74.141
这里主要添加了nrpe客户端所允许的服务端。
3.启动nagios和客户端nrpe

nagios server  

[root@Git nagios]# /etc/init.d/nagios stop
Stopping nagios: done.
[root@Git nagios]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: No lock file found in /var/run/nagios.pid
Starting nagios: done.

nrpe client 并查看是否启动

[root@Front1 ~]# /etc/init.d/nrpe restart
Shutting down nrpe:                                        [  OK  ]
Starting nrpe:                                             [  OK  ]
[root@Front1 ~]# netstat -ltp|grep nrpe
tcp        0      0 *:5666                      *:*                         LISTEN      20941/nrpe          
[root@Front1 ~]# 

测试nagios server和nrpe的链接情况

server端nrpe测试

[root@Git nagios]# /usr/lib/nagios/plugins/check_nrpe -H 192.168.74.238
NRPE v2.14
[root@Git nagios]# /usr/lib/nagios/plugins/check_nrpe -H 127.0.0.1
NRPE v2.14
[root@Git nagios]# 
成功会出现版本号

client测试链接server

[root@Front1 ~]# /usr/lib/nagios/plugins/check_nrpe -H 192.168.74.141
CHECK_NRPE: Error - Could not complete SSL handshake.
[root@Front1 ~]# /usr/lib/nagios/plugins/check_nrpe -H 127.0.0.1
NRPE v2.14
[root@Front1 ~]# 

有错误,为啥呢?因为server端的nrpe all_hosts里面没有client的ip,填上就好了。

这时候打开
http://192.168.74.141/nagios/   用户名nagiosadmin 密码nagiosadmin

192.168.74.141是我nagiosserver的ip

这时候是看不到客户端的信息的。因为你根本没有把客户端加进去

4.让nagios server识别client

server端查看:

[root@Git objects]# ll
total 56
-rw-rw-r-- 1 root root  7704 Aug 31 06:28 commands.cfg
-rw-rw-r-- 1 root root  2166 Aug 31 06:28 contacts.cfg
-rw-r--r-- 1 root root  4821 Dec 30 21:50 front.cfg
-rw-r--r-- 1 root root  5403 Dec 30 21:49 localhost.cfg
-rw-rw-r-- 1 root root  3124 Aug 31 06:28 printer.cfg
-rw-rw-r-- 1 root root  3293 Aug 31 06:28 switch.cfg
-rw-rw-r-- 1 root root 11158 Aug 31 06:28 templates.cfg
-rw-rw-r-- 1 root root  3208 Aug 31 06:28 timeperiods.cfg
-rw-rw-r-- 1 root root  4019 Aug 31 06:28 windows.cfg
[root@Git objects]# pwd
/etc/nagios/objects
[root@Git objects]# 

默认的是没有 front.cfg的,这个是我新添加的内容见下面

下面配置文件的host_name alias 自定义,我用的是hostname ,ip 不要写错了。

define host{
        use                     linux-server            ; Name of host template to use
							; This host definition will inherit all variables that are defined
							; in (or inherited by) the linux-server host template definition.
        host_name              Front1.Webserver 
        alias                  Front1.Webserver
        address                192.168.74.238
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             PING
	check_command			check_ping!100.0,20%!500.0,60%
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             Root Partition
	check_command			check_local_disk!20%!10%!/
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             Current Users
	check_command			check_local_users!20!50
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             Total Processes
	check_command			check_local_procs!250!400!RSZDT
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             Current Load
	check_command			check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             Swap Usage
	check_command			check_local_swap!20!10
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             SSH
	check_command			check_ssh
	notifications_enabled		0
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Front1.Webserver
        service_description             HTTP
	check_command			check_http
	notifications_enabled		0
        }
到这里还有完成

需要修改nagios.cfg,添加信息

# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/etc/nagios/objects/commands.cfg
cfg_file=/etc/nagios/objects/contacts.cfg
cfg_file=/etc/nagios/objects/timeperiods.cfg
cfg_file=/etc/nagios/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
cfg_file=/etc/nagios/objects/front.cfg
cfg_file=/etc/nagios/objects/localhost.cfg
#cfg_dir=/etc/nagios/objects/hosts
查找关键字

[root@Git nagios]# grep -E 'localhost|front' nagios.cfg 
cfg_file=/etc/nagios/objects/front.cfg
cfg_file=/etc/nagios/objects/localhost.cfg
admin_email=nagios@localhost
admin_pager=pagenagios@localhost
[root@Git nagios]# pwd
/etc/nagios
[root@Git nagios]# l

这样就OK了.其实就是加一个节点,然后告诉nagioserver我添加了一个新的节点。

以上就是我配置的。

问题来了,如果我有100个机器,那么objects目录岂不是非常的乱。怎么解决?我看了这个文档,写的很清楚,亲自实践了,成功了,上面的hosts注释的那个就是看了他的配置

链接:http://blog.chinaunix.net/uid-21926461-id-3713609.html

-----------------------------------------------------------------------------------------------------------------------------------

define hostgroup{
    hostgroup_name    linux-server
    alias               Linux Server
    members             localhost,Front1.Webserver
}

hostgroup里面的members 一定要和 节点里面的host_name 一样。




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值