nagios安装配置笔记

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
[root@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时可用命令检查版本
[root@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
[root@server01 opt]# vi /usr/local/nagios/share/ssi/common-header.ssi
<script type="text/javascript" src="/nagios/nagiosgraph.js"></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="<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a></li>

<li><a href="<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a>
<ul>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/show.cgi" target="<?php echo $link_target;?>">Graphs</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showhost.cgi" target="<?php echo $link_target;?>">Graphs by Host</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showservice.cgi" target="<?php echo $link_target;?>">Graphs by Service</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showgroup.cgi" target="<?php echo $link_target;?>">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+450+-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
[root@server02 opt]# tar xzf nrpe-2.14.tar.gz
[root@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 没有空格
编辑/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
[root@server02 nrpe-2.14]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.14



图表显示不出来求解,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值