Nagios部署与配置

本文基于以下部分编辑:

  • Nagios的安装和配置

  • Nagios的插件监控

  • Nagios的扩展
    注:本环境默认安装在/usr/local/nagios中 nagios版本:nagios-4.2.4 插件版本:nagios-plugins-2.1.2

    实验环境如下:

Host NameOSIPSoftware
Nagios-ServerCentOS 7192.168.32.129Apache、Php、Nagios、nagios-plugins
Nagios-ClientCentOS 7192.168.32.138nagios-plugins、nrpe

Nagios的安装和配置

nagios-server

Nagios的组成部分: 守护进程 web界面 插件

LAMP环境的部署
yum install gcc php httpd php-gd gd gd-devel mysql* -y
ntpdate统一系统时间
yum install -y ntpdate
ntpdate cn.pool.ntp.org
安装nagios的相关依赖库文件
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel unzip

添加用户并授权
mkdir /usr/local/nagios
useradd nagios -s /sbin/nologin -M
chown nagios:nagios /usr/local/nagios/
ll -d /usr/local/nagios/

下载并安装
chmod a+x nagios-4.2.4.tar.gz
tar zxvf nagios-4.2.4.tar.gz -C /usr/local/src
cd /usr/local/src/nagios4.2.4/
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
检查是否生成了对应httpd的web配置文件
ls -al /etc/httpd/conf.d/
结果如下:
nagios配置文件
cd /usr/local/nagios/ #查看是否有以下几个目录

bin:Nagios可执行程序所在目录
etc:Nagios配置文件所在目录
sbin:nagios CGI文件所在目录,也就是执行外部命令所需要文件的所在的目录
share: nagios网页文件所在的目录
libexec: nagios外部插件 所在目录
var: nagios日志文件,lock等文件所在的目录

为nagios添加默认登陆名nagiosadmin 并设置密码
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

启动nagios服务和httpd服务并设置为开启自启
/etc/init.d/httpd start
/etc/init.d/nagios start
chkconfig httpd on
chkconfig nagios on

安装nagios-plugin
chmod a+x nagios-plugins-2.1.2.tar.gz
tar zxvf nagios-plugins-2.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-plugins-2.2.1
./configure --prefix=/usr/local/nagios/
make && make install

登陆网页localhost/nagios输入用户名和密码进入网站

nagios搭建完成

Nagios-Client

ntpdate统一系统时间
yum install -y ntpdate
ntpdate cn.pool.ntp.org
安装nagios的相关依赖库文件
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel unzip

添加用户并授权
mkdir /usr/local/nagios
useradd nagios -s /sbin/nologin -M
chown nagios:nagios /usr/local/nagios/
ll -d /usr/local/nagios/

安装nagios-plugin
chmod a+x nagios-plugins-2.1.2.tar.gz
tar zxvf nagios-plugins-2.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nagios-plugins-2.2.1
./configure --prefix=/usr/local/nagios/
make && make install

安装NRPE服务
tar zxvf nrpe-3.2.1.tar.gz -C /usr/local/src/
cd /usr/local/src/nrpe-3.2.1
./configure --prefix=/usr/local/nagios/
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

修改守护进程
参考:http://blog.51cto.com/yangrong/1408526

Nagios-Service

If you plan on running nrpe under inetd or xinetd and making use of TCP wrappers, you need to add a line to your /etc/services file as follows (modify the port number as you see fit)

 nrpe            5666/tcp    # NRPE
#在only from处添加监控主机的IP地址
[root@Nagios-Client]# vim /etc/xinetd.d/nrpe 
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 192.168.32.129,192.138.32.138
}

在/etc/services中添加nrpe和端口号

[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      26483/xinetd

Nagios-Client


#在only from处添加监控主机的IP地址
[root@localhost nrpe-2.13]# vim /etc/xinetd.d/nrpe 
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 192.168.10.7
}
在/etc/services中添加nrpe和端口号
nrpe2.PNG

确认已经监听5666端口,服务端安装nrpe不需要添加主机ip,客户机需要添加主机ip
[root@localhost nrpe-2.13]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@localhost nrpe-2.13]# netstat -lntup | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      26483/xinetd
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值