码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP+Zabbix一键安装脚本

时间:2015-06-16 01:28:28      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:lnmp   zabbix   

环境:CentOS 6.5(最小化安装)


执行截图:

技术分享


技术分享


#!/bin/bash
#date:2015-6-14
#author:yfshare
#mail:838554604@qq.com
echo ‘‘
echo -e "\t###########################################################"
echo -e "\t###\t\t\t\t\t\t\t###"
echo -e "\t###\twelcome to use Zabbix&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###########################################################"
echo ‘‘
function check_service() {
network=`netstat -tunlp |grep ${1} |wc -l`
Process=`ps -ef|grep ${1}|grep -v grep|wc -l`
while true
do
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
fi
done
}
function Content() {
read -p ‘please input software path:‘ path
mkdir ${path}/log
log="${path}/log/install.log"
yum -y install gcc gcc-c++ >>${log} 2>&1
#install PHP
yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel >>${log} 2>&1
tar -jxvf ${path}/php-5.3.8.tar.bz2 -C ${path}>>${log} 2>&1
cd ${path}/`tar -jxvf php-5.3.8.tar.bz2|head -n 1|awk -F/ ‘{print $1}‘`
./configure --prefix=/usr/local/php --with-bz2 --with-curl --enable-ftp --enable-sockets --enable-bcmath --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local/photo --with-png-dir=/usr/local/photo --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sed -i ‘/max_execution_time/s/30/300/‘ /usr/local/php/lib/php.ini
sed -i ‘/post_max_size/s/8/16/‘ /usr/local/php/lib/php.ini
sed -i ‘/max_input_time/s/60/300/‘ /usr/local/php/lib/php.ini
sed -i ‘/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"‘ /usr/local/php/lib/php.ini
sed -i ‘/^\;date\.timezone \=/d‘ /usr/local/php/lib/php.ini
sed -i ‘/run\/php-fpm.pid/s/^;//g‘ /usr/local/php/etc/php-fpm.conf
sed -i ‘/^;pm.min_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf
sed -i ‘/^;pm.max_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf
sed -i ‘/^;pm.start_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf
echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
/usr/local/php/sbin/php-fpm
check_service php "/usr/local/php/sbin/php-fpm"
#install Nginx
tar -jxvf ${path}/pcre-8.12.tar.bz2 -C ${path} >>${log} 2>&1
cd ${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>&1
tar -zxvf ${path}/zlib-1.2.7.tar.gz -C ${path} >>${log} 2>&1
cd ${path}/`tar -zxvf ${path}/zlib-1.2.7.tar.gz|head -n 1|awk -F/ ‘{print $1}‘`
./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
tar -zxvf ${path}/openssl-1.0.1c.tar.gz -C ${path} >>${log} 2>&1
cd ${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>&1
tar -zxvf ${path}/nginx-1.6.2.tar.gz -C ${path}>>${log} 2>&1
cd ${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>&1
cp ${path}/conf/etc_init.d_nginx /etc/init.d/nginx
chmod 775 /etc/init.d/nginx
cp ${path}/conf/nginx.conf /usr/local/nginx/conf
chkconfig --add nginx
chkconfig nginx on
/etc/init.d/nginx start
check_service nginx "/etc/init.d/nginx start"
#install mysql
yum -y install mysql* >>${log} 2>&1
/etc/init.d/mysqld start |tail -n 1
check_service mysqld "/etc/init.d/mysqld start"
chkconfig mysqld on
mysqladmin -uroot password redhat
#install zabbix
yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel >>${log} 2>&1
tar -zxvf ${path}/zabbix-2.0.14.tar.gz -C ${path}>>${log} 2>&1
cd ${path}/`tar -zxvf ${path}/zabbix-2.0.14.tar.gz|head -n 1|awk -F/ ‘{print $1}‘`
zabbix_install="${path}/`tar -zxvf ${path}/zabbix-2.0.14.tar.gz|head -n 1|awk -F/ ‘{print $1}‘`"
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1
useradd -s /sbin/nologin zabbix
#initial database
mysql -uroot -predhat < ${path}/conf/initial_database.sql
mysql -uzabbix -pzabbix zabbix < ${zabbix_install}/database/mysql/schema.sql
mysql -uzabbix -pzabbix zabbix < ${zabbix_install}/database/mysql/images.sql
mysql -uzabbix -pzabbix zabbix < ${zabbix_install}/database/mysql/data.sql
cp ${zabbix_install}/misc/init.d/fedora/core/zabbix_* /etc/init.d/
chmod 775 /etc/init.d/zabbix_*
sed -i ‘/LogFile/s/tmp/var\/log/‘ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘/^DBUser\=/s/root/zabbix/‘ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘/DBPassword\=$/s/^#//g‘ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘/DBPassword\=$/s/^[ \t]//g‘ /usr/local/zabbix/etc/zabbix_server.conf
sed -i ‘/DBPassword\=$/s/\=/&zabbix/g‘ /usr/local/zabbix/etc/zabbix_server.conf
sed -i -e ‘/DBPort\=/s/^#//g‘ /usr/local/zabbix/etc/zabbix_server.conf -e ‘/DBPort\=/s/^[ \t]//g‘ /usr/local/zabbix/etc/zabbix_server.conf
mkdir /usr/local/nginx/html/zabbix
cp -rf ${zabbix_install}/frontends/php/* /usr/local/nginx/html/zabbix/
chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R
chmod o+w /usr/local/nginx/html/zabbix/conf
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
touch /var/log/zabbix_server.log
chown zabbix:zabbix /var/log/zabbix_server.log
chmod 775 /var/log/zabbix_server.log
/etc/init.d/zabbix_server start
check_service zabbix_server "/etc/init.d/zabbix_server start"
/etc/init.d/zabbix_agentd start
check_service zabbix_agentd "/etc/init.d/zabbix_agentd start"
chkconfig --add zabbix_server
chkconfig --add zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
touch /usr/local/nginx/logs/zabbix.access.log
/etc/init.d/nginx reload
echo ‘‘
echo ‘mysql database password for root is redhat‘
echo "installer log files are saved at ${path}/log/install.log,Thanks for Using"
echo "Access http://ip/zabbix configuration zabbxi"
}
#
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 1
else
if [[ ${System} != ‘centos‘ ]] || [[ ${processor} != ‘x86_64‘ ]];then
echo ‘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
fi
fi


本文出自 “鹏城-酱油瓶” 博客,谢绝转载!

LNMP+Zabbix一键安装脚本

标签:lnmp   zabbix   

原文地址:http://yfshare.blog.51cto.com/8611708/1662138

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!