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

Nagios系统监控软件的安装设置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-3-19 13:30:18 | 显示全部楼层 |阅读模式
Nagios是一款开源的免费监控软件,能很好的监控Windows、Linux和Unix的主机状态,交换机、路由器等网络设备等。相信很多朋友都有用过这个软件,下面把我的安装使用过程中拿出来和大家分享一下,有不足之处希望大家指正。



安装环境: RedHat 5.5 x86_64bit
一、主监控机系统的安装
1、建目录用户与授权:
[iyunv@localhost ]# groupadd nagios
[iyunv@localhost ]# useradd -g nagiosnagios
[iyunv@localhost ]# mkdir /usr/local/nagios
[iyunv@localhost ]# chown nagios:nagios /usr/local/nagios

2、解压与安装:(下载地址:http://sourceforge.net/projects/nagios/files/)
[iyunv@localhost ]# tar -zxvf nagios-3.2.3.tar.gz
[iyunv@localhost ]# cd nagios-3.2.3
[iyunv@localhost ]# ./configure
[iyunv@localhost ]# make all
[iyunv@localhost ]# make install
[iyunv@localhost ]# make install-init
[iyunv@localhost ]# make install-commandmode
[iyunv@localhost ]# make install-config

3、安装相关插件:(下载地址:http://www.nagios.org/download/plugins/)
[iyunv@localhost ]# tar -zxvf nagios-plugins-1.4.15.tar.gz
[iyunv@localhost ]# cd nagios-plugins-1.4.15
[iyunv@localhost ]# ./configure
[iyunv@localhost ]# make && make install
[iyunv@localhost ]# ls /usr/local/nagios/libexec/(查看有无安装成功,成功会显示组件包)

4、安装apache发布器(如果之前系统未安装httpd组件的话,要新装一下相关的rpm包):
[iyunv@localhost ]# rpm -ivh apr-1.2.7-11.x86_64.rpm
[iyunv@localhost ]# rpm -ivh postgresql-libs-8.1.11-1.el5_1.1.x86_64.rpm
[iyunv@localhost ]# rpm -ivh apr-util-1.2.7-7.el5.x86_64.rpm
[iyunv@localhost ]# rpm -ivh httpd-2.2.3-22.el5.x86_64.rpm
[iyunv@localhost ]# rpm -ivh httpd-manual-2.2.3-22.el5.x86_64.rpm
(注意这上面的rpm包要按照顺序来安装)

5、配置发布器httpd.conf的参数:
[iyunv@localhost ]# vim /etc/httpd/conf/httpd.conf
(在文件内容的最底下添加)
ServerName localhost:80
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
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">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

6、添加nagios的登录用户(如nagiosadmin)
[iyunv@localhost ]# htpasswd -c /usr/local/nagios/etc/htpasswd.usersnagiosadmin
[iyunv@localhost ]# cat /usr/local/nagios/etc/htpasswd.users(说明:查看有无添加成功)

7、添加启动nagios服务:
[iyunv@localhost ]# chkconfig --add nagios
[iyunv@localhost ]# chkconfig nagios on
[iyunv@localhost ]# service nagios start

8、启动http发布服务:
[iyunv@localhost ]# service httpd start
[iyunv@localhost ]# chkconfig httpd on


9、登录页面:
(1) http://IP地址/nagios
(2) 输入登录用户名和密码
(3) 进入管理平台

注意: 如果输入用户名和密码成功登录以后,页面显示“无权访问网页”,这是因为没有安装PHP的套件,nagios的网页需要php来支持。解决办法如下:
(1) 确保linux主机或服务器能够上互联网。
(2) 执行下面的安装命令:
[iyunv@localhost ]# yum install php (说明:yum命令会先对比本机缺少的php包,然后自动从互联网上寻找,找到以后会列出来,提示你是否下载安装,这时候再点击“yes”下载过来自动安装。)


二、主监控机系统的参数配置
1、主配置文件:nagios.cfg
[iyunv@localhost ]# cd /usr/local/nagios/etc
[iyunv@localhost ]# vim nagios.cfg
(主要配置参数说明)
cfg_file=/usr/local/nagios/etc/objects/commands.cfg #监控命令配置文件
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg #联系人配置文件路径
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg #监视时段配置文件路径
cfg_file=/usr/local/nagios/etc/objects/templates.cfg #监控服务报警配置文件
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg #监控本机服务配置文件
cfg_file=/usr/local/nagios/etc/objects/windows.cfg # 监控windows机器列表的配置文件
cfg_file=/usr/local/nagios/etc/objects/linux.cfg #新增监控linux机器列表的配置文件
check_external_commands=1 #允许在web界面下执行重启nagios、停止主机/服务检查等操作,0表不启用
command_check_interval=5 #监控正常检测周期间隔时间,可以以设成10秒(10s),默认值是-1(为尽可能的快速轮询);注意这是检测周期,不是报警周期,检测周期设置一定要比服务的告警周期要小
interval_length=60 #间隔长度,默认值为60,代表基数是60秒,表示周期是1分钟
service_check_timeout=60 #服务检查时间间隔
host_check_timeout=30 #主机检查时间间隔
event_handler_timeout=30
notification_timeout=10
ocsp_timeout=5
perfdata_timeout=5
2、监控(哪些)机器的配置文件:linux.cfg
[iyunv@localhost ]# cd /usr/local/nagios/etc/objects
[iyunv@localhost ]# vim linux.cfg
define host{ ;要监控的主机定义
use linux-server ;被监控主机用途
host_name web_host ;被监控主机名称
alias It’s http server ;被监控主机别名
address 10.0.0.2 ;被监控主机IP地址
}
define hostgroup{ ;要监控的组定义
hostgroup_name remote-linuxt-server ;被监控组名称
alias linuxserver ;被监控组别名
members web_host ;被监控组成员主机名有哪些,这里不能用别名,多个成员之间用,逗号隔开
}
define service{ ;要监控的服务定义
use local-service ;服务模型,可自定义
hostname web_host ;要加入此服务的主机名称,要与上面一致。
hostgroup_name remote-linux-server ;要加入此服务的组名称,要与上面一致
service_description HTTP_port ;要监控的项目名称,可自己起
check_command check_tcp!80!0.1!0.3 ;检测命令,配置文件在commands.cfg
notifications_enabled 0 ;是否通知报告
notification_interval 10 ;发告警的时间间隔10分钟,默认单位是分钟,这行不设的话默认是1小时
}
(注意:这边的“notification_interval”报警时间间隔要与templates.cfg文件中“normal_check_interval”的时间相对应,不能小于那边设置的时间,不然会报错。normal_check_interval默认是10分钟发送报警邮件一次)
(说明:定义service服务的时候,要加入此服务的主机名称和组名称,可只设置一个,不必同时设置。
如果服务是多台主机共用的(如检测内存),可设置一个组名称。
如果服务只是某一台或几台主机用的,设置一个主机名称就可以了。)

3、命令参数配置文件:command.cfg
[iyunv@localhost ]# cd /usr/local/nagios/etc/objects
[iyunv@localhost ]# vim command.cfg

define command{
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
说明:这里的$USER1$,$ARG1$, $ARG2$, $ARG3$是什么意思呢?
(1)$USER1$是指插件路径/usr/local/nagios/libexec
(2)-w $ARG1$的参数指定磁盘剩了多少是警告状态,
(3)-c $ARG2$的参数指定剩多少是严重状态,
(4)-p $ARG3$用来指定路径目录.

在loccalhost.cfg调用命令的时候可写成“check_command check_local_disk!10%!5%!/”
在命令名后面用!分隔出了3个参数,10%是$ARG1$的值,5%是$ARG2$的值,/ 是$ARG3$的值,

4、报警联系人参数配置文件:contacts.cfg
[iyunv@localhost ]# cd /usr/local/nagios/etc/object
[iyunv@localhost ]# vim contacts.cfg
define contact{ ;联系人
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email nagios@localhost.com ;接收报警的邮件地址
}
define contactgroup{ ;联系人组
contactgroup_name admins ;联系人组名
alias Nagios Administrators ;组别名
members nagiosadmin ;组成员名单
}

5、配置完参数以后一定要重新检测是否正确

[iyunv@localhost ]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
( -v 检查配置参数 )
[iyunv@localhost ]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
( -d 后台重启服务进程 )
6、命令和插件监控
[iyunv@localhost ]# cd /usr/local/nagios/libexec
[iyunv@localhost ]# ./check_disk -h(查看磁盘情况的命令使用方法,提示:这边所有命令的使用方法都可以通过”命令名 –h”来查看)

命令使用:check_disk -w 10% -c 5% /此命令的含义是检查/分区的使用情况,若剩余10%以下,为警告状态(warning);5%以下,为严重状态(critical)。命令调用时简写成check_disk!10%!5%!/)

(小结:localhost.cfg定义监控项目用某个命令,这个命令必须在commands.cfg中定义,定义这个命令时使用了libexec下的插件)


运维网声明 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-15977-1-1.html 上篇帖子: Linux---Nagios监控出图 下篇帖子: Nagios系统监控软件的图表显示 监控软件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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