天天看點

自己寫的一個安裝LNMP環境的腳本

#!/bin/bash   

INSTALL_SRC=/root/install_lnmp/src  

INSTALL_SCRIPT=/root/install_lnmp/script  

INSTALL_CONF=/root/install_lnmp/conf  

if [ $(id -u) != "0" ]; then  

    echo "Error: You must run this script as root!!!"  

    exit 1  

fi  

clear  

printf "=============================================\n"  

printf " Install lnmp made by Henry He on 2011/05/15 \n"  

printf "         Last update on 2011/05/15           \n"  

echo "pls wait 5 senconds..."  

for i in zlib mhash libmcrypt curl openssl ncurses;do  

    LIB=`echo $i|rpm -qa|grep $i`  

    if [[ "$LIB" == zlib* ]];then  

       echo "zlib [found]!!!"  

       continue  

    elif  

        [[ "$LIB" == mhash* ]];then  

        echo "mhash [found]!!!"  

        continue  

        [[ "$LIB" == libmcrypt* ]];then  

        echo "libmcrypt [found]!!!"  

        [[ "$LIB" == curl* ]];then  

        echo "curl [found]!!!"  

        [[ "$LIB" == openssl* ]];then  

        echo "openssl [found]!!!"  

        [[ "$LIB" == ncurses* ]];then  

        echo "ncurses [found]!!!"  

    else  

        yum install -y $i.x86_64 $i-devel.x86_64  

    fi  

done  

echo ""  

echo "===================="  

echo "   check finished   "  

for a in www mysql;do  

id $a >/dev/null 2>&1  

    if [ $? != 0 ];then  

       groupadd $a && useradd $a -g $a -s /sbin/nologin -d /dev/null -M -c "for $a"  

       echo "www and mysql user has been added to your system..."  

install_mysql() {  

        echo "+-----------------------------------------------------+"  

        echo "+ we will install mysql service on the local computer +"  

        if [ -s "$INSTALL_SRC/mysql-5.0.91.tar.gz" ] && [ ! -d "$INSTALL_SRC/mysql-5.0.91" ];then  

           echo "mysql-5.0.91.tar.gz [found]"  

           cd $INSTALL_SRC && tar xzvf mysql-5.0.91.tar.gz  

           cd mysql-5.0.91  

           ./configure --prefix=/usr/local/mysql  

                       --without-debug                    \  

                       --with-pthread                     \  

                       --enable-thread-safe-client        \  

                       --enable-assembler                 \  

                       --with-client-ldflags=-all-static  \  

                       --with-mysqld-ldflags=-all-static  \  

                       --with-extra-charsets=all          \  

                       --with-charset=utf8                \  

                       --with-big-tables                  \  

                       --with-innobase                    \  

                       --with-innodb                      \  

                       --with-myisam                      \  

                       --enable-local-infile  

             make && make install && make clean  

             if [ $? = 0 ];then  

                 cd /usr/local/mysql/share/mysql  

                 cp mysql.server /etc/init.d/mysql  

                 cp my-medium.cnf /etc/my.cnf  

                 chkconfig --add mysql  

                 chkconfig mysql on  

                 cd /usr/local/mysql  

                 chown -R root:mysql /usr/local/mysql  

                 bin/mysql_install_db --user=mysql  

                 chown -R mysql:mysql var/  

            fi  

        fi  

        echo ""  

        echo "================="  

        echo "     finished    "  

}  

install_nginx() {  

       echo "+----------------------------------------------------+"  

       echo "+ we will install nginx service on the local machine +"  

       cd $INSTALL_SRC  

       if [ -s pcre-8.12.tar.bz2 ] && [ ! -d "pcre-8.12" ];then  

          echo "pcre-8.12.tar.bz2 [found]"  

          tar jxvf pcre-8.12.tar.bz2  

       fi  

       if [ -s openssl-1.0.0d.tar.gz ] && [ ! -d "openssl-1.0.0d" ];then  

          echo "openssl-1.0.0d.tar.gz [found]"  

          tar xzvf openssl-1.0.0d.tar.gz  

       if [ -s nginx-0.9.7.tar.gz ] && [ ! -d "nginx-0.9.7" ];then  

           echo "nginx-0.9.7.tar.gz [found]"  

           tar xzvf nginx-0.9.7.tar.gz  

       cd nginx-0.9.7  

       ./configure --prefix=/usr/local/nginx        \  

                   --user=www                       \  

                   --group=www                      \  

                   --with-http_sub_module           \  

                   --with-http_ssl_module           \  

                   --with-http_gzip_static_module   \  

                   --with-http_stub_status_module   \  

                   --without-mail_imap_module       \  

                   --without-mail_pop3_module       \  

                   --without-mail_smtp_module       \  

                   --with-pcre=../pcre-8.12         \  

                   --with-openssl=../openssl-1.0.0d  

        make && make install && make clean  

        if [ $? = 0 ];then  

           if [ ! -f "/etc/init.d/nginx" ];then  

              cp $INSTALL_SCRIPT/nginx /etc/init.d/  

              chkconfig --add nginx  

              chkconfig nginx on  

           fi  

           if [ -f "/usr/local/nginx/conf/nginx.conf" ];then  

              rm -f /usr/local/nginx/conf/nginx.conf  

              cp $INSTALL_CONF/nginx.conf /usr/local/nginx/conf  

           if [ ! -d "/usr/local/nginx/vhosts" ];then  

              mkdir /usr/local/nginx/vhosts  

              cp $INSTALL_CONF/http-vhosts.conf /usr/local/nginx/vhosts/  

              IP=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|cut -d':' -f2)  

              sed -i "s#192.168.1.5#$IP#" /usr/local/nginx/vhosts/http-vhosts.conf  

              mv $INSTALL_CONF/test.php /usr/local/nginx/html  

install_php() {  

        echo "+-------------------------------------------------------+"  

        echo "+ we willl install php environment on the local machine +"  

        if [ -s "$INSTALL_SRC/php-5.3.5.tar.bz2" ] && [ ! -d "$INSTALL_SRC/php-5.3.5" ];then  

           cd $INSTALL_SRC  

           tar jxvf php-5.3.5.tar.bz2  

        cd php-5.3.5  

        ./configure --prefix=/usr/local/php        \  

                    --with-curl                    \  

                    --with-zlib                    \  

                    --with-mhash                   \  

                    --with-openssl                 \  

                    --with-mcrypt                  \  

                    --with-mysql=/usr/local/mysql  \  

                    --with-fpm-user=www            \  

                    --with-fpm-group=www           \  

                    --enable-xml                   \  

                    --enable-sockets               \  

                    --enable-fpm                   \  

                    --enable-zip                   \  

                    --enable-mbstring              \  

                    --enable-inline-optimization   \  

                    --disable-debug                \  

                    --disable-ipv6  

make && make install && make clean  

           if [ ! -f "/usr/local/php/lib/php.ini" ];then  

              cp php.ini-production /usr/local/php/lib/php.ini  

              sed -i '/;date.timezone/a date.timezone=Asia/Shanghai' /usr/local/php/lib/php.ini  

              sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /usr/local/php/lib/php.ini  

           if [ ! -f "/usr/local/php/etc/php-fpm.conf" ];then  

              cp $INSTALL_CONF/php-fpm.conf /usr/local/php/etc  

           if [ ! -f "/etc/init.d/php-fpm" ];then  

              cd sapi/fpm  

              cp init.d.php-fpm /etc/init.d/php-fpm  

              chmod 755 /etc/init.d/php-fpm  

              chkconfig --add php-fpm  

              chkconfig php-fpm on  

              echo "Starting PHP-FPM..."  

              /etc/init.d/php-fpm start  

         echo ""  

         echo "================="  

         echo "     finished    "  

install_mysql && install_nginx && install_php 

export PATH=$PATH:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin 

[ -f /usr/local/php/bin/phpize ] && [ -x /usr/local/php/bin/phpize ] || exit 1 

if [ -s "$INSTALL_SRC/memcache-2.2.6.tgz" ] && [ ! -d "$INSTALL_SRC/memcache-2.2.6" ];then 

   cd ${INSTALL_SRC} && tar xf memcache-2.2.6.tgz 

   cd memcache-2.2.6 && phpize 

   ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config 

   make && make install && make clean 

fi 

if [ -s "$INSTALL_SRC/xcache-1.3.2.tar.gz" ] && [ ! -d "$INSTALL_SRC/xcache-1.3.2" ];then 

   cd ${INSTALL_SRC} && tar xf xcache-1.3.2.tar.gz 

   cd xcache-1.3.2 && phpize 

   ./configure --enable-xcache --enable-xcache-optimizer --with-php-config=/usr/local/php/bin/php-config 

if [ -s "$INSTALL_SRC/suhosin-0.9.32.1.tar.gz" ] && [ ! -d "$INSTALL_SRC/suhosin-0.9.32.1" ];then 

   cd ${INSTALL_SRC} && tar xf suhosin-0.9.32.1.tar.gz 

   cd suhosin-0.9.32.1 && phpize 

   ./configure --enable-suhosin --with-php-config=/usr/local/php/bin/php-config 

 本文轉自dongfang_09859 51CTO部落格,原文連結:http://blog.51cto.com/hellosa/566007,如需轉載請自行聯系原作者

繼續閱讀