开源中文网

您的位置: 首页 > Linux应用 > nagios > 正文

lamp下Nagios 服务端安装过程详解

来源: 网络整理  作者: 佚名

Nagios 是一款监控工具了目前 小编只知道Nagios能在linux系统是安装使用了,下面给各位介绍lamp下Nagios 服务端安装过程详解

前提:LAMP环境搭建完成
备注:经过Centos6.4、Centos6.5、Centos7.0测试试用!
脚本:
#!/bin/bash
# Author:Byrd
# Version:1.0
# Site:www.t4x.org
# Contact:root#t4x.org
#This script for Nagios-V3.5.1
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG="en_US.UTF-8"
# Check if user is root
if [ $UID != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install Nagios3.5.1"
    exit 1
fi
clear
echo "========================================================================="
echo "INSTALL NAGIOS-V3.5.1"
echo "========================================================================="
NagiosSoft=http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz
NagiosPls=http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
NagiosNrpe=http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
NagiosNrpV=nrpe-2.15
NagiosPve=nagios-plugins-2.0.3
NagiosVer=nagios-3.5.1
NagiosDir=/byrd/tools/nagios
[ ! -d $NagiosDir ] && mkdir -p $NagiosDir
if [ `cat /etc/selinux/config | grep SELINUX=disabled | wc -l` -eq 0 ];then
    sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
    setenforce 0
    useradd nagios
    groupadd nagcmd
    usermod -a -G nagcmd nagios
    usermod -a -G nagcmd daemon
    yum install ntpdate vim wget -y
    echo 'export LC_ALL=C' >> /etc/profile
    source /etc/profile
    echo '*/10 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
    ntpdate time.nist.gov
fi
if [ ! -f $NagiosDir/$NagiosVer.tar.gz ];then
    cd $NagiosDir
    wget $NagiosSoft
    tar zxf $NagiosVer.tar.gz
    cd nagios
    ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra
    make all
    make install
    RETVAL=$?
    make install-init
    make install-commandmode
    make install-config
    make install-webconf
    /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123
    sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.confnInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf
    /usr/local/apache/bin/apachectl -k restart
    /etc/init.d/nagios start
else
    cd $NagiosDir
    tar zxf $NagiosVer.tar.gz
    cd nagios
    make clean
    ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra
    make all
    make install
    RETVAL=$?
    make install-init
    make install-commandmode
    make install-config
    make install-webconf
    /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123
    sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.confnInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf
    /usr/local/apache/bin/apachectl -k restart
    /etc/init.d/nagios start
fi
if [ $RETVAL -eq 0 ];then
    echo "Nagios 3.5.1 Install Successful"
else
    exit 1
fi
clear
echo "========================================================================="
echo "INSTALL NAGIOS-PLUGINS-2.0.3"
echo "========================================================================="
if [ ! -f $NagiosDir/$NagiosPve.tar.gz ];then
    cd $NagiosDir
    yum install perl-devel -y
    wget $NagiosPls
    tar zxf $NagiosPve.tar.gz
    cd $NagiosPve
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql
    make && make install
    RETVALPls=$?
else
    cd $NagiosDir
    yum install perl-devel -y
    tar zxf $NagiosPve.tar.gz
    cd $NagiosPve
    make clean
    ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql
    make && make install
    RETVALPls=$?
fi
if [ $RETVALPls -eq 0 ];then
    echo "$NagiosPve INSTALL SUCCESSFUL"
else
    echo "$NagiosPve INSTALL FAILED"
    exit $RETVALPls
fi
if [ ! -f $NagiosDir/$NagiosNrpV.tar.gz ];then
    cd $NagiosDir
    wget $NagiosNrpe
    tar zxf $NagiosNrpV.tar.gz
    cd $NagiosNrpV
    ./configure
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config
else
    cd $NagiosDir
    tar zxf $NagiosNrpV.tar.gz
    cd $NagiosNrpV
    make clean
    ./configure
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config
fi
if [ -f /usr/local/nagios/libexec/check_nrpe ];then
    echo "$NagiosNrpV INSTALL SUCCESSFUL"
else
    echo "$NagiosNrpV INSTALL FAILED"
    echo 1
fi
过程:
[root@Nagios-Server ~]# uname -a
Linux Nagios-Server 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@Nagios-Server ~]# echo 'export LC_ALL=C' >> /etc/profile
[root@Nagios-Server ~]# source /etc/profile
[root@Nagios-Server ~]# echo $LC_ALL
C
[root@Nagios-Server ~]# getenforce
Enforcing
[root@Nagios-Server ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
[root@Nagios-Server ~]# setenforce 0
[root@Nagios-Server ~]# cat /etc/selinux/config | grep SELINUX=
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@Nagios-Server ~]# yum install ntpdate -y
[root@Nagios-Server ~]# echo '*/10 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1' >>/var/spool/cron/root
[root@Nagios-Server ~]# ntpdate time.nist.gov
[root@Nagios-Server ~]# mkdir /byrd/tools/nagios -p
[root@Nagios-Server nagios]# cd /byrd/tools/nagios/
[root@Nagios-Server nagios]# yum install wget -y
[root@Nagios-Server nagios]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.5.1/nagios-3.5.1.tar.gz
[root@Nagios-Server nagios]# tar zxf nagios-3.5.1.tar.gz
[root@Nagios-Server nagios]# cd nagios
[root@Nagios-Server nagios]# useradd nagios     
[root@Nagios-Server nagios]# groupadd nagcmd     
[root@Nagios-Server nagios]# usermod -a -G nagcmd nagios
[root@Nagios-Server nagios]# usermod -a -G nagcmd daemon
[root@Nagios-Server nagios]# id -n -G nagios
nagios nagcmd
[root@Nagios-Server nagios]# id -n -G daemon
daemon bin adm lp nagcmd
[root@Nagios-Server nagios]# ./configure --with-command-group=nagcmd --with-httpd-conf=/usr/local/apache/conf/extra
[root@Nagios-Server nagios]# make all
[root@Nagios-Server nagios]# make install
[root@Nagios-Server nagios]# make install-init
[root@Nagios-Server nagios]# make install-commandmode
[root@Nagios-Server nagios]# make install-config
[root@Nagios-Server nagios]# make install-webconf
[root@Nagios-Server nagios]# /usr/local/apache/bin/htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagiosadmin admin123
[root@Nagios-Server nagios]# sed -i 's#Include conf/extra/httpd-default.conf#Include conf/extra/httpd-default.confnInclude conf/extra/nagios.conf#g' /usr/local/apache/conf/httpd.conf
[root@Nagios-Server nagios]# /usr/local/apache/bin/apachectl -k restart
[root@Nagios-Server nagios]# /etc/init.d/nagios checkconfig
[root@Nagios-Server nagios]# /etc/init.d/nagios start
[root@Nagios-Server nagios]# cd ..
[root@Nagios-Server nagios]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[root@Nagios-Server nagios]# tar zxf nagios-plugins-2.0.3.tar.gz
[root@Nagios-Server nagios]# cd nagios-plugins-2.0.3
[root@Nagios-Server nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql
[root@Nagios-Server nagios-plugins-2.0.3]# yum -y install perl-devel perl-CPAN
[root@Nagios-Server nagios-plugins-2.0.3]# make && make install
[root@Nagios-Server nagios-plugins-2.0.3]# cd ..
[root@Nagios-Server nagios]# ll /usr/local/nagios/libexec/ | wc -l
61
[root@Nagios-Server nagios]# pwd                              
/byrd/tools/nagios
[root@Nagios-Server nagios]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
[root@Nagios-Server nagios]# tar zxf nrpe-2.15.tar.gz
[root@Nagios-Server nagios]# cd nrpe-2.15
[root@Nagios-Server nrpe-2.15]# ./configure
[root@Nagios-Server nrpe-2.15]# make all
[root@Nagios-Server nrpe-2.15]# make install-plugin
[root@Nagios-Server nrpe-2.15]# make install-daemon
[root@Nagios-Server nrpe-2.15]# make install-daemon-config
备注:
[root@Nagios-Server ~]# /etc/init.d/nagios start
Starting nagios: done.
[root@Nagios-Server ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
软件:
nrpe:http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/
nagios:http://sourceforge.net/projects/nagios/
other:http://www.nagios.org/download/addons/

Tags:过程
相关文章列表:
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明