以下是LNMP+Nagios Server端的安装脚本,脚本预计需要执行半小时,当脚本执行完毕后你的基于LNMP的Nagios Server端就装好啦
下面是效果图:
下面是脚本代码:(写的不太好,求大神们指点)
#!/bin/bash#date:2015-5-27#author:yfshare#mail:838554604@qq.comecho ''echo -e "\t###########################################################"echo -e "\t###\t\t\t\t\t\t\t###"echo -e "\t###\twelcome to use Nagios&Nginx Install Scripts\t###"echo -e "\t###\tRequirement:\t\t\t\t\t###"echo -e "\t###\tSystem:\t\tCentOS 6.x\t\t\t###"echo -e "\t###\tprocessor:\tx86_64\t\t\t\t###"echo -e "\t###\t\t\t\t\t\t\t###"echo -e "\t###########################################################"function check_service() {network=`netstat -tunlp |grep ${1} |wc -l`Process=`ps -ef|grep ${1}|grep -v grep|wc -l`while truedo if [ ${network} -ge 1 ] || [ ${Process} -ge 1 ];then echo -e "${1} started successfully" break else echo -e "${1} failed to start" /bin/sh $2 sleep 2 fidone}function Content() {echo ''read -p 'please input software path:' pathmkdir ${path}/loglog="${path}/log/install.log"echo ''echo -e 'Please input the password for user admin:'yum -y install httpd-tools >>${log} 2>&1declare -i count=3while truedo htpasswd -cm $path/conf/htpasswd.users admin result=`echo $?` ((--count)) if [[ $result != 0 ]];then if [[ $count -ge 1 ]];then echo '' else exit 1 fi else break fidonecd $pathyum -y install gcc gcc-c++ perl perl-devel mysql mysql-devel libxml2 libxml2-devel unzip >>${log} 2>&1#install phptar -zxvf zlib-1.2.7.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf ${path}/zlib-1.2.7.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure -prefix=/usr/local/zlib >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf ${path}/libmcrypt-2.5.7.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1useradd -s /sbin/nologin www >>${log} 2>&1groupadd nagcmd &&useradd -G nagcmd nagios &&usermod -G nagcmd wwwtar -jxvf $path/php-5.3.8.tar.bz2 -C $path >>${log} 2>&1yum install libpng.x86_64 freetype.x86_64 libjpeg-turbo.x86_64 libjpeg-turbo-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y >>${log} 2>&1cd $path/`tar -jxvf ${path}/php-5.3.8.tar.bz2|head -n 1|awk -F/ '{print $1}'`./configure --prefix=/usr/local/php --enable-mbstring --enable-soap --enable-wddx=shared --enable-xml --with-gd --with-gettext --with-regex=system --with-zlib-dir=/usr/local/zlib --enable-fpm --with-jpeg-dir --with-fpm-user=www --with-fpm-group=www --enable-shmop --with-mcrypt --with-mysqli=mysqlnd >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confsed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.confsed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.confsed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.confsed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf/usr/local/php/sbin/php-fpmecho '/usr/local/php/sbin/php-fpm'>>/etc/rc.localcheck_service php "/usr/local/php/sbin/php-fpm"#install nginxtar -jxvf ${path}/pcre-8.12.tar.bz2 -C ${path} >>${log} 2>&1cd ${path}/`tar -jxvf ${path}/pcre-8.12.tar.bz2|head -n 1|awk -F/ '{print $1}'`./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/openssl-1.0.1c.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/openssl-1.0.1c.tar.gz|head -n 1|awk -F/ '{print $1}'`./config >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/nginx-1.6.2.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/nginx-1.6.2.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=${path}/pcre-8.12 --with-zlib=${path}/zlib-1.2.7 --with-openssl=${path}/openssl-1.0.1c --with-http_stub_status_module >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1cp $path/conf/etc_init.d_nginx /etc/init.d/nginx >>${log} 2>&1chown www:www /usr/local/nginx -Rchmod 775 /etc/init.d/nginx &&/etc/init.d/nginx start >>${log} 2>&1chkconfig --add nginx && chkconfig nginx oncheck_service nginx "/etc/init.d/nginx start"cat $path/conf/nginx.conf >/usr/local/nginx/conf/nginx.confcat $path/conf/fastcgi.conf >/usr/local/nginx/conf/fastcgi.confcat $path/conf/fcgi.conf >/usr/local/nginx/conf/fcgi.confcat $path/conf/start_perl_cgi.sh > /usr/local/nginx/start_perl_cgi.shchmod 775 /usr/local/nginx/start_perl_cgi.sh#install FCGItar -zxvf $path/FCGI-0.73.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/FCGI-0.73.tar.gz|head -n 1|awk -F/ '{print $1}'`perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/FCGI-ProcManager-0.25.tar.gz|head -n 1|awk -F/ '{print $1}'`perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/IO-1.25.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/IO-1.25.tar.gz|head -n 1|awk -F/ '{print $1}'`perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/IO-All-0.39.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/IO-All-0.39.tar.gz|head -n 1|awk -F/ '{print $1}'`perl Makefile.PL >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/spawn-fcgi-1.6.3.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1cd $path &&unzip $path/perl-fcgi.zip >>${log} 2>&1cp $path/perl-fcgi.pl /usr/local/nginx/chmod 755 /usr/local/nginx/perl-fcgi.pl/usr/local/nginx/start_perl_cgi.sh startecho "/bin/sh /usr/local/nginx/start_perl_cgi.sh start" >>/etc/rc.localIP=`ls /usr/local/nginx/logs/|grep "perl-fcgi.sock"|wc -l`while truedo if [ ${IP} -eq 1 ];then echo -e 'start perl-fcgi done' break else echo -e 'perl-fcgi failed to start' /usr/local/nginx/start_perl_cgi.sh start fidone#install Nagiosyum -y install php-gd >>${log} 2>&1tar -zxvf $path/nagios-3.3.1.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/nagios-3.3.1.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure --with-command-group=nagcmd --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-nc=/usr/include >>${log} 2>&1 &&make all >>${log} 2>&1 &&make install >>${log} 2>&1 &&make install-init >>${log} 2>&1 &&make install-config >>${log} 2>&1 &&make install-commandmode >>${log} 2>&1sed -i '/authorized\_for\_/s/nagiosadmin/&\,admin/g' /usr/local/nagios/etc/cgi.cfgmv $path/conf/htpasswd.users /usr/local/nagios/etc/mkdir /usr/local/nagios/logs -psed -i '/use_authentication/s/1/0/g' /usr/local/nagios/etc/cgi.cfgsed -i '/requiretty$/s/^Defaults/#&/g' /etc/sudoerschown nagios:nagcmd /usr/local/nagios -Rchkconfig --add nagios &&chkconfig nagios on/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg |grep ^Total/etc/init.d/nagios startcheck_service nagios "/etc/init.d/nagios start"#install Nagios-plugintar -zxvf $path/nagios-plugins-1.4.15.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf $path/nagios-plugins-1.4.15.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules >>${log} 2>&1make >>${log} 2>&1 &&make install >>${log} 2>&1libexec=`ls /usr/local/nagios/libexec/|wc -l`echo -e "nagios/libexec:${libexec}"#install NRPEyum -y install openssl-devel >>${log} 2>&1tar -zxvf ${path}/nrpe-2.13.tar.gz -C $path >>${log} 2>&1cd $path/`tar -zxvf ${path}/nrpe-2.13.tar.gz|head -n 1|awk -F/ '{print $1}'`./configure >>${log} 2>&1 &&make all >>${log} 2>&1 &&make install-plugin >>${log} 2>&1 &&make install-daemon >>${log} 2>&1 &&make install-daemon-config >>${log} 2>&1e=`ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'`sed -i "/allowed_host/s/127.0.0.1/&,${e}/g" /usr/local/nagios/etc/nrpe.cfgecho "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.localchown nagios:nagcmd /usr/local/nagios -Rln -s /usr/local/nagios/share /usr/local/nginx/html/nagios/usr/local/nagios/libexec/check_nrpe -H localhost >>${log} 2>&1sed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptablessed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 5666 \-j ACCEPT' /etc/sysconfig/iptablessed -i '/^:OUTPUT/a\-A INPUT \-m state \-\-state NEW \-m tcp \-p tcp \-\-dport 9000 \-j ACCEPT' /etc/sysconfig/iptablessed -i '/WorldWideWeb/s/http/#&/g' /etc/servicessed -i '/HyperText/s/http/#&/g' /etc/servicessed -i '/cslistener/s/cslistener/#&/g' /etc/servicessed -i "/WorldWideWeb/anginx\t 80\/tcp\nnginx\t80\/udp\nnginx\t80\/sctp" /etc/servicessed -i "9770 a php\-fpm\t9000\/tcp\nphp\-fpm\t9000\/udp" /etc/servicessed -i "/sfm-db-server/anrpe\t5666\/tcp\nnrpe\t5666\/udp" /etc/services/etc/init.d/iptables restart >>${log} 2>&1 &&chkconfig iptables on/etc/init.d/nagios restartecho -e ''/etc/init.d/nginx reloadecho ''echo "Script installation log in ${path}/log/install.log"}#ret_code=`curl -I -s --connect-timeout 15 www.baidu.com -w %{http_code}|tail -n 1`System=`cat /proc/version |grep -io Centos`ID=`cat /proc/version |awk -F'(' '{print $1}'`processor=`uname -p`if [[ ${ret_code} != '200' ]];then echo '' echo -e "\033[31;49;1m[Error]Network exception, please try again\033[39;49;0m" exit 1else if [[ ${System} != 'centos' ]] || [[ ${processor} != 'x86_64' ]];thenecho 'Warn message:'echo -e "The current operation system:${ID} is not in the system support list\nSystem environment check fails, it may affect the program to run"read -p "Ignored the warning messages [Y/N]? " key if [[ ${key} != [Yy] ]];then echo -e "\033[31;49;1mThanks for using\033[39;49;0m" echo '' else echo '' echo -e "\033[31;49;1mStart install...\033[39;49;0m" Content exit 1 fi else echo '' echo -e "\033[31;49;1mStart install...\033[39;49;0m" Content exit 1 fifi