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

nagios安装配置笔记

[复制链接]

尚未签到

发表于 2015-11-23 08:24:33 | 显示全部楼层 |阅读模式
Nagios安装
概述:
Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等。
Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等。
Nagios 可以监控的功能有:
1、监控网络服务(SMTP、POP3、HTTP、NNTP、PING等);
2、监控主机资源(处理器负荷、磁盘利用率等);
3、简单地插件设计使得用户可以方便地扩展自己服务的检测方法;
4、并行服务检查机制;
5、具备定义网络分层结构的能力,用"parent"主机定义来表达网络主机间的关系,这种关系可被用来发现和明晰主机宕机或不可达状态;
6、当服务或主机问题产生与解决时将告警发送给联系人(通过EMail、短信、用户定义方式);
7、可以定义一些处理程序,使之能够在服务或者主机发生故障时起到预防作用;
8、自动的日志滚动功能;
9、可以支持并实现对主机的冗余监控;
官方网站:http://www.nagios.com/
1 环境准备
机器名    eth0    说明
server01    192.168.100.30/24    Centos 6.3 64bit
server02    192.168.100.31/24    Centos 6.3 64bit

2 安装基础支持套件和添加用户
基础依赖包安装
yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
下载nagios核心和插件包
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
为nagios添加用户
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
[iyunv@server01 opt]# id nagios   查看验证
uid=501(nagios) gid=502(nagios) groups=502(nagios),501(nagcmd)

3 nagios core安装
tar zxvf nagios-3.4.1.tar.gz
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios
./configure --with-command-group=nagcmd

make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start

为web Access创建一个默认用户
htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin
根据提示输入密码即可

4 nagios插件安装
cd /tmp/nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
nagios服务设置
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --add httpd
chkconfig --level 35 httpd on

5 nagios web登录
http://<your.nagios.server.ip>/nagios
若是开启了selinux会提示错误做如下设置
chcon  -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon  -R -t httpd_sys_content_t /usr/local/nagios/share/



6 安装nrpe
yum install openssl-devel
yum install xinetd
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz/download
tar zxf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make && make install

当被监控机器安装好了nagios以及nrpe时可用命令检查版本
[iyunv@server01 nrpe-2.14]# /usr/local/nagios/libexec/check_nrpe  -H 192.168.100.31
NRPE v2.14
配置文件说明
cgi.cfg    控制cgi访问的配置文件
nagios.cfg    Nagios主配置文件
resource.cfg    变量定义文件,通过在此文件中定义变量,以便在其他文件应用。
Object    一个目录,有很多配置文件模板,用于定义nagios对象
objects/commands.cfg    命令定义配置文件,里面有定义的命令可以被其他配置文件引用。
objects/contacts.cfg    定义联系人和联系人组的配置文件
objects/localhost.cfg    定义监控本地主机的配置文件
objects/printer.cfg    定义监控打印机的配置文件模板,默认没有启用此文件
objects/switch.cfg    监控路由器的配置文件模板,默认没有启用
objects/templates.cfg    定义主机,服务的一个模板配置文件,可以再其他配置文件引用
objects/timeperiods.cfg    定义nagios监控时间段的配置文件
Objects/windows.cfg    监控windows主机的一个配置文件模板,默认没有启用此文件

配置文件引用在/usr/local/nagios/etc/objects/nagios.cfg文件里设置
# You can specify individual object config files as shown below:
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/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
如上我将localhost.cfg文件注释了,用hosts.cfg和service.cfg替换,host.cfg文件主要定义要监控的主机和主机组,service.cfg主要定义监控的服务等
Hosts.cfg文件配置如下:
# Define a host for the local machine

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               client
        alias                   client
        address                 192.168.100.31
        }



###############################################################################

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }



###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################

# Define an optional hostgroup for Linux machines

define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost,client     ; Comma separated list of hosts that belong to this group
        }
上述配置文件中的linux-server是在templates.cfg里配置,可以添加多个主机组
配置了客户端后可登陆web http://<your.nagios.server.ip>/nagios
界面看到添加的监控服务器下图中的clients


点击服务可以监控具体的服务,下图是监控cpu负载的情况





安装nagiosgrah
wget http://sourceforge.net/projects/nagiosgraph/files/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz/download
yum install perl-rrdtool perl-GD
yum install perl-Time-HiRes
tar zxf  nagiosgraph-1.4.4.tar.gz
cd nagiosgraph-1.4.4
perl ./install.pl  --check-prereq
perl ./install.pl  --layout overlay --prefix /usr/local/nagios
2个选项需要输入y其他默认即可
Modify the Nagios configuration? [n] y
Modify the Apache configuration? [n] y
安装完成后访问测试
http://192.168.100.30/nagios/cgi-bin/show.cgi
http://192.168.100.30/nagios/cgi-bin/showconfig.cgi
配置复制安装包里的文件
cp nagiosgraph-1.4.4/share/nagiosgraph.ssi  /usr/local/nagios/share/ssi/common-header.ssi
修改文件common-header.ssi
[iyunv@server01 opt]# vi /usr/local/nagios/share/ssi/common-header.ssi
<script type=&quot;text/javascript&quot; src=&quot;/nagios/nagiosgraph.js&quot;></script>
mv /usr/local/nagios/share/images/action.gif  /usr/local/nagios/share/images/action.gif-orig
拷贝安装包文件文件graph.gif
cp nagiosgraph-1.4.4/share/graph.gif /usr/local/nagios/share/images/action.gif

vi /usr/local/nagios/share/side.php  搜索Trends后添加
<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/trends.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Trends</a></li>

<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/trends.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Trends</a>
<ul>
<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/show.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Graphs</a></li>
<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/showhost.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Graphs by Host</a></li>
<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/showservice.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Graphs by Service</a></li>
<li><a href=&quot;<?php echo $cfg[&quot;cgi_base_url&quot;];?>/showgroup.cgi&quot; target=&quot;<?php echo $link_target;?>&quot;>Graphs by Group</a></li>
</ul>
</li>

修改/usr/local/nagios/etc/objects/commands.cfg 添加
define command {
       command_name  process-service-perfdata
       command_line  /usr/local/nagios/libexec/insert.pl
     }

修改文件/usr/local/nagios/etc/objects/templates.cfg 添加
define service {
       name graphed-service
       action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&period=week&rrdopts=-w&#43;450&#43;-j
     }




被监控机器也就是client安装
安装基础软件
yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
添加用户
/usr/sbin/useradd nagios
passwd nagios

cd /opt/nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

安装nrpe
yum install xinetd
[iyunv@server02 opt]# tar xzf nrpe-2.14.tar.gz
[iyunv@server02 opt]# cd nrpe-2.14
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
编辑vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.100.30 没有空&#26684;
编辑/etc/xinetd.d/nrpe 文件添加监控主机的地址192.168.100.30
only_from       = 127.0.0.1 <nagios_ip_address>
编辑/etc/servers文件添加
nrpe            5666/tcp   # NRPE
重启服务
service xinetd restart

测试是否nrpe守护进程启动了
netstat -at | grep nrpe 输出
tcp 0 0 *:nrpe *:* LISTEN
[iyunv@server02 nrpe-2.14]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.14
  

  

  图表显示不出来求解,

运维网声明 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-142351-1-1.html 上篇帖子: nagios插件之登陆SBC监控电话数 下篇帖子: nagios监控 mysql 表结构
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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