Nagios部署

nagios需要依赖lamp环境,所有我们先在nagios服务器上安装配置lamp环境。

[root@pc1 ~]# yum -y install httpd php* mariadb*

解压相关软件

[root@pc1 ~]# cd /root/桌面

[root@pc1 ~]#   tar -zxvf nagios-4.0.1.tar.gz -C /usr/src

[root@pc1 ~]#   tar -zxvf nagios-plugins-1.5.tar.gz -C /usr/src

[root@pc1 ~]#   tar -zxvf nrpe-2.15.tar.gz -C /usr/src

2、安装依赖环境

yum -y install openssl-devel

3、编译安装nagois

[root@localhost ~]# useradd -M -s /sbin/nologin nagios

[root@localhost ~]# mkdir /usr/local/nagios

[root@localhost ~]# chown -R nagios:nagios /usr/local/nagios/

[root@localhost ~]# cd /usr/src/nagios-4.0.1/

配置编译环境

    [root@pc1 nagios-4.0.1]# yum -y install gcc*

[root@localhost nagios-4.0.1]#  ./configure --prefix=/usr/local/nagios

编译安装

[root@localhost nagios-4.0.1]# make all

[root@localhost nagios-4.0.1]# make install

[root@localhost nagios-4.0.1]# make install-init

[root@localhost nagios-4.0.1]# make install-commandmode

[root@localhost nagios-4.0.1]# make install-config

make install #安装主程序,CGI和HTML文件

make install-init #在/etc/rc.d/init.d安装启动脚本

make install-commandmode #安装command模板

make install-config #安装示例配置文件

6、编译安装nagios-plugins:

[root@localhost nagios-4.0.1]#   cd  /usr/src/nagios-plugins-1.5

[root@pc1 nagios-plugins-1.5]#  ./configure --prefix=/usr/local/nagios

[root@pc1 nagios-plugins-1.5]#   make && make install

7、编译安装nrpe:

[root@pc1 nagios-plugins-1.5]#  cd  /usr/src/nrpe-2.15/

[root@pc1 nrpe-2.15]#   ./configure && make all

[root@pc1 nrpe-2.15]#  make install-plugin

8、配置httpd.conf

添加nagios的访问界面

[root@pc1 nrpe-2.15]# vim  /etc/httpd/conf/httpd.conf

在最后面添加:

ScriptAlias /nagios/cgi-bin/ "/usr/local/nagios/sbin/"

<Directory "/usr/local/nagios/sbin">

    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted

</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">

    Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted

</Directory>

9、设置页面访问认证:

[root@localhost ~]# vim /usr/local/nagios/etc/cgi.cfg

修改:

use_authentication=0 (0:允许访问所有页面。1:禁止)

[root@pc1 nrpe-2.15]# systemctl restart httpd

[root@pc1 nrpe-2.15]# systemctl restart mariadb

+++++++++++++++++++++++++++++++++++++++++++++++++++++

pc2    被控端设置

1、安装依赖环境

[root@localhost ~]# yum -y install openssl openssl-devel gcc*

[root@localhost ~]# useradd -M -s /sbin/nologin nagios

安装nagios-plugins

    [root@localhost ~]#  cd  /root/桌面

[root@localhost ~]# tar -zxvf nagios-plugins-1.5.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/nagios-plugins-1.5/

[root@localhost nagios-plugins-1.5]#  ./configure --prefix=/usr/local/nagios

[root@localhost nagios-plugins-1.5]#  make && make install

[root@localhost nagios-plugins-1.5]#  chown -R nagios:nagios /usr/local/nagios/

3、安装nrpe

[root@localhost ~]# tar -zxvf  /root/桌面/nrpe-2.15.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/nrpe-2.15/

[root@localhost nrpe-2.15]# ./configure --prefix=/usr/local/nagios/

[root@localhost nrpe-2.15]# make all

[root@localhost nrpe-2.15]# make install-plugin

[root@localhost nrpe-2.15]# make install-daemon

[root@localhost nrpe-2.15]# make install-daemon-config

4、配置

[root@localhost nrpe-2.15]# vim /usr/local/nagios/etc/nrpe.cfg

修改:

allowed_hosts=127.0.0.1,192.168.1.1 //添加监控服务器的IP地址

[root@localhost nrpe-2.15]#  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d   //启动nrpe

[root@localhost nrpe-2.15]# netstat -anp | grep nrpe   //端口号是TCP5666

5、安装测试服务

[root@localhost ~]# yum -y install httpd vsftpd bind dhcp

[root@pc2 nrpe-2.15]# systemctl restart httpd

[root@pc2 nrpe-2.15]# systemctl restart named

[root@pc2 nrpe-2.15]# systemctl restart vsftpd

将以上为进行简单的配置,并启动服务

pc1添加被监控客户端的测试选项

[root@pc1 nrpe-2.15]# cd /usr/local/nagios/etc/

cp  -p objects/localhost.cfg  objects/192.168.1.2.cfg

vim  objects/192.168.1.2.cfg

修改:

删除或者注释host group 选项

define host{

        use                     linux-server

        host_name               server2

        alias                   server2

        address                 192.168.1.2             //30行  将127.0.0.1修改为192.168.1.2

        }

替换所有模块中的host_name 的名称为server2

:% s/localhost/server2/g

添加模块:

define service{

        use                            local-service

        host_name                      server2

        service_description              FTP

        check_command                 check_ftp

        notifications_enabled            0

        }

define service{

        use                            local-service

        host_name                      server2

        service_description              DHCP

        check_command                  check_dhcp

        notifications_enabled            0

        }

define service{

        use                            local-service

        host_name                      server2

        service_description             DNS

        check_command                  check_dns

        notifications_enabled            0

        }

7、配置nagios.cfg,添加监控节点

vim  /usr/local/nagios/etc/nagios.cfg

添加:

cfg_file=/usr/local/nagios/etc/objects/192.168.1.2.cfg

8、重启服务

killall -9 nagios

systemctl  start nagios &

若无法启动,尝试另一种启动方式

/etc/init.d/nagios start

Reloading systemd:                                         [  确定  ]

Starting nagios (via systemctl):

  1. 查看监控结果

pc1   访问192.168.1.1/nagios

  • 23
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值