阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS安装Nagios+NRPE

137次阅读
没有评论

共计 3315 个字符,预计需要花费 9 分钟才能阅读完成。

Linux 下有 2 大监控神器 cacti+nagios,下面我把我自己搭建 nagios 的步骤记录下来,以便以后需要的时候看。

首先安装依赖包
#yum install -y httpd mysql mysql-devel mysql-server php php-mysql gcc gcc-c++ gblic gblic-devel gd gd-devel openssl-devel
添加 nagios 用户,用户组
#groupadd nagcmd
#useradd nagios
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd daemon(http 的 user)
下载 nagios 安装包,解压
开始编译
#./configure –prefix=/etc/nagios \
>–with-nagios-user=nagios \
>–with-nagios-group=nagios \
>–enable-event-broker
#make all
#make install
#make install-init
#make install-commandmode
#make install-config
#make install-webconf(编译安装的 httpd 会出现错误)
安装 nagios-plugins
#./configure –with-nagios-user=nagios \
>–with-nagios-group=nagios \
>–with-mysql=/path/to/mysql(监控 mysql 必须添加此选项)
#make && make install
下面开始安装 nrpe
首先确定开发环境
#yum grouplist
确定有 Development tools 和 Development Libraries
如果没有就安装
#yum groupinstall -y “Development tools” “Development Libraries”
开始安装 nrpe
#./configure –with-nagios-user=nagios \
>–with-nagios-group=nagios \
>–with-nrpe-user=nagios \
>–with-nrpe-group=nagios \
>–enable-command-args \
>–enable-ssl
#make all
#make install-plugin
服务器端不需要开始 nrpe 服务

下面开始配置客户端
nrpe 依赖于 nagios-plugins,首先安装 nagios-plugins
#./configure –with-nagios-user=nagios \
>–with-nagios-group=nagios \
>–with-mysql=/path/to/mysql(监控 mysql 必须添加此选项)
#make && make instal
下面开始安装 nrpe
#./configure –with-nagios-user=nagios \
>–with-nagios-group=nagios \
>–with-nrpe-user=nagios \
>–with-nrpe-group=nagios \
>–enable-command-args \
>–enable-ssl
#make all
#make install-plugin
#make install-daemon(安装守护进程)
#make install-daemon-config(安装守护进程配置文件)

修改 nrpe.cfg 文件
找到 allowed_hosts 添加你的服务器的 IP

启动 nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
下面就可以在服务器端定义主机,定义命令开始监控
定义命令
define command{
        command_name        check_nrpe
        command_line          $USER1$/check_nrpe -H  $HOSTADDRESS$  -c $ARG1$(- c 表示在远程执行命令)
}
定义主机
define host {
        use                            linux-server
        host_name                webserver
        alias                          web-server
        address                      192.168.0.4
}
定义服务
define service {
        use                            linux-service
        host_name                  webserver
        service_description    PING
        check_command        check_nrpe!check_ping
}
想要监控什么就在客户端上定义命令,在服务器上填写检测内容就可以了

下面附上 nrpe 的启动脚本
#!/bin/sh
#
# Source function library
if [-f /etc/rc.d/init.d/functions]; then
  . /etc/rc.d/init.d/functions
elif [-f /etc/init.d/functions]; then
  . /etc/init.d/functions
elif [-f /etc/rc.d/functions]; then
  . /etc/rc.d/functions
fi
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[${NETWORKING} = “no” ] && exit 0
NrpeBin=/usr/local/nagios/bin/nrpe
NrpeCfg=/usr/local/nagios/etc/nrpe.cfg
LockFile=/var/lock/subsys/nrpe
# See how we were called.
case “$1” in
 start)
    # Start daemons.
    echo -n “Starting nrpe: “
    daemon $NrpeBin -c $NrpeCfg -d
  echo
  touch $LockFile
    ;;
 stop)
  # Stop daemons.
  echo -n “Shutting down nrpe: “
    killproc nrpe
  echo
  rm -f $LockFile
    ;;
 restart)
  $0 stop
  $0 start
    ;;
 status)
  status nrpe
    ;;
 *)
  echo “Usage: nrpe {start|stop|restart|status}”
    exit 1
esac
exit 0

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

相关阅读

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统(使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计3315字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中