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

Red Hat Enterprise Linux 5.5 下安装配置 Nagios

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-8 09:47:31 | 显示全部楼层 |阅读模式
  Nagios是一款多功能的开源网络监控工具, 由于它是以插件程序为导向,因此可以用来监控网络中的各种操作系统和设备。而如果没有可用的插件,它也会自动退回到SNMP(简单网络管理协议)标准,这也使Nagios得使用范围大大增加。在基础配置下,你可以创建一台Nagios主机来对同一网络中的各个节点进行监控。
  Nagios工具对服务器的要求不是很高。如果你想监控100个以内的节点,几乎任何服务器都可以满足其需求。而如果你想用它来监控成千上万个节点,对服务器的要求就略高一些。要求服务器拥有多个CPU核,2GB的RAM以及大约40GB以上的硬盘空间。
  
  1. Nagios的安装:
  启用Nagios需要以下几个模块:
  Apache2
Php5

GCC编译器与开发库

GD库与开发库

本例中会按照以下规则进行安装:

       Nagios和插件将安装到/usr/local/nagios

       Nagios将被配置为监控本地系统的几个主要服务(http,ping等)

       Nagios的Web接口是URL是http://localhost/nagios/

安装apach2,php5(如果已经装了apahce可跳过此步):安装可参考Red Hat Enterprise Linux 5.5 下安装最新Apache2.2.16+PHP5.3.3+GD2


一:配置服务器端:
1.添加用户:
#useradd nagios
#usermod -s /sbin/nologin nagios
#groupadd nagcmd
#usermod -G nagcmd nagios
#usermod -G nagcmd apache

2.安装nagios-3.1.0
tar xzvf nagios-3.2.2.tar.gz
cd nagios-3.2.2
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf(设置apache的conf目录) --with-gd-lib=/usr/local/gd2/lib(设置gd的lib目录) --with-gd-inc=/usr/local/gd2/include(设置gd的include目录)
P.S. 这里是假设APACHE安装在/usr/local/apache;GD库安装在/usr/local/gd2的情况下.如果GD为yum自动安装可改为 --with-gd-lib=/usr/lib --with-gd-inc=/usr/include 如果提示找不到GD就 yum install gd; yum install gd-devel;


make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf (可以自动设置httpd.conf)

  3.安装nagios-plugins-1.4.13:
tar xzvf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround --prefix=/usr/local/nagios
make
make install
4.cat /usr/local/apache/conf/nagios.conf >> /usr/local/apache/conf/httpd.conf(把nagios的配置接到httpd.conf文件后面)

5. 配置Nagios管理员接受告警信息的邮箱,写入管理员邮箱
      # vi /usr/local/nagios/etc/objects/contacts.cfg
      email    admin@admin.com   ;  
      ——校验Nagios配置文件,验证配置是否有误
      #/usr/local/nagios/bin/nagios -v

  ——启动Nagios,配置在系统启动时运行Nagios
           #chkconfig --add nagios
           #chkconfig nagios on
           #chkconfig httpd on
  ——运行Nagios
           #service nagios start
  6.添加用户:
  /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  输入密码
  7.service httpd restart                      //启动apache服务器
  http://localhost/nagios 登陆到Web界面,输入用户名:nagiosadmin ,密码:”设置的密码 “就可以看到nagios的界面了。
  8.改check_external_commands=0为check_external_commands=1 这行的作用是允许执行在web界面下重启nagios、停止主机/服务检查等操作。把command_check_interval的值从默认的1改成command_check_interval=10s(根据自己的情况定这个命令检查时间间隔,不要太长也不要太短)。
  第二个要修改的配置文件是cgi.cfg,它的作用是控制相关cgi脚本,先确保use_authentication=1。曾看过不少的文章,都是建议把use_authentication的值设置成”0”来取消验证,这是一个十分糟糕的想法。default_user_name=xxx
  如果需要创建多用户:
  /usr/local/apache/bin/htpasswd /usr/local/nagios/etc/htpasswd xxx
  修改 etc/cgi.cfg



authorized_for_system_information=nagiosadmin,xxx
authorized_for_configuration_information=nagiosadmin,xxx
authorized_for_system_commands=xxx //多个用户之间用逗号隔开
authorized_for_all_services=nagiosadmin,xxx
authorized_for_all_hosts=nagiosadmin,xxx
authorized_for_all_service_commands=nagiosadmin,xxx

  然后etc/objects/contacts.cfg:修改监视管理员的联系方式,以及通知方式,下面的添加模板.



define contact {
contact_name         xxx
alias                system administrator
service_notification_period    24x7
host_notification_period       24x7
service_notification_options   w,u,c,r
host_notification_options       d,u,r
service_notification_commands  service-notify-by-email
host_notification_commands     host-notify-by-email(邮件)
email                         xxx.hotmail.com
}<BR>

  
  服务通知选项(service_notification_options)与主机通知选项(host_notification_options)的几个选项在这里说明一下:w-warning,u-unknown,c-critical,r-recovery;d-down,u-unreachable,注意一下,主机报警和服务报警有些差异。
  nagios也为我们准备了一个配置全局模板的地方:



define contact {

use  generic-contact

}

  这表示这里是该用户应用了etc/objects/templates.cfg 里面的,修改此处可以更改全局的联系方式:



define contact{
name                            generic-contact        ; The name of this contact template
service_notification_period     24x7                        ; service notifications can be sent anytime
host_notification_period        24x7                         ; host notifications can be sent anytime
service_notification_options    w,u,c,r,f,s                 ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options       d,u,r,f,s           ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands   notify-service-by-email     ; send service notifications via email
host_notification_commands      notify-host-by-email        ; send host notifications via email
register                        0                      ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}

  
  同时contacts.cfg也为我们准备了contactgroup的修改可以方便我们对管理员分类
  接下来是最关键的host(监控机器)相关的配置.
  Nagios为我们准备了一个sample:etc/objects/localhost.cfg
  下面是我自己监控局域网内的某台机器的实例,IP:192.168.2.217
  vi /usr/local/nagios/etc/objects/1921682217.cfg



define host{
use                   linux-server
host_name             1921682217
alias                 1921682217
address               192.168.2.217
}
define service{
use                   generic-service         ; Name of service template to use
host_name            1921682217
service_description     HTTP
check_command           check_http
notifications_enabled    0
}

  
  其他配置文件功能:
etc/objects/commands.cfg:这个文件的主要功能是用来发送报警短信和报警邮件.
etc/objects/timeperiods.cfg:修改监控时间,默认是7*24小时监控.
  8.echo "cfg_file=/usr/local/nagios/etc/objects/1921682217.cfg" >> /usr/local/nagios/etc/nagios.cfg (将配置文件include到主配置文件里)
  9.启动相关服务:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检查配置文件是否正确
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg //手动启动nagios
/usr/local/nagios/bin/nagios -s /usr/local/nagios/etc/nagios.cfg //评估启动时间
/etc/init.d/nagios start //启动
/etc/init.d/nagios reload //重启

运维网声明 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-110935-1-1.html 上篇帖子: Nagios-配置版 下篇帖子: nagios监控网卡流量
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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