设为首页 收藏本站
查看: 1419|回复: 0

Nagios搭建与配置详解

[复制链接]

尚未签到

发表于 2019-1-14 14:36:59 | 显示全部楼层 |阅读模式
Nagios搭建与配置详解

系统平台:

系统版本详细信息:

Red Hat Enterprise Linux Server release 5.5 (Tikanga)

内核版本信息:Linux 2.6.18-194.el5

使用的软件包:

1httpd

2php

3nagios-3.2.3.tar.gz

4nagios-plugins-1.4.1.tar.gz

安装次序:1,2,3,4

安装步骤:

由于安装步骤比较常规,所以这里说一下各个包在安装时候注意的事项。

1,安装rpm

rpm -ivh httpd-* php-*

2,安装nagios

安装nagios前,需要新建nagios用户,否则安装时会报错。

useradd nagios

usermod -G nagios apache

编译前的配置 ./configure --prefix=/usr/local/nagios

编译:make all

安装: make install安装主要的程序、CGIHTML文件

make install-commandmode 给外部命令访问nagios配置文件的权限

make install-config 把配置文件的例子复制到nagios的安装目录

make install-initnagios做成一个运行脚本,使nagios随系统开机启动

make install-webconf创建naigos网页配置文件

验证:切换目录到安装路径(这里是/usr/local/nagios,看是否存在 etcbin sbin share var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:

bin

Nagios执行程序所在目录,这个目录只有一个文件nagios

etc

Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件

sbin

Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录

Share

Nagios网页文件所在的目录

Var

Nagios日志文件、spid 等文件所在的目录

3,安装nagios插件

编译前的配置: ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios &&make && make install

验证:cd /usr/local/nagios/libexec ; ls

chown nagios.nagios /usr/local/nagios

chown -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的安装非常简单,只需要执行常规的安装步骤就可以安装成功。

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd

相关文件的修改

  service xinetd restart
netstat -at | grep nrpe

tcp 00 *:nrpe *:*LISTEN

  配置步骤:
一,配置apache

1编写测试php网页:

vi /var/www/html/test.php


测试: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.htm

2,配置apache虚拟主机

查看/etc/httpd/conf.d/nagios.conf文件,如果文件存在则无需编辑,否则进行如下编辑

#setting for nagios
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
//Cgi文件所在目录
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd//验证文件路径
Require valid-user

Alias /nagios /usr/local/nagios/share
//nagios页面文件目录
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd//验证文件路径
Require valid-user

  生成用户验证文件及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没有关于内存,cpuuptime的监控,所以需要将脚本拷贝的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 nagios

chkconfig nagios on

chkconfig --level 35 httpd on

  
  注:用nagios监控windows机器,需要在被监控的机器上安装NSClient软件。
被监控端的安装配置

首先为被监控端准备nagios-pluginsnrpe的安装包。

添加用户nagios

usraddnagios

我的安装包放在/usr目录下面;

cd/usr

tar xzvf nagios-plugins-XXX.tar.gz

cd nagios-plugins-XXX

./configure --prefix=/usr/local/nagios

make

make install

./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios &&make && make install

chown nagios.nagios /usr/local/nagios

chown -R nagios.nagios /usr/local/nagios/libexec

再在被监控主机上安装NRPE扩展插件程序:

tar -zxvf nrpe-xxx.tar.gz

cd nrpe-xxx

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd

相关文件的修改

vi/etc/xinetd.d/nrpe

only_from= 127.0.0.1 10.2.5.130

(注意,10.2.5.130监控服务器的IP,也就是所允许10.2.5.130来监控本机的服务)

vi/etc/services

nrpe5666/tcp# NRPE(添加一行)

service xinetd restart

如果配置没有问题的话,输入如下命令。查看配置是否配好

netstat -at | grep nrpe

tcp 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

到此,被监控主机要做的工作已经完成了。







运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663275-1-1.html 上篇帖子: centos6.2 使用nagios nrpe监控本地与远程Linux主机 下篇帖子: The Nagios Monitoring Data written into the Mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表