#!/bin/bash #Authors are from JC #From the region BeiJing-China #Contact:[email protected] # Source function library. . /etc/rc.d/init.d/functions cd $shell shell=/shell/script if [ -d /shell/script ];then action "shell安裝目錄已存在:" /bin/true else mkdir -p $shell >/dev/null fi function main_menu() { echo;echo; echo "----------------------------------Linux+Nginx+1.2+MySQL5.5+PHP5.2+Memcache---------------------------------------------" current_date=`date +%Y%m%d-%H:%M:%S` dis_manumenu="《線上服務器${ip}安裝服務菜單》" cat <<EOF 當前時間為:$current_date ============================================================== $dis_manumenu ============================================================== -->[lnmp服務器自動化版本程序 ]:<-- **1)安裝lnmp服務(make && make install) **2)查看lnmp啟動服務端口(tcp:80,3306,9000) **3)啟動lnmp服務端口 **4)關閉lnmp服務端口 **5)回滾之前操作(即恢復lnmp安裝前的狀態) **6)備份lnmp環境 **7)還原lnmp環境 ############################################################### =============================================================== EOF } main_menu read -p "請選擇: " num ##############編譯前的依賴環境安裝############################ case $num in 1) echo "-------------------------------------現在開始安裝lnmp+memcache環境----------------------------------------------------------" sleep 3 cd /etc/yum.repos.d wget http://mirrors.163.com/.help/CentOS-Base-163.repo yum -y install ntp rsync sudo /usr/sbin/ntpdate pool.ntp.org yum -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 make libXp* gcc-c++ autoconf ncurses ncurses-devel echo 'export LC_ALL=C'>> /etc/profile source /etc/profile #cd $shell #[ ! -f cmake-2.8.4.tar.gz ] && \ #wget -P/shell/script/ -c http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz && echo "cmake-2.8.4.tar.gz download is OK" # cd $shell # tar zxvf cmake-2.8.4.tar.gz # cd cmake-2.8.4 # ./configure # gmake # gmake install sleep 3 cd $shell [ ! -f bison-2.5.tar.gz ] && \ wget -P /shell/script/ -c http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz && echo "bison-2.5.tar.gz download is OK" sleep 2 cd $shell tar zxvf bison-2.5.tar.gz cd bison-2.5 ./configure && make && make install sleep 3 ##############編譯安裝MySQL5.1.56版本數據庫################### yum -y install cmake cd $shell [ ! -f mysql-5.5.19.tar.gz ] && \ wget -P/shell/script/ -c http://down1.chinaunix.net/distfiles/mysql-5.5.19.tar.gz && echo "mysql-5.5.19.tar.gz download is OK" cd $shell groupadd mysql useradd -s /sbin/nologin -g mysql -M mysql tar zxvf mysql-5.5.19.tar.gz cd $shell/mysql-5.5.19 /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STOPAGE_ENGINE=1 -DWITH_BLACKHOLE_STOPAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP-PORT=3306 make && make install chmod +w /usr/local/mysql chown -R mysql:mysql /usr/local/mysql ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16 mkdir -p /var/mysql/ mkdir -p /var/mysql/data/ mkdir -p /var/mysql/log/ chown -R mysql:mysql /var/mysql/ cd support-files/ cp my-large.cnf /var/mysql/my.cnf cp mysql.server /etc/init.d/mysqld /usr/local/mysql/scripts/mysql_install_db --defaults-file=/var/mysql/my.cnf --basedir=/usr/local/mysql/ --datadir=/var/mysql/data/ --user=mysql chmod 700 /etc/init.d/mysqld echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile source /etc/profile ln -s /usr/local/mysql/bin/* /usr/bin/ sed -i '46s#basedir=#basedir=/usr/local/mysql/#' /etc/init.d/mysqld sed -i '47s#datadir=#datadir=/var/mysql/data/#' /etc/init.d/mysqld chkconfig --add mysqld chkconfig --level 345 mysqld on /etc/init.d/mysqld restart action "mysql5.5.19版本安裝完成" /bin/true action "mysql5.5.19版本安裝完成" /bin/true sleep 3 ############編譯安裝libiconv1.13.1版本############################################# cd $shell [ ! -f libiconv-1.13.1.tar.gz ] && \ wget -P $shell -c http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz echo "libiconv-1.13.1.tar.gz download is OK" sleep 3 cd $shell tar zxvf libiconv-1.13.1.tar.gz cd libiconv-1.13.1 ./configure --prefix=/usr/local && make && make install action "libiconv1.13.1版本安裝完成" /bin/true action "libiconv1.13.1版本安裝完成" /bin/true sleep 3 cd $shell [ ! -f libmcrypt-2.5.8.tar.gz ] && \ wget -P $shell -c http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz echo "libmcrypt-2.5.8.tar.gz download is OK" sleep 3 cd $shell tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure && make && make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make && make install action "libmcrypt2.5.8版本安裝完成" /bin/true action "libmcrypt2.5.8版本安裝完成" /bin/true sleep 3 ############編譯安裝mhash0.9.9.9.9版本############################################# cd $shell [ ! -f mhash-0.9.9.9.tar.gz ] && \ wget -P /shell/script/ -c "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0" echo "mhash-0.9.9.9.tar.gz download is OK" sleep 3 cd $shell tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure && make && make install ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -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.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -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-config action "mhash0.9.9.9版本安裝完成" /bin/true action "mhash0.9.9.9版本安裝完成" /bin/true #################編譯安裝mcrypt2.6.8版本############################################## cd $shell [ ! -f mcrypt-2.6.8.tar.gz ] && \ wget -P /shell/script -c "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0" echo "mcrypt-2.6.8.tar.gz download is OK" sleep 3 cd $shell tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./configure make && make install sleep 3 ################編譯安裝php5.2.17 or patch php5.2.17#################################### cd $shell [ ! -f php-5.2.17.tar.gz ] && \ wget -P /shell/script -c http://www.php.net/get/php-5.2.17.tar.gz/from/this/mirror echo "php-5.2.17.tar.gz download is OK" sleep 3 cd $shell [ ! -f php-5.2.17-fpm-0.5.14.diff.gz ] && \ wget -P /shell/script -c http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz echo "php-5.2.17-fpm-0.5.14.diff.gz download is OK" sleep 3 cd $shell tar -zxvf php-5.2.17.tar.gz gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 cd php-5.2.17/ ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap make ZEND_EXTRA_LIBS='-liconv' make install cp php.ini-dist /usr/local/php/etc/php.ini ############編譯安裝memcache2.2.5版本########################### yum -y install libevent libevent-devel cd $shell [ ! -f memcached-1.2.5.tar.gz ] && \ wget -P /shell/script -c http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz echo "memcache-1.2.5.tar.gz download is OK" sleep 3 cd $shell tar zxvf memcached-1.2.5.tar.gz cd memcached-1.2.5 ./configure --prefix=/usr/local/memcache make && make install cd $shell [ ! -f memcache-2.2.5.tgz ] && \ wget -P /shell/script -c http://pecl.php.net/get/memcache-2.2.5.tgz echo "memcache-2.2.5.tgz download is OK" sleep 3 cd $shell tar zxvf memcache-2.2.5.tgz cd memcache-2.2.5/ /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install ##########編譯安裝eaccelerator0.9.6.1版本######################## cd $shell [ ! -f eaccelerator-0.9.6.1.tar.bz2 ] && \ wget -P /shell/script -c http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2 echo "eaccelerator-0.9.6.1.tar.bz2 download is OK" sleep 3 cd $shell tar -xjvf eaccelerator-0.9.6.1.tar.bz2 cd eaccelerator-0.9.6.1 /usr/local/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config make && make install ##########編譯安裝PDO_MYSQL1.0.2版本############################# cd $shell [ ! -f PDO_MYSQL-1.0.2.tgz ] && \ wget -P /shell/script -c http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz echo "PDO_MYSQL-1.0.2.tgz download is OK" sleep 3 cd $shell tar zxvf PDO_MYSQL-1.0.2.tgz cd PDO_MYSQL-1.0.2/ rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql make && make install #########編譯安裝ImageMagick6.7.1.0版本########################## cd $shell [ ! -f ImageMagick.tar.gz ] && \ wget -P /shell/script -c http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz echo "ImageMagick.tar.gz download is OK" sleep 3 cd $shell tar -zxvf ImageMagick.tar.gz cd ImageMagick-6.5.1-2 ./configure && make && make install #######編譯安裝imagick2.3.0版本################################# cd $shell [ ! -f imagick-2.3.0.tgz ] && \ wget -P /shell/script -c http://pecl.php.net/get/imagick-2.3.0.tgz echo "imagick-2.3.0.tgz download is OK" sleep 3 cd $shell tar zxvf imagick-2.3.0.tgz cd imagick-2.3.0 /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/php/etc/php.ini sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/php/etc/php.ini mkdir -p /usr/local/eaccelerator_cache sed -i '1290a [eaccelerator]' /usr/local/php/etc/php.ini sed -i '1291a zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"' /usr/local/php/etc/php.ini sed -i '1292a eaccelerator.shm_size="64"' /usr/local/php/etc/php.ini sed -i '1293a eaccelerator.cache_dir="/usr/local/eaccelerator_cache"' /usr/local/php/etc/php.ini sed -i '1294a eaccelerator.enable="1"' /usr/local/php/etc/php.ini sed -i '1295a eaccelerator.optimizer="1"' /usr/local/php/etc/php.ini sed -i '1296a eaccelerator.check_mtime="1"' /usr/local/php/etc/php.ini sed -i '1297a eaccelerator.debug="0"' /usr/local/php/etc/php.ini sed -i '1298a eaccelerator.filter=""' /usr/local/php/etc/php.ini sed -i '1299a eaccelerator.shm_max="0"' /usr/local/php/etc/php.ini sed -i '1300a eaccelerator.shm_ttl="3600"' /usr/local/php/etc/php.ini sed -i '1301a eaccelerator.shm_prune_period="3600"' /usr/local/php/etc/php.ini sed -i '1302a seaccelerator.shm_only="0"' /usr/local/php/etc/php.ini sed -i '1303a eaccelerator.compress="1"' /usr/local/php/etc/php.ini sed -i '1304a eaccelerator.compress_level="9"' /usr/local/php/etc/php.ini /usr/sbin/groupadd www /usr/sbin/useradd -g www www mkdir -p /var/www/wiki mkdir -p /var/www/memcache mkdir -p /var/www/phpmyadmin chmod +w /var/www/memcache chmod +w /var/www/phpmyadmin chmod +w /var/www/wiki chown -R www:www /var/www/wiki chown -R www:www /var/www/memcache chown -R www:www /var/www/phpmyadmin sed -i '58s#<!--##g' /usr/local/php/etc/php-fpm.conf sed -i '58s#-->##g' /usr/local/php/etc/php-fpm.conf sed -i '59s#<!--##g' /usr/local/php/etc/php-fpm.conf sed -i '59s#-->##g' /usr/local/php/etc/php-fpm.conf sed -i '63s#<!--##g' /usr/local/php/etc/php-fpm.conf sed -i '63s#-->##g' /usr/local/php/etc/php-fpm.conf sed -i '66s#<!--##g' /usr/local/php/etc/php-fpm.conf sed -i '66s#-->##g' /usr/local/php/etc/php-fpm.conf sed -i '63s#nobody#www#g' /usr/local/php/etc/php-fpm.conf sed -i '66s#nobody#www#g' /usr/local/php/etc/php-fpm.conf sed -i '79s#5#128#g' /usr/local/php/etc/php-fpm.conf sed -i '113s#1024#20480#g' /usr/local/php/etc/php-fpm.conf sed -i '132s#500#1024#g' /usr/local/php/etc/php-fpm.conf ulimit -SHn 65535 /usr/local/php/sbin/php-fpm start ###############編譯安裝pcre8.31版本 or Nginx1.21版本########################## cd $shell [ ! -f pcre-8.31.tar.gz ] && \ wget -P /shell/script -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz echo "pcre-8.31.tar.gz download is OK" sleep 3 cd $shell tar -zxvf pcre-8.31.tar.gz cd pcre-8.31 ./configure && make && make install cd $shell [ ! -f nginx-1.2.1.tar.gz ] && \ wget -P /shell/script -c http://www.nginx.org/download/nginx-1.2.1.tar.gz echo "nginx-1.2.1.tar.gz download is OK" sleep 3 cd $shell tar -zxvf nginx-1.2.1.tar.gz cd nginx-1.2.1 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make && make install //