#!/bin/bash
#filename:test.sh#author:viticm
#createtime:2013-5-31 11:12:03#use:installweb develop
cUser=`whoami`
cCommand=$1cDownload=on
cBase=no
cWebUser=www
cInstallFile=/web/cInstallPhpPath=/usr/local/php/cInstallNginxPath=/usr/local/nginx/cInstallMysqlPath=/usr/local/mysql/cPhpMakefile=/home/Makefile
iSystemType=`getconf LONG_BIT`
Arr_OpenPortList=""cTestDomain=www.baidu.com
##### mysql config #####
cMysqlDefaultPasswd=mysql
cMysqlInstallPath=/usr/local/mysql/cMysqlConfUploadFile=`pwd`/my.cnf
##### mysql config #####
####### PHP #######
cDate_TimeZone="Asia/Shanghai"cDisplay_Errors=On
cError_Reporting="E_ALL & ~E_NOTICE"cAllow_Call_Time_Pass_Reference=On
###### PHP ########
#### PHP-FPM CONFIGS ####
pm_max_children=64pm_start_servers=20pm_min_spare_servers=5pm_max_spare_servers=35pm_max_requests=1024pm_user=${cWebUser}
pm_group=${cWebUser}
#### PHP-FPM CONFIGS ####
usage()
{cat <
Usage: $0
-m or --mysql installmysql-n or --nginx installnginx-p or --php install php( and this can enter two params,like -p 5.3( 5.4 ) then install php what version is 5.3)
EOF
return0}
# on OEL,/etc/issue states "Enterprise Linux Enterprise Linux Server"SUPPORTED_OS='CentOS|Red Hat Enterprise Linux Server|Enterprise Linux Enterprise Linux Server|Fedora|SUSE|Debian GNU/Linux|Ubuntu|Oracle Linux Server'
if ! egrep -q "$SUPPORTED_OS" /etc/issue ; then
cat <
Unable toinstall: Your distribution is not suitable forinstallation using
Zend's DEB/RPM repositories.
EOF
exit1
fi#-v or --versionif [ "$1" = "-v" -o "$1" = "--version" ]; then
echo "`basename $0` version 1.0.1"usage
exit0
fi#-h or --helpif [ "$1" = "-h" -o "$1" = "--help" ]; thenusage
exit0
fiMYUID=`id -u 2> /dev/null`if [ ! -z "$MYUID" ]; then
if [ $MYUID != 0 ]; then
echo "You need root privileges to run this script.";
#exit2
fi
else
echo "Could not detect UID";
exit2
fi
cat <
Hit ENTER toinstall web develop, or Ctrl+C to abort now.
EOF
# give read a parameter, as it requiredindash
read answer
#BasefunctionInstallBasePackage()
{echo
echo "************************************************************************"
echo "* Start install Base package( vim git wget base for mysql php nginx ). *"
echo "************************************************************************"#clean iptables
#echo -e "\e[0;36;1mfirst will clean iptables,please wait.\e[0m"# iptables-F
# iptables-X
# iptables-Zif [[ ${cBase} == "ok" ]] ; then
echo -e "\e[0;35;1myour base is ok,now will not install base package.\e[0m"
else#it will download from network .echo -e "\e[0;33;1mnow will test your network if worked,please wait some time.\e[0m"
ping -c 5${cTestDomain}if [[ $? -ne 0 ]] ; then
echo -e "\e[0;31;1myour network not worked,please check it.\e[0m"exit1
else
echo -e "\e[0;35;1myour network is worked,now will download from your network.\e[0m"
fi
fi
if [[ ${cBase} == "no" ]] ; then#vim
#yum -y installvimyum -y installctagsyum -y installcscopeyum -y installntp
#gityum -y installgit
#wget
yum -y install wget#gcc
yum -y install yum-fastestmirroryum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
#Nginxyum -y install pcre-devel zlib-devel readline-devel
#Phpyum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel
#Mysqlyum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel*#bcyum -y installbcfi#synchronoustimechkconfig ntpd on
ntpdate cn.pool.ntp.org
hwclock--systohc
#config ulimit configsechonow will config limit allow handles.echo "* soft nofile 2048" >> /etc/security/limits.confecho "* hard nofile 32768" >> /etc/security/limits.confecho "config limits is ok, remember reboot your server."
if [[ $? -ne 0 ]] ; then
echo -e "\e[0;31;1minstall base is failed.\e[0m"exit1
fi
echo
echo "**************************************"
echo "* Install base package is completed. *"
echo "**************************************"}
#MysqlfunctionInstallMysql()
{echo
echo "**********************************************"
echo "* Start install mysql( Percona-Server-5.6 ). *"
echo "**********************************************"local cMysqlPackage="Percona-Server-5.6.10-alpha60.2.tar.gz"local cMysqlPackageDir="Percona-Server-5.6.10-alpha60.2"
if [[ ${cBase} == "no" ]] ; then
yum -y install make
yum -y installcmakeyum -y install libtermcap-develyum -y install patch
yum -y install perl
yum -y installbisonfi
if [[ ${cDownload} == "off" ]] ; thencd ${cInstallFile}fi
if [ -x ./${cMysqlPackageDir} ]then#rm -fr Percona-Server-5.1.62
echo "Percona is exists,use it."
else
if [ -f ./${cMysqlPackage} ]then
tar -zxvf ${cMysqlPackage}else
wget -c http://www.percona.com/redir/downloads/Percona-Server-5.6/Percona-Server-5.6.10-alpha60.2/source/Percona-Server-5.6.10-alpha60.2.tar.gz
if [[ $? -ne 0 ]] ; then
echo "download mysql is failed,please check your network."exit1
fi
sleep 3
tar -zxvf ${cMysqlPackage}fi
fi
echo "start install mysql"
sleep 3#delete mysqlinstalldirectory
cd ${cMysqlPackageDir}if [[ "" != `ps -A | grep mysqld` ]]; thenPRINTWARNING"mysql is install and run now will uninstall it, or Ctrl+C to abort now."read answer
service mysql stop
#makeclean
#makeuninstallrm -rf ${cMysqlInstallPath}fiCC=gcc CFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -O3" CXX=g++ CXXFLAGS="-DBIG_JOINS=1 -DHAVE_DLOPEN=1 -felide-constructors -fno-rtti -O3"cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_MYISAM_STORAGE_ENGINE=1\-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITH_READLINE=1\-DENABLED_LOCAL_INFILE=1\-DMYSQL_DATADIR=/var/mysql/datasleep 3
make -j4 && make installgroupadd mysql
useradd-g mysql mysql
cd ${cMysqlInstallPath}&& chown -R mysql . && chgrp -R mysql .echo "make install is ok"
sleep 3
mkdir -p /var/mysql/data && chown mysql:mysql /var/mysql/ -Rif [[ -f ${cMysqlConfUploadFile} ]] ; then
cp ${cMysqlConfUploadFile} /etc/my.cnfelse
cp ${cMysqlInstallPath}support-files/my-default.cnf /etc/my.cnf
#sed "s/skip-locking/external-locking/g" -i /etc/my.cnf
#sed "s/#innodb_/innodb_/g" -i /etc/my.cnf
#sed -i '32 i\default-storage-engine=InnoDB' -i /etc/my.cnffi${cMysqlInstallPath}/scripts/mysql_install_db --basedir=${cMysqlInstallPath}/ --user=mysql --datadir=/var/mysql/dataln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
echo "install_db Initialize the database is complete"
sleep 3
echo "Try to start the database"
cp ${cMysqlInstallPath}support-files/mysql.server /etc/init.d/mysqlcp ${cMysqlInstallPath}/bin/mysql /usr/sbin/service mysql start
cd ${cMysqlInstallPath}&& chown -R mysql . && chgrp -R mysql .echo "Database startup is complete"
sleep 3
echo "Change your password after 10 seconds"
sleep 10cd ${cMysqlInstallPath}&& ./bin/mysqladmin -uroot password ${cMysqlDefaultPasswd}if [[ "" == `cat /etc/rc.d/rc.local | grep "service mysql start"` ]] ; then
echo "service mysql start" >> /etc/rc.d/rc.localfi
if [[ $? -ne 0 ]] ; then
echo -e "\e[0;31;1mInstallation fails, check the above error\e[0m"exit1
else
echo -e "\e[0;34;1mCongratulations, the installation was successful.Directory:"${cMysqlInstallPath}"\e[0m"
fi
echo
echo "**********************************************************"
echo "* Install Mysql is completed.( Use Percona-Server-5.6 ). *"
echo "**********************************************************"}
#NginxfunctionInstallNginx()
{
cd ${cInstallFile}
local cNginxPackage=tengine-2.0.0.tar.gz
local cNginxPackageDir=tengine-2.0.0
echo
echo "***************************************"
echo "* Start install Nginx( Use tengine ). *"
echo "***************************************"
#if [[ "" != `ps -A | grep nginx` ]]; then# PRINTWARNING"mysql is install and run now will uninstall it, or Ctrl+C to abort now."# service nginx stop
#makeuninstall
#rm -rf ${cInstallNginxPath}
#figroupadd www
useradd-g www wwwif [[ ${cDownload} == "on" ]] ; then
echo -e "\e[0;33;1mnow download package form website,check your network if failed!\e[0m"#Nginx1.3.0
if [[ -f ${cInstallFile}${cNginxPackage} ]] ; then
echo${cNginxPackage} is found.else
echonow will download ${cNginxPackage} from network.wget -c http://tengine.taobao.org/download/${cNginxPackage}
fi#opensslif [[ -f ${cInstallFile}openssl-1.0.1c.tar.gz ]] ; then
echo openssl-1.0.1c.tar.gz is found.else
echo now will download openssl-1.0.1c.tar.gz from network.wget -c http://www.openssl.org/source/openssl-1.0.1c.tar.gz
fi#Nginx(pcre)
#if [[ -f ${cInstallFile}pcre-8.30.tar.gz ]] ; then#echo pcre-8.30.tar.gz is found.
#else#echo now will download pcre-8.30.tar.gz from network.
#wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.30/pcre-8.30.tar.gz
# fibExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1mdownload package is failed,Please check your network.\e[0m"exitfi
fi#installpcre
#tar -zxvf pcre-8.30.tar.gz && cd pcre-8.30/ && ./configure
#make -s -j4 && make install# cd ../#installopensslif [[ -d openssl-1.0.1c ]] ; thenPRINTUSEDIR openssl-1.0.1celse
tar zxvf openssl-1.0.1c.tar.gz #&& cd openssl-1.0.1cfi# ./config --prefix=/usr/local/ --openssldir=/usr/local/openssl-1.0.1c shared zlib-dynamic enable-camellia enable-tlsext -fPIC
#make && make install && cd ../#installnginxif [[ -d ${cNginxPackageDir} ]] ; thenPRINTUSEDIR ${cNginxPackageDir}else
tar -xzvf ${cNginxPackage}ficd ${cInstallFile}${cNginxPackageDir}makeclean
./configure --user=${cWebUser} --group=${cWebUser} \--prefix=${cInstallNginxPath} \--sbin-path=${cInstallNginxPath}sbin/nginx \--conf-path=${cInstallNginxPath}conf/nginx.conf \--with-http_stub_status_module \--lock-path=/var/run/nginx.lock \--pid-path=/var/run/nginx.pid \--with-openssl=../openssl-1.0.1c \--with-pcre-jitsleep 10
make && make installbExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1minstall nginx have some error,you can read it.\e[0m"exitelse
echo -e "\e[0;34;1mgood luck! install nginx sucess! \e[0m"
fi
#if install nginx is sucess,then will config it.#echo "Now will config the nginx,please wait."
if [[ -f ${cNginxConfFile} ]] ; then
cp -n ${cNginxConfFile} ${cInstallNginxPath}conf/nginx.confelse
sed -e "2 c\user ${cWebUser};" -i ${cInstallNginxPath}conf/nginx.conffi#start nginx and set start on bootecho ${cInstallNginxPath}sbin/nginx >> /etc/rc.d/rc.local
${cInstallNginxPath}sbin/nginx
#open port3306 and 80iptables-I INPUT -p tcp --dport 80 -j ACCEPT
iptables-I OUTPUT -p tcp --sport 80 -j ACCEPT
iptables-I INPUT -p tcp --dport 3306 -j ACCEPT
iptables-I OUTPUT -p tcp --sport 3306 -j ACCEPT/etc/rc.d/init.d/iptables save
service iptables restartecho
echo "***********************************************"
echo "* Install Nginx is completed.( Use tengine ). *"
echo "***********************************************"}
#PHPfunctionInstallPHP()
{
cd ${cInstallFile}echo
echo "**********************************************"
echo "* Start install PHP.( Default version 5.3 ). *"
echo "**********************************************"local cPhpVersion=${2}
local cPhpPackage=""local cPhpPackageDir=""
if [[ -z ${cPhpVersion} ]]; then
echo install default php version 5.3cPhpVersion="5.3"cPhpPackage="php-5.3.28.tar.bz2"cPhpPackageDir="php-5.3.28"
else
if [[ "5.3" != ${cPhpVersion} && "5.4" != ${cPhpVersion} ]]; thenUseage
exit1
else
if [[ "5.3" == ${cPhpVersion} ]]; thencPhpPackage="php-5.3.28.tar.bz2"cPhpPackageDir="php-5.3.28"
elsecPhpPackage="php-5.4.15.tar.bz2"cPhpPackageDir="php-5.4.15"
fi
fi
fi
if [[ ${cDownload} == "on" ]] ; then
echo now download package form website,check your network if failed!#PHP5.3.14
if [[ -f ${cInstallFile}${cPhpPackage} ]] ; then
echo${cPhpPackage} is found.else
echonow will download php package from network.wget -c http://cn.php.net/distributions/${cPhpPackage}
fi#PHPif [[ -f ${cInstallFile}mcrypt-2.6.8.tar.gz ]] ; then
echo mcrypt-2.6.8.tar.gz is found.else
echo now will download mcrypt-2.6.8.tar.gz from network.wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
fi
if [[ -f ${cInstallFile}mhash-0.9.9.9.tar.gz ]] ; then
echo mhash-0.9.9.9.tar.gz is found.else
echo now will download mhash-0.9.9.9.tar.gz from network.wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
fi
if [[ -f ${cInstallFile}libmcrypt-2.5.8.tar.gz ]] ; then
echo libmcrypt-2.5.8.tar.gz is found.else
echo now will download libmcrypt-2.5.8.tar.gz from network.wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
fi
if [[ -f ${cInstallFile}libiconv-1.14.tar.gz ]] ; then
echo libiconv-1.14.tar.gz is found.else
echo now will download libiconv-1.14.tar.gz from network.wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
fi
if [[ -f ${cInstallFile}memcache-3.0.6.tgz ]] ; then
echo memcache-3.0.6.tgz is found.else
echo now will download memcache-3.0.6.tgz from network.wget http://pecl.php.net/get/memcache-3.0.6.tgz
fi
if [[ -f ${cInstallFile}PDO_MYSQL-1.0.2.tgz ]] ; then
echo PDO_MYSQL-1.0.2.tgz is found.else
echo now will download PDO_MYSQL-1.0.2.tgz from network.wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
fibExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1mdownload package failed,you can check your network if can work.\e[0m"exitfi
fi
echo "install some plugin for php"#1
if [[ -d libiconv-1.14/ ]] ; thenPRINTUSEDIR libiconv-1.14/
else
tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14/
fi./configure --prefix=/usr/localmake -s -j4 && make install && cd ../
sleep 1#2
if [[ -d libmcrypt-2.5.8/ ]] ; thenPRINTUSEDIR libmcrypt-2.5.8/
else
tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/
fi./configure && make && make install
/sbin/ldconfig && cd libltdl/ && ./configure --enable-ltdl-install
make -s -j4 && make install && cd ../ && cd ../
sleep 2#3
if [[ -d mhash-0.9.9.9/ ]] ; thenPRINTUSEDIR mhash-0.9.9.9/
else
tar -zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9/
fi./configuremake -s -j4 && make install && cd ../
sleep 3#4
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configsleep 1#5
/sbin/ldconfigif [[ -d mcrypt-2.6.8/ ]] ; thenPRINTUSEDIR mcrypt-2.6.8/
else
tar -zxvf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
fi./configuremake -s -j4 && make install && cd ../
sleep 2bExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1minstall package false,please read the errors.\e[0m"exitfi
echo install plugin forphp is completed.echo now will installphp, version is ${cPhpVersion}
#64 OR 32SYSTEM LIB MUST BE DIFFERENTif [[ ${iSystemType} == 64 ]] ; then
cp -frp /usr/lib64/libldap* /usr/libfi#6cd ${cInstallFile}if [[ -d ${cPhpPackageDir} ]] ; thenPRINTUSEDIR ${cPhpPackageDir}else
tar -xjvf ${cPhpPackage}
cd ${cPhpPackageDir}fi./configure --prefix=${cInstallPhpPath} \--with-config-file-path=${cInstallPhpPath}etc \--with-iconv-dir=/usr/local/ --with-freetype-dir\--with-mysql=${cInstallMysqlPath} \--with-mysqli=${cInstallMysqlPath}bin/mysql_config \--with-jpeg-dir --with-png-dir --with-zlib \--with-mhash --enable-sockets --enable-ftp\--with-libxml-dir --enable-xml --disable-rpath \--enable-safe-mode --enable-bcmath \--enable-shmop --enable-sysvsem \--enable-inline-optimization --with-curl \--with-curlwrappers \--enable-mbregex \--enable-mbstring --with-mcrypt --with-gd \--enable-gd-native-ttf --with-openssl --with-mhash \--enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl \--enable-fpm \--with-xmlrpc --enable-zip --enable-soap \--without-pear;make -s -j4 ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production ${cInstallPhpPath}etc/php.iniln -s ${cInstallPhpPath}bin/php /usr/sbin/php
#now we can config php.inised "538 c\display_errors = ${cDisplay_Errors}" -i ${cInstallPhpPath}etc/php.inised "521 c\error_reporting = ${cError_Reporting}" -i ${cInstallPhpPath}etc/php.inised "334 c\allow_call_time_pass_reference = ${cAllow_Call_Time_Pass_Reference}" -i ${cInstallPhpPath}etc/php.inised "1008 c\date.timezone = ${cDate_TimeZone}" -i ${cInstallPhpPath}etc/php.ini
bExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1minstall PHP failed,you can read the errors or send email to me.\e[0m"exitfi
echo -------------------------------end-----------------------------------cd ${cInstallFile}echo "######################install Extensions for PHP#################"
echo -------------------------------start---------------------------------
if [[ -d memcache-3.0.6/ ]] ; thenPRINTUSEDIR memcache-3.0.6/
else
tar -zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
fi${cInstallPhpPath}bin/phpize
./configure --with-php-config=${cInstallPhpPath}bin/php-configsleep 1
make -s -j4 && make install && cd ../
if [[ -d PDO_MYSQL-1.0.2/ ]] ; thenPRINTUSEDIR PDO_MYSQL-1.0.2/
else
tar -zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
fi${cInstallPhpPath}bin/phpize
./configure --with-php-config=${cInstallPhpPath}bin/php-config --with-pdo-mysql=${cInstallMysqlPath}make -s -j4 && make install && cd ../
echo "[PDO_MYSQL]" >> ${cInstallPhpPath}etc/php.iniecho "extension=pdo_mysql.so" >> ${cInstallPhpPath}etc/php.iniif [[ $? -ne 0 ]] ; then
echo -e "\e[0;31;1minstall extensions for php is failed.\e[0m"exit1
fi
sleep 5#PHP-FPM/usr/sbin/groupadd ${cWebUser} && /usr/sbin/useradd -g ${cWebUser} ${cWebUser}mkdir -p /var/log/nginx && chmod +w /var/log/nginx &&chown -R ${cWebUser}:${cWebUser} /var/log/nginxmkdir -p /data/${cWebUser} && chmod +w /data/${cWebUser} && chown -R ${cWebUser}:${cWebUser} /data/${cWebUser}cp -n ${cInstallPhpPath}etc/php-fpm.conf.default ${cInstallPhpPath}etc/php-fpm.confif [[ -f ${cPhpFpmConfFile} ]] ; then
cp -n ${cPhpFpmConfFile} ${cInstallPhpPath}etc/php-fpm.confelse
sed "s/;pid = /pid = /g" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/;error_log = /error_log = /g" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/pm.max_children = .*/pm.max_children = ${pm_max_children}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/pm.start_servers = .*/pm.start_servers = ${pm_start_servers}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/pm.min_spare_servers =.*/pm.min_spare_servers = ${pm_min_spare_servers}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/pm.max_spare_servers =.*/pm.max_spare_servers = ${pm_max_spare_servers}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/pm.max_requests =.*/pm.max_spare_servers = ${pm_max_requests}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/user =.*/user = ${pm_user}/" -i ${cInstallPhpPath}etc/php-fpm.confsed "s/group =.*/group = ${pm_group}/" -i ${cInstallPhpPath}etc/php-fpm.conffi#start php-fpm and set start on bootcp ${cInstallFile}${cPhpPackageDir}/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpmchmod +x /etc/rc.d/init.d/php-fpmecho service php-fpm start >> /etc/rc.d/rc.local
service php-fpm start
bExit=`echo $?`if [[ ${bExit} != 0 ]] ; then
echo -e "\e[0;31;1minstall Extensions for PHP failed! \e[0m"exit1
else
echo -e "\e[0;34;1mgood luck! you install Extensions for PHP is secess! \e[0m"
fi}
#download tipsfunctionDownloadTip()
{if [[ ${cDownload} == "on" ]] ; then
echo -e "\e[0;35;1mDownload is on,the package will download from website.Please check your network is worked.\e[0m"
else
echo -e "\e[0;30;1mDownload is off,make sure your package is Existing.\e[0m"
#if download if off,now can download from our svn.
fi
if [[ -f ${cOtherOfflinePackageFile} ]] ; then
tar -xzvf ${cOtherOfflinePackageFile} -C ${cInstallFile}fi}
#thisfunction can use insert string above lastline
#this have two parameters,one isstring another is filepath.
#string ervery line must be division by '|'
functionInsertStrAboveLastLine()
{
oldIFS=$IFS
IFS="|"
for item in $1
doiInsertLine=`awk 'END{print NR}' $2`
cNewItem=`echo ${item} | sed '/^$/d'`if [[ ${cNewItem} != "" ]] ; then#echo this is null
#else#echoitem:${cNewItem}sed -e "${iInsertLine} i\ ${cNewItem}" -i $2
fi#iInsertLine=`awk 'END{print NR}'${cTestFile}`
#sed -e "${iInsertLine} i\ ${item}" -i ${cTestFile}doneIFS=$oldIFS
}
#@desc: set iptable rules
#@param: void
#@return: voidfunctionSetIptables()
{
Arr_OpenPortList="${1}"
echonow will config iptables, open port list is:
PrintArrList"${Arr_OpenPortList}"
for port in${Arr_OpenPortList}doiptables-I INPUT -i eth0 -p tcp --dport ${port} -j ACCEPT
iptables-I OUTPUT -o eth0 -p tcp --sport ${port} -j ACCEPTdone
/etc/init.d/iptables save
service iptables restart
}
#@desc: print array list
#@param: array
#@return voidfunctionPrintArrList()
{
Arr_List="${1}"
for item in${Arr_List}do
echo -e "\e[0;33;1m${item}\e[0m"
done}
#@desc:print usedirstr
#@param:string dirname#@return: voidfunctionPRINTUSEDIR()
{
cDirName=$1
echo ${cDirName} is found, use it and makeuninstall.
cd ${cDirName}&& makeuninstall
}
#@desc print red error and exit
#@paramstring$cErrorStr
#@return voidfunctionPRINTERR()
{
cErrorStr=${1}echo -e "\e[0;31;1mERROR:${cErrorStr}\e[0m"exit1}
#@desc print yellow warning and not exit
#@paramstring$cWarningStr
#@return voidfunctionPRINTWARNING()
{
cWarningStr=${1}echo -e "\e[0;33;1mWARNING:${cWarningStr}\e[0m"}
#createinstall file
if [[ $cCommand != -base ]] ; then`mkdir -p ${cInstallFile}`
bInstallFile=`echo $?`if [[ $bInstallFile != 0 ]] ; then
echo -e "\e[0;31;1mmake ${cInstallFile} file is failed! \e[0m"exitelsecd ${cInstallFile}fi
fi###################main##################if [[ $cCommand == "-base" ]] ; thenDownloadTip
#if [[ ${cDownload} == "off" ]] ; then#echoDownload is off,please modify it.
# exit
#elseInstallBasePackage
#fi
elif [[ $cCommand == "-m" || "--mysql" == ${cCommand} ]] ; thenDownloadTip
InstallMysqlelif [[ $cCommand == "-n" || "--nginx" == ${cCommand} ]] ; thenDownloadTip
InstallNginxelif [[ $cCommand == "-p" || "--php" == ${cCommand} ]] ; thenDownloadTip
InstallPHPelif [[ $cCommand == "--test" ]] ; thenInsertStrAboveLastLine"|1|2|3|4|5|" /home/test.txtelseDownloadTip
InstallBasePackagesleep 3InstallMysqlsleep 3InstallPHPsleep 3InstallNginxsleep 3SetIptables"${Arr_OpenPortList}"exit0
fi