Cacti+Nagios完全攻略(二)nagios配置安装

发布时间:2020-06-06 15:52:50 作者:yeyu8011
来源:网络 阅读:811
Nagios简介
 
      Nagios是一个用来监视系统和网络的开源应用软件,它通常运行于一个主服务器上,这个服务器运行 Liunx 或 Unix 操作系统。Nagios 利用其众多的插件实现对本机和远端服务的监控,当被监控对象出现异常,Nagios 就会及时给管理人员告警。它是一个基于TCP/IP协议的软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,也可以通过自定义 shell 脚本进行监控服务,非常适合各类企业的网络应用。
       Nagios功能非常强大,它可以监控服务和主机,但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,nagios自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成。nagios安装,是指基本平台,也就是nagios软件包的安装。它是监控体系的框架,也是所有监控的基础。
       打开nagios官方的文档,会发现nagios基本上没有什么依赖包,只要求系统是linux或者其他nagios支持的系统。不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。
   
Nagios 系统的特点主要有下面几点:
 
需要安装软件列表
 
nagios-3.2.0.tar.gz
php-devel-5.1.6-39.el5_8.rpm
php-json-ext-1.2.1.tar.bz2
 
 

开启系统sendmail服务
 在nagios监控服务器上开启sendmail服务的主要作用是让nagios在检测到故障时可以发送报警邮件,目前几乎所有的linux发行版本都默认自带了sendmail服务,所以,在安装系统时只需开启sendmail服务即可,并且不需要在sendmail上做任何配置。

 

Nagios安装
1、 创建nagios用户和组
[root@cacti-qmail nagios-3.2.0]# useradd nagios
[root@cacti-qmail nagios-3.2.0]#mkdir /usr/local/nagios
[root@cacti-qmail nagios-3.2.0]#chown nagios.nagios /usr/local/nagios
 
2、安装nagios
[root@cacti-qmail soft]# wget http://ncu.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.1/nagios-3.2.0.tar.gz 
[root@cacti-qmail soft]# tar -zxvf nagios-3.2.0.tar.gz 
[root@cacti-qmail soft]#cd nagios-3.2.0
[root@cacti-qmail nagios-3.2.0]# ./configure --prefix=/usr/local/nagios
[root@cacti-qmail nagios-3.2.0]#make all
 
输入make all 得到下面具体信息
 
==============================================================
 
*** Compile finished ***
 
If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
 
 make install
     - This installs the main program, CGIs, and HTML files
   
    使用make install来安装主程序,CGI和HTML文件
 
 make install-init
     - This installs the init script in /etc/rc.d/init.d
 
    使用make install-init在/etc/rc.d/init.d安装启动脚本
 
 make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file
 
    使用make install-commandmode来配置目录权限
 
 make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios. Read the HTML documentation for more info
       on doing this. Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!
    使用make install-commandmode来安装示例配置文件,安装的路径是/usr/local/nagios/etc
 
 make install-webconf
     - This installs the Apache config file for the Nagios
       web interface
   使用make install-webconf来安装apache的配置文件
 
=================================================================
 
make install出现以下错误是因为没有创建nagios用户及组并且赋权
=================================================================
cd ./base && make install
make[1]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'
make install-basic
make[2]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install: invalid user `nagios' 非法用户nagios
make[2]: *** [install-basic] Error 1
make[2]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'
make: *** [install] Error 2
=====================================================================
 
 
[root@cacti-qmail nagios-3.2.0]#make all
[root@cacti-qmail nagios-3.2.0]#make install && make install-init && make install-commandmode && make install-config && make install-webconf
验证程序是否被正确安装
  切换目录到安装路径(这里是/usr/local/nagios),看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:
bin Nagios执行程序所在目录,nagios文件即为主程序
etc Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
sbin Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share Nagios网页文件所在的目录
Var Nagios日志文件、spid 等文件所在的目录
修改nagios页面文件
[root@cacti-qmail nagios-3.2.1]# more /etc/httpd/conf/nagios.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
 
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
 
<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
 
Alias /nagios "/usr/local/nagios/share"
 
<Directory "/usr/local/nagios/share">
# SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>
基本上这个文件可以直接使用,所以直接复制过去
[root@cacti-qmail nagios-3.2.1]# cp /etc/httpd/conf/nagios.conf  /var/www/html/
生成nagios页面访问账号
根据这个配置文件中指定的AuthUserFile项,它指定的是通过Apache访问Nagios的合法用户的帐户名单库文件,需要使用htpasswd命令对这个名单库进行用户的添加。而默认安装环境下在/usr/local/nagios/etc/目录下是没有 htpasswd.uses这个文件的,所以需要手动添加。请特别注意,用root身份建立的htpasswd.user文件的权限问题,应该在建立该文件完毕后立即更改为nagios用户nagios组的所有权
 
[root@cacti-qmail ~]# touch /usr/local/nagios/etc/htpasswd.users
 
建立Nagios的网页访问用户帐户文件(这里必须要与Nagios网页配置文件当中AuthUserFile指定的路径文件名一致)
 
[root@cacti-qmail ~]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users  killer
New password:
Re-type new password:
Adding password for user killer
 
[root@cacti-qmail nagios-3.2.0]# cat /usr/local/nagios/etc/htpasswd.user                         
killer:HbfEis6w0gKqI
 
修改nagios主配置文件 
[root@cacti-qmail nagios-3.2.0]# vi /usr/local/nagios/etc/nagios.cfg
log_file=/usr/local/nagios/var/nagios.log( 默认无nagios.log文件,需要手动创建)
command_check_interval=15s
#command_check_interval=-1
设定命令检查的时间间隔,将原来值-1的项注释掉,启用原来备用值为15s(15秒)。这项的时间间隔值请按实际需求情况设定。
[root@cacti-qmail nagios-3.2.0]# touch /usr/local/nagios/var/nagios.log   
[root@cacti-qmail nagios-3.2.0]# chown nagios.nagios /usr/local/nagios/var/nagios.log    
NagiosCGI配置文件                      
[root@cacti-qmail nagios-3.2.0]# vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 (默认是启动身份验证)
设定启用身份验证
authorized_for_system_information=killer
设定系统信息的授权用户
authorized_for_configuration_information=killer
设定配置信息的授权用户
authorized_for_system_commands=killer
设定系统命令的授权用户
authorized_for_all_services=killer
设定全部监测服务的授权用户。
authorized_for_all_hosts=killer
设定全部被监测主机的授权用户
authorized_for_all_service_commands=killer
设定全部监测服务命令的授权用
authorized_for_all_host_commands=killer
设定全部主机命令的授权用户

apache关于nagios 的配置

 

将apache的运行用户加到nagios组里面,从httpd.conf中过滤出当前的apache运行用户
grep "User" /etc/httpd/conf/httpd.conf
usermod -G nagios apache  
或者 直接把User和Group 都改为nagios
User  nagios
Group nagios
 
vim /etc/httpd/conf/httpd.conf
 然后找到
DirectoryIndex index.html index.html.var
修改为
DirectoryIndex index.html index.php
接着增加如下内容:
AddType application/x-httpd-php .php
测试nagios是否成功
设置nagios为开机启动
[root@cacti-qmail ~]#chkconfig nagios on
[root@cacti-qmail ~]# service nagios start
测试nagios是否成功启动
在IE输入 http://192.168.100.1/nagios/ 跳出以下窗口

Cacti+Nagios完全攻略(二)nagios配置安装 Cacti+Nagios完全攻略(二)nagios配置安装

 
 
推荐阅读:
  1. nagios配置安装
  2. Cacti+Nagios(七):Nagios监控windows(基于check_nt)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nagios ct nagios监控

上一篇:MongoDB帮助信息:db方法,collection方法

下一篇:docker:更换docker的pull源,轻松pull

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》