使用shell自动安装部署Nagios


 #!/bin/sh
#This script is auto_nagios
#version 1.0.0
#copyright (c) zhaohaihua zhaohha@ufida.com.cn
export install_dir="/usr/src/pack_nagios"
dir=`pwd`
tar zxf $dir/pack_nagios.tar.gz -C /usr/src
login_nagios_user=chanjet
fetion_id=15910683240
fetion_passwd=zhh19861213
#notify email
EMAIL=zhaohh@chanjet.com
LOCAL_HOSTNAME=`hostname`
CHEK_HOSTNAME=chanjet21
#localhost ip
IP=`ifconfig eth0 | grep inet addr | awk {print $2} | cut -d: -f2`
#be monitored host ip
CHEK_IP=192.168.0.3
# Check if user is root
if [[ $LOGNAME != "root" ]]; then
    printf "Error: You must be root to run this script! "
    exit 1
fi
 
#read config
. config.sh
. showcolor.sh
 
#function to install all
Install_all(){
Install_apache
Install_nagios
Install_plugins
Install_nrpe
Install_fetion
. $dir/define.sh
Auth_user
}
 
#function to install partion
Install_partion(){
Install_apache
Install_nagios
Install_plugins
Install_fetion
. $dir/define.sh
Auth_user
}
 
#function to only  install nrpe
function Install_nrpe_only(){
useradd nagios -s /sbin/nologin
cd $install_dir
tar zxf $NRPE_VERSION.tar.gz
cd $NRPE_VERSION
$NRPE_COMPILE_COMMAND
sleep 2
make all && make install
sleep 2
#cp $NRPE_PREFIX/libexec/check_nrpe $NAGIOS_PREFIX/libexec/
#cp $NAGIOS_PREFIX/libexec/{check_disk,check_load,check_ping,check_procs} $NRPE_PREFIX/libexec/
mkdir $NRPE_PREFIX/etc
chown -R nagios.nagios $NRPE_PREFIX/etc
cp $install_dir/$NRPE_VERSION/sample-config/nrpe.cfg $NRPE_PREFIX/etc/
cd ..
rm -rf $NRPE_VERSION
echo "nrpe install is ok ,but you need to cp NRPE_PREFIX/libexec/check_nrpe NAGIOS_PREFIX/libexec/;cp NAGIOS_PREFIX/libexec/{check_disk,check_load,check_ping,check_procs} NRPE_PREFIX/libexec/"
sleep 3
}
 
 
#function to install apache
Install_apache(){
cd $install_dir
tar zxf $APACHE_VERSION.tar.gz
cd $APACHE_VERSION
$APACHE_COMPILE_COMMAND
sleep 2
make && make install
sleep 2
cd ..
rm -rf $APACHE_VERSION
echo /usr/local/apache2/bin/ >>/etc/profile
ln -s /usr/local/apache2/bin/apachectl /bin/apachectl
sed -i /^#ServerName www/cServerName $LOCAL_HOSTNAME:80 /usr/local/apache2/conf/httpd.conf
sed -i /^ *DirectoryIndex/c DirectoryIndex index.php index.html index.html.var /usr/local/apache2/conf/httpd.conf
cat>>/usr/local/apache2/conf/httpd.conf<<EOF
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
  AuthType Basic
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthUserFile /usr/local/nagios/etc/htpasswd
   Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
EOF
apachectl start
echo "apache install is ok "
sleep 3
}
 
#function to install_nagios
Install_nagios(){
useradd nagios -s /sbin/nologin
cd $install_dir
tar zxf $NAGIOS_VERSION.tar.gz
cd $NAGIOS_VERSION
$NAGIOS_COMPILE_COMMAND
sleep 2
make all
make install
make install-init
make install-commandmode
make install-config
sleep 2
cd ..
rm -rf $NAGIOS_VERSION
echo "nagios install is ok "
sleep 3
}
#function to Install_nagios-plugins
Install_plugins(){
cd $install_dir
tar zxf ${NAGIOS_PLUGINS_VERSION}.tar.gz
cd ${NAGIOS_PLUGINS_VERSION}
$NAGIOS_PLUGINS_COMPILE_COMMAND
sleep 2
make;make install
sleep 2
cd ..
rm -rf ${NAGIOS_PLUGINS_VERSION}
echo "nagios-plugins install is ok "
sleep 3
}
 
 
#function to install nrpe
function Install_nrpe(){
cd $install_dir
tar zxf $NRPE_VERSION.tar.gz
cd $NRPE_VERSION
$NRPE_COMPILE_COMMAND
sleep 2
make all && make install
sleep 2
cp $NRPE_PREFIX/libexec/check_nrpe $NAGIOS_PREFIX/libexec/
cp $NAGIOS_PREFIX/libexec/{check_disk,check_load,check_ping,check_procs} $NRPE_PREFIX/libexec/
mkdir $NRPE_PREFIX/etc
cp $install_dir/$NRPE_VERSION/sample-config/nrpe.cfg $NRPE_PREFIX/etc/
chown -R nagios.nagios $NRPE_PREFIX/libexec
chown -R nagios.nagios $NRPE_PREFIX/etc
chown -R nagios.nagios $NAGIOS_PREFIX/libexec
chown -R nagios.nagios $NAGIOS_PREFIX/etc
cd ..
rm -rf $NRPE_VERSION
echo "nrpe install is ok "
sleep 3
}
 
#function to install fetion
Install_fetion(){
cd $install_dir/fetion
mkdir -p $NAGIOS_PREFIX/libexec/sms
cp libACE* libcrypto* libssl* fetion  $NAGIOS_PREFIX/libexec/sms
echo "fetion install is ok "
sleep 3
}
#function to create web auth user
function Auth_user(){
chown -R nagios.nagios $NAGIOS_PREFIX/etc
clear
read -p "Please enter web author:" AUTH_USER
$APACHE_PREFIX/bin/htpasswd -c $NAGIOS_PREFIX/etc/htpasswd $AUTH_USER
cat<<EOF
 
......

相关内容

    暂无相关文章