您的位置:首页 > 移动开发 > IOS开发

Nagios搭建与配置详解

2013-05-24 13:46 363 查看
Nagios搭建与配置详解系统平台:系统版本详细信息:Red Hat Enterprise Linux Server release 5.5 (Tikanga)内核版本信息:Linux 2.6.18-194.el5使用的软件包:1,httpd2,php3,nagios-3.2.3.tar.gz4,nagios-plugins-1.4.1.tar.gz安装次序:1,2,3,4安装步骤:由于安装步骤比较常规,所以这里说一下各个包在安装时候注意的事项。1,安装rpm包rpm -ivh httpd-* php-*2,安装nagios安装nagios前,需要新建nagios用户,否则安装时会报错。useradd nagiosusermod -G nagios apache编译前的配置 ./configure --prefix=/usr/local/nagios编译:make all安装: make install安装主要的程序、CGI及HTML文件make install-commandmode 给外部命令访问nagios配置文件的权限make install-config 把配置文件的例子复制到nagios的安装目录make install-init把nagios做成一个运行脚本,使nagios随系统开机启动make install-webconf创建naigos网页配置文件验证:切换目录到安装路径(这里是/usr/local/nagios),看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:
binNagios执行程序所在目录,这个目录只有一个文件nagios
etcNagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
sbinNagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
ShareNagios网页文件所在的目录
VarNagios日志文件、spid 等文件所在的目录
3,安装nagios插件编译前的配置: ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios &&make && make install验证:cd /usr/local/nagios/libexec ; lschown nagios.nagios /usr/local/nagioschown -R nagios.nagios /usr/local/nagios/libexec配置过程指定的安装路径是/usr/local/nagios,而不是/usr/local/nagios-plus,安装完成后,将在目录/usr/local/nagios生成目录libexec(里面有很多文件),这正是nagios所需要的。监控软件nagios-扩展NRPE功能和意义基本的Nagios 监测服务只能是本地系统监测以及对远程主机的连通性监测。为了使Nagios的监测服务器能够远程对被监测主机系统上的信息进行获取,比如远程系统上的进程数、磁盘空间使用状况、所运行的服务等等这些必须要登录远程主机系统上才能了解的信息的话,就必须要依靠NRPE这个核心扩展插件程序,NRPE作为中间的代理程序,扮演着一手接受着Nagios监测服务器发来的请求,另一手在远程主机系统上获取指定的信息的中间人角色。NRPE工作方式如以上提到的实现Nagios对远程系统的监测,那么首先必须要在被监测的远程主机上除了安装Nagios-plugins插件程序之外还必须安装NRPE 核心扩展插件程序,并将NRPE在被监测的远程主机系统上以守护进程的方式运行起来,开放指定的NRPE监听端口监听着Nagios监测服务器发送过来的所有监测请求。另外,在Nagios监测服务器上,在必须要安装Nagios-plugins插件程序和NRPE核心扩展插件程序。唯一不同的是, Nagios监测服务器不需要将NRPE作为守护进程运行着,因为它本身一般不需要被别人监测着而是去监测别人,对Nagios监测服务器而言,它只需要使用到Nagio-plugins插件程序和NRPE扩展插件程序就足够了安装nrpe:nrpe的安装非常简单,只需要执行常规的安装步骤就可以安装成功。./configuremake allmake install-pluginmake install-daemonmake install-daemon-configmake install-xinetd相关文件的修改service xinetd restart
netstat -at | grep nrpetcp 00 *:nrpe *:*LISTEN配置步骤:
一,配置apache1,编写测试php网页:vi /var/www/html/test.php<?phpinfo();?>测试:http://Ip/test.php看能否出来php说明文字如果没有成功则配置apache支持.php网页编辑/etc/httpd/conf/httpd.conf添加AddType application/x-httpd-php.php添加AddType application/x-httpd-php-source.phps找DirectoryIndex字样修改为:DirectoryIndex index.html index.php index.htm2,配置apache虚拟主机查看/etc/httpd/conf.d/nagios.conf文件,如果文件存在则无需编辑,否则进行如下编辑#setting for nagiosScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin<Directory "/usr/local/nagios/sbin">//Cgi文件所在目录AuthType BasicOptions ExecCGIAllowOverride NoneOrder allow,denyAllow from allAuthName "Nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswd//验证文件路径Require valid-user</Directory>Alias /nagios /usr/local/nagios/share<Directory "/usr/local/nagios/share">//nagios页面文件目录AuthType BasicOptions NoneAllowOverride NoneOrder allow,denyAllow from allAuthName "nagios Access"AuthUserFile /usr/local/nagios/etc/htpasswd//验证文件路径Require valid-user</Directory>生成用户验证文件及web合法访问用户nagiosadmin,执行命令:
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
如要添加更多的用户,不要使用“-c”,否则会覆盖所有生成的行。
重启apache
/usr/local/apache/bin/apachectl restart
启动nagios
/etc/init.d/nagios start
此时就可以访问nagios了。
没有问题的话,进行nagios进一步的配置。
二,配置nagios因为/usr/local/nagios-plus没有关于内存,cpu及uptime的监控,所以需要将脚本拷贝的nagios-plus目录下,并设置相应的配置文件。

1)编辑/usr/local/nagios/etc/nrpe.cfg添加command[check_mem]=/usr/local/nagios/libexec/check_mem -w 20 -c 15
command[check_cpu.sh]=/usr/local/nagios/libexec/check_cpu.sh -w 20 -c 15
command[check_uptime.sh]=/usr/local/nagios/libexec/check_uptime.sh -w 20 -c 15

2) 编辑/usr/local/nagios/etc/objects/commands.cfg#nrpe set
define command{
command_name check_nrpe#定义的命令名就叫作check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#说明:#$USER1$/check_nrpe会通过引用resource.cfg里的函数$USER1$获得#/usr/local/nagios/libexec/check_nrpe这个绝对路径。#-H $HOSTADDRESS$ 用来获得指定被监测主机的IP地址,$HOSTADDRESS$变量会#通过定义主机名查找到host段中的IP地址。#-c $ARG1$ 用来指定被监测主机上NRPE守护进程运行着的NRPE命令名。define command{
command_name check_mem
command_line $USER1$/check_mem -w $ARG1$ -c $ARG2$
}
define command{
command_name check_cpu.sh
command_line $USER1$/check_cpu.sh -w $ARG1$ -c $ARG2$
}
define command{
command_name check_uptime.sh
command_line $USER1$/check_uptime.sh -w $ARG1$ -c $ARG2$

修改nagios主配文件/usr/local/nagios/etc/nagios.cfg
反注释cfg_file=/usr/local/nagios/etc/objects/host.cfg此条指定nagios的配置文件路径。
配置host.cfg文件
define host{
host_name Nagios-Server
alias Nagios Server
address 127.0.0.1
check_command check-host-alive
check_interval 5
max_check_attempts 5
retry_interval 1
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}

define host{
host_name Cacti-Server
alias Cacti Server
address 10.2.5.130
check_command check-host-alive
check_interval 5
max_check_attempts 5
retry_interval 1
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}

配置services.cfg文件,监控的项目有:查看主机存活(网络ping),ssh服务,内存使用量,硬盘或目录使用率,当前用户登录数,cpu使用率,系统负载,系统运行时间,进程数等
若有多个主机,复制此配置文件只将host_name更改一下即可。
define service {
host_name Nagios-Server
service_description check-host-alive
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
check_command check-host-alive
}

define service {
host_name Nagios-Server
service_description check-mem
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
check_command check_nrpe!check_mem
}

define service {
host_name Nagios-Server
service_description check-disk
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
check_command check_nrpe!check_sda3
}

define service {
host_name Nagios-Server
service_description check-users
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
check_command check_nrpe!check_users
}

define service {
host_name Nagios-Server
service_description check-load
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
check_command check_nrpe!check_load
}

define service {
host_name Nagios-Server
service_description check-cpu
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
check_command check_nrpe!check_cpu.sh
}

define service {
host_name Nagios-Server
service_description check-uptime
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
check_command check_nrpe!check_uptime.sh
}

define service {
host_name Nagios-Server
service_description check-total-procs
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
check_command check_nrpe!check_total_procs
}

define service{
uselocal-service; Name of service template to use
host_nameNagios-Server
service_descriptionSSH
check_commandcheck_ssh
notifications_enabled0
}

配置文件检查命令:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启nagios服务:
/etc/init.d/nagios restart
/etc/init.d/httpd restart
验证:
再次打开http://ip/nagios确认配置已经生效。

配置服务开机启动
chkconfig --add nagioschkconfig nagios onchkconfig --level 35 httpd on
注:用nagios监控windows机器,需要在被监控的机器上安装NSClient软件。
被监控端的安装配置首先为被监控端准备nagios-pluginsnrpe的安装包。添加用户nagios:usraddnagios我的安装包放在/usr目录下面;cd/usrtar xzvf nagios-plugins-XXX.tar.gzcd nagios-plugins-XXX./configure --prefix=/usr/local/nagiosmakemake install./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios &&make && make installchown nagios.nagios /usr/local/nagioschown -R nagios.nagios /usr/local/nagios/libexec再在被监控主机上安装NRPE扩展插件程序:tar -zxvf nrpe-xxx.tar.gzcd nrpe-xxx./configuremake allmake install-pluginmake install-daemonmake install-daemon-configmake install-xinetd相关文件的修改vi/etc/xinetd.d/nrpeonly_from= 127.0.0.1 10.2.5.130(注意,10.2.5.130监控服务器的IP,也就是所允许10.2.5.130来监控本机的服务)vi/etc/servicesnrpe5666/tcp# NRPE(添加一行)service xinetd restart如果配置没有问题的话,输入如下命令。查看配置是否配好netstat -at | grep nrpetcp 00 *:nrpe *:*LISTEN找到NRPE运行的执行程序ll /usr/local/nagios/bin/nrpe-rwxrwxr-x 1 nagios nagios 93420 Oct7 01:16 /usr/local/nagios/bin/nrpe了解NRPE的执行程序的使用方式/usr/local/nagios/bin/nrpe -h测试NEPE本地是否正常启动/usr/local/nagios/libexec/check_nrpe –Hlocalhost如果正确的话,回返回NRPE的版本号将NRPE运行添加加入系统启动脚本中echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.d/rc.local到此,被监控主机要做的工作已经完成了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息