43524 发表于 2015-9-30 09:27:54

nagios监控报警一般搭建过程及常见问题

l Nagios是什么l Nagios安装步骤l Nagios-plugins插件安装步骤l Nagios安装完成后启动l Nagios web访问l 常见问题l 参考资料

Nagios是什么上个星期,自己搭建了下nagios服务器,这里记录下我自己的方法心得,给新手一个指导。  Nagios是什么呢?官网是这样定义的:Nagios is a host/service/network monitoring program written in C and released under the GNU General Public License, version 2. CGI programs are included to allow you to view the current status, history, etc viaa web interface if you so desire.翻译过来是这样:Nagios是一个C编写的程序,用来监控主机/服务/网络,并且是GNU 2.0通用公共许可证下发布, CGI程序包括允许您查看当前的状态,历史记录等通过一个Web界面,如果你愿意的话。   官网所说的功能:* Monitoring of network services (via SMTP, POP3, HTTP, PING, etc). 监控网服务* Monitoring of host resources (processor load, disk usage, etc.). 监控主机资源* A plugin interface to allow for user-developed service monitoring methods. 提供一个接口,可以用于用户自定义服务监控* Ability to define network host hierarchy using "parent" hosts, allowing detection of and distinction between hosts that are down and those that are unreachable. 可以通过定义parent主机层来检测网络无法到达的主机是否在线* Notifications when problems occur and get resolved (via email, pager, or user-defined method). 通知出现的问题故障可以通过邮件或用户自定义方法* Ability to define event handlers for proactive problem resolution. 可以定义事件处理程序来主动解决问题* Automatic log file rotation/archiving. 自动日志文件循环/归档。* Optional web interface for viewing current network status, notification and problem history, log file, etc. 可选的Web界面来查看当前网络状态,通知和问题历史,日志文件,等等。

Nagios安装步骤下载地址:http://nchc.dl.sourceforge.net/p ... nagios-4.1.1.tar.gz    安装lamp,安装方法可以再看我的博客,这里就不做说明了。1.安装依赖包 yum install gcc glibc glibc-common yum install gd gd-devel unzip2.添加用户nagios,并将apache加入nagios组,为后面通过WEB访问做准备 useradd -M -s /sbin/nologin nagios && usermod -a -G nagios apache3.建立安装目录/usr/local/nagios.并改变目录用户和组权限为nagios mkdir /usr/local/nagios && chown -R nagios:nagios /usr/local/nagios4.编译nagios tar -zxvf nagios-4.1.1.tar.gz && cd nagios-4.1.1 ./configure --prefix=/usr/local/nagios--with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios--with-command-group=nagios --with-httpd-conf=/usr/local/apache2/conf.d (注意:我的环境apache是源码安装在/usr/localapache2目录,所能用了--with-httpd-conf)编译完成时当看到如下几行文字时,说明编译成功。
5.编译安装nagios  make all && make install &&make install-init &&make install-config &&make install-commandmode  (说明: make install 安装主要程序,CGI,和HTML文件 。     make install-init 安装init script 到 /etc/rc.d/init.d。     make install-config 安装 *SAMPLE* 事例配置文件到 /usr/local/nagios/etc目录 。          make install-commandmode 安装配置一些外部命令 。     make install-exfoliation 安装 Exfoliation 主题 。     make install-classicui    安装经典主题 。 )细心留意我们会发现,其实在第4步编译完成时,nagios给了我们安装的提示如图
6. 配置web访问    (非必须,没有apache,nagios照样工作,配置文件默认会安装在apache的conf.d目录 ) makeinstall-webconf 在apache的conf.d目录下多了一个nagios.conf文件,查看发现 AuthUserFile /usr/local/nagios/etc/htpasswd.users 文件。

   以上面发现的文件 创建一个nagios的web访问是的认账号yourname,并设密码。    htpasswd -c /usr/local/nagios/etc/htpasswd.users  yourname   虽然web访问已经开启了认证,但nagios配置文件cgi.cfg并不知道,所以增加yourname权限到cgi.cfg 。  sed -i 's/nagiosadmin/nagiosadmin\,nagiosuparty/g'/usr/local/nagios/etc/cgi.cfg           (注意:记住这个帐号和你输入的密码,web访问时用于认证) 
Nagios-plugins插件安装步骤    下载地址:http://www.nagios-plugins.org/do ... lugins-2.1.1.tar.gz     插件可以理解为nagios为监控某个服务功能,开发的小程序或python、shell脚本(用户可以自己开发)。   安装 nagios-plugins比较简单     ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios     make && make install        检查是否安装成功nagios-plugins插件,只要看/usr/local/nagios/libexec/ 目录是否有以check开头的文件。      
   
Nagios安装完成后启动:
1. 关闭SELINUX或者增加权限     setenforce 0        或者增加权限:    chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/    chcon -R -t httpd_sys_content_t /usr/local/nagios/share/2 .启动nagios服务。   启动前先验证下nagios配置文件的是否正确:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg      没有错误就可以启动nagios了。   设为开机启动方法:chkconfig --add nagios && chkconfig nagios on   立刻启动方法:service httpd restart
Nagios web访问: http访问:http://nagios服务器ip地址/nagios    这时由于没有对nagios配置文件做任何修改,只有localhost如下图  
常见问题   源码安装apache时,#LoadModule cgid_module modules/mod_cgid.so是注释掉的没有启用。当http访问时会出现 no running    查看nagios日志也是正常:Sep 29 15:00:32 lab05 nagios: Nagios 4.1.1 starting... (PID=2574)Sep 29 15:00:32 lab05 nagios: Local time is Tue Sep 29 15:00:32 CST 2015Sep 29 15:00:32 lab05 nagios: LOG VERSION: 2.0Sep 29 15:00:32 lab05 nagios: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initializedSep 29 15:00:32 lab05 nagios: qh: core query handler registeredSep 29 15:00:32 lab05 nagios: nerd: Channel hostchecks registered successfullySep 29 15:00:32 lab05 nagios: nerd: Channel servicechecks registered successfullySep 29 15:00:32 lab05 nagios: nerd: Channel opathchecks registered successfullySep 29 15:00:32 lab05 nagios: nerd: Fully initialized and ready to rock!Sep 29 15:00:32 lab05 nagios: wproc: Successfully registered manager as @wproc with query handlerSep 29 15:00:32 lab05 nagios: wproc: Registry request: name=Core Worker 2579;pid=2579Sep 29 15:00:32 lab05 nagios: wproc: Registry request: name=Core Worker 2578;pid=2578Sep 29 15:00:32 lab05 nagios: wproc: Registry request: name=Core Worker 2577;pid=2577Sep 29 15:00:32 lab05 nagios: wproc: Registry request: name=Core Worker 2576;pid=2576Sep 29 15:00:32 lab05 nagios: Successfully launched command file worker with pid 2580查看apache2日志时发现cgi没有开启: 编辑/uar/local/apache2/conf/httpd.conf 去掉 #LoadModule cgid_module modules/mod_cgid.so 的#号再次重启apache 访问正常。

本文是 巧妙绝情 一个字一个图打出来,参考了好多资料,感谢他们的分享,基于open source分享精神,转载请注明出出
参考资料:Nagios定义和功能:https://www.nagios.org/aboutNagios、nagios-plugins安装步骤:安装指南:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html http://nagios.sourceforge.net/docs/nagioscore/4/en/quickstart.html

页: [1]
查看完整版本: nagios监控报警一般搭建过程及常见问题