温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos安装nagios+nrpe

发布时间:2020-06-06 07:36:35 来源:网络 阅读:615 作者:zxz108318 栏目:移动开发

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI