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

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

[复制链接]

尚未签到

发表于 2019-1-15 11:20:10 | 显示全部楼层 |阅读模式
Nagios简介

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

  • 监控主机资源和网络服务

  • 允许用户通过设计实现简单的插件来监控自己特定的服务

  • 当被监控对象出现问题时,会及时通知管理人员

  • 事先定义事件处理程序,当对象出现问题时自动调用对应的处理程序

  • 通过 web 页面来监视对象状态,警告提示和日志文件。

需要安装软件列表
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"


# 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


Alias /nagios "/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

基本上这个文件可以直接使用,所以直接复制过去
[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/ 跳出以下窗口







运维网声明 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-663540-1-1.html 上篇帖子: nagios监控mfs脚本 下篇帖子: PNP 实现nagios图形分析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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