成都网站建设设计

将想法与焦点和您一起共享

Nagios搭建与配置-创新互联

Nagios 搭建与配置

成都创新互联公司是一家集网站建设,吉州企业网站建设,吉州品牌网站建设,网站定制,吉州网站建设报价,网络营销,网络优化,吉州网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

实验环境 centos6.5 两台

实验步骤

一.安装Nagios的依赖关系:

yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server xinetd

二.安装配置Nagios(监控本机)

  1. 添加nagios运行所需要的用户和组:

    useradd nagios

  2. 把apache加入到nagios组

    usermod -a -G nagios apache

  3. 上传nagios包,加压后编译安装nagios:

    tar -zxf nagios-4.0.3.tar.gz

    cd nagios-4.0.3

    ./configure --with-command-group=nagios  --enable-event-broker

    make all                      (编译全部)

    make install                    (安装)

    make install-init                 (生成启动脚本文件)

    make install-commandmode             (设置组的执行权限)

    make install-config               (生成配置文件)

    make install-webconf               (安装nagios的web文件到httpd的conf.d目录下)

  4. 为email指定您想用来接收nagios警告信息的邮件地址,默认是本机的nagios用户:

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

  5. 修改配置 email     nagios@localhost    这个是默认设置

  6. 创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

  7. 以上过程配置结束以后需要启动httpd:

    /etc/init.d/httpd start

  8. 编译、安装nagios-plugins(插件)

    tar -zxf nagios-plugins-1.5.tar.gz

    cd nagios-plugins-1.5

    ./configure --with-nagios-user=nagios --with-nagios-group=nagios

    make

    make install

  9. 检查其主配置文件的语法是否正确:

    /usr/local/nagios/bin/nagios -v  /usr/local/nagios/etc/nagios.cfg

  10. 如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了: service nagios start

    关闭selinux:setenforce 0

    关闭防火墙:service iptables stop

    修改本地监控配置文件:vim /usr/local/nagios/etc/objects/localhost.cfg

  11. 通过web界面查看nagios:

    http://your_nagios_IP/nagios

    这时候已将可以监控Linux本机。浏览器测试:‘IP地址’/nagios

三.基于NRPE(桥梁)监控远程Linux主机

  1. 配置-监控端

1).安装NRPE

tar -xf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure --with-nrpe-user=nagios \

   --with-nrpe-group=nagios \

   --with-nagios-user=nagios \

   --with-nagios-group=nagios \

   --enable-command-args \

   --enable-ssl

make all

make install-plugin         (设置插件权限)

2).添加策略

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

添加:define command{

    command_name   check_nrpe

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

    }

3).定义监控对象,复制一个模板 cp localhost.cfg linux.cfg

编辑模块文件:

vim linux.cfg      (:%s /localhost/linux/g[修改localhost为linux])

   host_name  linux

    address  被监控端的IP

将这五行注释掉      

define hostgroup{

    hostgroup_name  linux-servers ; The name of the hostgroup

   alias      Linux Servers ; Long name of the group

    members     linux   ; Comma separated list of hosts that belong to this group

    }

修改 check_command  为 check_nrpe_procs(中间的部分不用动只修改最后的部分)

4).添加模块

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

添加:

define command{

    command_name   check_nrpe_disk

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c "check_disk"

    }

define command{

    command_name   check_nrpe_users

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c "check_users"

    }

define command{

    command_name   check_nrpe_procs

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c "check_procs"

    }

define command{

    command_name   check_nrpe_load

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c "check_load"

    }

define command{

    command_name   check_nrpe_swap

    command_line   $USER1$/check_nrpe -H $HOSTADDRESS$ -c "check_swap"

    }

vim vim /usr/local/nagios/etc/nagios.cfg 添加一条

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

cd objects/

5).给权限:

chown nagios.nagios linux.cfg  chmod 664 linux.cfg

6).启动服务:

service nagios restart

2.安装配置-被监控端

1)先添加nagios用户

useradd -s /sbin/nologin nagios

2)NRPE依赖于nagios-plugins,因此,需要先安装nagios-plugins

tar -zxf nagios-plugins-1.5.tar.gz

cd nagios-plugins-1.5

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make all

make install

3)安装NRPE

tar -xf nrpe-2.12.tar.gz

cd nrpe-2.12.tar.gz

./configure --with-nrpe-user=nagios \

   --with-nrpe-group=nagios \

   --with-nagios-user=nagios \

   --with-nagios-group=nagios \

   --enable-command-args \

   --enable-ssl

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd       (生成临时服务)

4).修改文件:

vim /etc/xinetd.d/nrpe

only-from=127.0.0.1  10.1.1.2(这个是监控端nagios的IP)(nrpe允许以上IP的机器通过nrpe查询服务)

vim /etc/services

文件最后添加一条:nrpe 5666/tcp  nrpe

5).启动守护进程

service xinetd start

6).配置NRPE

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

log_facility=daemon

pid_file=/var/run/nrpe.pid

server_address=被监控端的IP

server_port=5666

nrpe_user=nagios

nrpe_group=nagios

allowed_hosts=监控端的IP

command_timeout=60

connection_timeout=300

debug=0

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / (记得修改!)

command[check_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200(记得修改!)

添加一条:command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20%

7).启动NRPE

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d(临时启动)

或者将如下内容定义为vim /etc/init.d/nrped脚本:

!/bin/bash

chkconfig: 2345 88 12

description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in

start)

echo -n "Starting NRPE daemon..."

$NRPE -c $NRPECONF -d

echo " done."

;;

stop)

echo -n "Stopping NRPE daemon..."

pkill -u nagios nrpe

echo " done."

;;

restart)

$0 stop

sleep 2

$0 start

;;

*)

echo "Usage: $0 start|stop|restart"

;;

esac

exit 0

chmod -R 777 /etc/init.d/nrped

8).启动服务

/etc/init.d/nrped start

service xinetd restart

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前题目:Nagios搭建与配置-创新互联
网页网址:http://chengdu.cdxwcx.cn/article/cejggi.html