解读lanmp安装文件centos.sh

Posted on Posted in bash
Tips: 本文创建于2013年11月25日,已超过 2 年,内容或图片可能已经失效!
#!/bin/bash  
#####定义环境变量    
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
export PATH  
  
# Check if user is root  
# 检查rootID是否为0   
if [ $(id -u) != "0" ]; then  
    echo "Error: You must be root to run this script, please use root to install lnmp"  
    exit 1  
fi  
  
#####清屏    
clear  
echo "========================================================================="  
echo "LNMP V1.1 for CentOS/RadHat Linux Server, Written by Licess"  
echo "========================================================================="  
echo "A tool to auto-compile & install Nginx+MySQL+PHP on Linux "  
echo ""  
echo "For more information please visit http://www.lnmp.org/"  
echo "========================================================================="  
#####定义变量当前目录    
cur_dir=$(pwd)  
  
#set mysql root password  
    echo "==========================="  
  
    mysqlrootpwd="root"  
    echo "Please input the root password of mysql:"  
    #####用户手动输入mysql密码  
    read -p "(Default password: root):" mysqlrootpwd  
    #####如果没输入,密码就为root   
    if [ "$mysqlrootpwd" = "" ]; then  
        mysqlrootpwd="root"  
    fi  
    echo "==========================="  
    echo "MySQL root password:$mysqlrootpwd"  
    echo "==========================="  
  
#do you want to install the InnoDB Storage Engine?  
echo "==========================="  
#####选择安装InnoDB,默认不安装  
    installinnodb="n"  
    echo "Do you want to install the InnoDB Storage Engine?"  
    read -p "(Default no,if you want please input: y ,if not please press the enter button):" installinnodb  
  
    case "$installinnodb" in  
    y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)  
    echo "You will install the InnoDB Storage Engine"  
    installinnodb="y"  
    ;;  
    n|N|No|NO|no|nO)  
    echo "You will NOT install the InnoDB Storage Engine!"  
    installinnodb="n"  
    ;;  
    *)  
    echo "INPUT error,The InnoDB Storage Engine will NOT install!"  
    installinnodb="n"  
    esac  
  
#which PHP Version do you want to install?  
echo "==========================="  
  
    isinstallphp53="n"  
    echo "Install PHP 5.3.28,Please input y"  
    echo "Install PHP 5.2.17,Please input n or press Enter"  
    read -p "(Please input y or n):" isinstallphp53  
  
    case "$isinstallphp53" in  
    y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)  
    echo "You will install PHP 5.3.28"  
    isinstallphp53="y"  
    ;;  
    n|N|No|NO|no|nO)  
    echo "You will install PHP 5.2.17"  
    isinstallphp53="n"  
    ;;  
    *)  
    echo "INPUT error,You will install PHP 5.2.17"  
    isinstallphp53="n"  
    esac  
  
#which MySQL Version do you want to install?  
echo "==========================="  
  
    isinstallmysql55="n"  
    echo "Install MySQL 5.5.37,Please input y"  
    echo "Install MySQL 5.1.73,Please input n or press Enter"  
    echo "Install MariaDB 5.5.37,Please input md"  
    read -p "(Please input y , n or md):" isinstallmysql55  
  
    case "$isinstallmysql55" in  
    y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)  
    echo "You will install MySQL 5.5.37"  
    isinstallmysql55="y"  
    ;;  
    n|N|No|NO|no|nO)  
    echo "You will install MySQL 5.1.73"  
    isinstallmysql55="n"  
    ;;  
    md|MD|Md|mD)  
    echo "You will install MariaDB 5.5.37"  
    isinstallmysql55="md"  
    ;;  
    *)  
    echo "INPUT error,You will install MySQL 5.1.73"  
    isinstallmysql55="n"  
    esac  
  
    get_char()  
    {  
    SAVEDSTTY=`stty -g`  
    stty -echo  
    stty cbreak  
    dd if=/dev/tty bs=1 count=1 2> /dev/null  
    stty -raw  
    stty echo  
    stty $SAVEDSTTY  
    }  
    echo ""  
    echo "Press any key to start...or Press Ctrl+c to cancel"  
    char=`get_char`  
  
function InitInstall()  
{  
    cat /etc/issue  
    uname -a  
    MemTotal=`free -m | grep Mem | awk '{print  $2}'`    
    echo -e "\n Memory is: ${MemTotal} MB "  
    #Set timezone  
    rm -rf /etc/localtime  
    ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  
  
    yum install -y ntp  
    ntpdate -u pool.ntp.org  
    date  
  
    rpm -qa|grep httpd  
    rpm -e httpd  
    rpm -qa|grep mysql  
    rpm -e mysql  
    rpm -qa|grep php  
    rpm -e php  
  
    yum -y remove httpd*  
    yum -y remove php*  
    yum -y remove mysql-server mysql mysql-libs  
    yum -y remove php-mysql  
  
    yum -y install yum-fastestmirror  
    yum -y remove httpd  
    #yum -y update  
  
    #Disable SeLinux  
    if [ -s /etc/selinux/config ]; then  
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config  
    fi  
  
    cp /etc/yum.conf /etc/yum.conf.lnmp  
    sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf  
  
    for packages in patch make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils;  
    do yum -y install $packages; done  
  
    mv -f /etc/yum.conf.lnmp /etc/yum.conf  
}  
  
function CheckAndDownloadFiles()  
{  
echo "============================check files=================================="  
if [ "$isinstallphp53" = "n" ]; then  
    if [ -s php-5.2.17.tar.gz ]; then  
      echo "php-5.2.17.tar.gz [found]"  
    else  
      echo "Error: php-5.2.17.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/web/php/php-5.2.17.tar.gz  
    fi  
    if [ -s php-5.2.17-fpm-0.5.14.diff.gz ]; then  
      echo "php-5.2.17-fpm-0.5.14.diff.gz [found]"  
    else  
      echo "Error: php-5.2.17-fpm-0.5.14.diff.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/web/phpfpm/php-5.2.17-fpm-0.5.14.diff.gz  
    fi  
else  
    if [ -s php-5.3.28.tar.gz ]; then  
      echo "php-5.3.28.tar.gz [found]"  
    else  
      echo "Error: php-5.3.28.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/web/php/php-5.3.28.tar.gz  
    fi  
fi  
  
if [ -s memcache-3.0.6.tgz ]; then  
  echo "memcache-3.0.6.tgz [found]"  
  else  
  echo "Error: memcache-3.0.6.tgz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/memcache/memcache-3.0.6.tgz  
fi  
  
if [ -s pcre-8.12.tar.gz ]; then  
  echo "pcre-8.12.tar.gz [found]"  
  else  
  echo "Error: pcre-8.12.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/pcre/pcre-8.12.tar.gz  
fi  
  
if [ -s nginx-1.6.0.tar.gz ]; then  
  echo "nginx-1.6.0.tar.gz [found]"  
  else  
  echo "Error: nginx-1.6.0.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/nginx/nginx-1.6.0.tar.gz  
fi  
  
if [ "$isinstallmysql55" = "n" ]; then  
    if [ -s mysql-5.1.73.tar.gz ]; then  
      echo "mysql-5.1.73.tar.gz [found]"  
      else  
      echo "Error: mysql-5.1.73.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/datebase/mysql/mysql-5.1.73.tar.gz  
    fi  
elif [ "$isinstallmysql55" = "y" ]; then  
    if [ -s mysql-5.5.37.tar.gz ]; then  
      echo "mysql-5.5.37.tar.gz [found]"  
      else  
      echo "Error: mysql-5.5.37.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/datebase/mysql/mysql-5.5.37.tar.gz  
    fi  
else   
    if [ -s mariadb-5.5.37.tar.gz ]; then  
      echo "mariadb-5.5.37.tar.gz [found]"  
      else  
      echo "Error: mariadb-5.5.37.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/datebase/mariadb/mariadb-5.5.37.tar.gz  
    fi  
fi  
  
if [ -s libiconv-1.14.tar.gz ]; then  
  echo "libiconv-1.14.tar.gz [found]"  
  else  
  echo "Error: libiconv-1.14.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/libiconv/libiconv-1.14.tar.gz  
fi  
  
if [ -s libmcrypt-2.5.8.tar.gz ]; then  
  echo "libmcrypt-2.5.8.tar.gz [found]"  
  else  
  echo "Error: libmcrypt-2.5.8.tar.gz not found!!!download now......"  
  wget -c  http://soft.vpser.net/web/libmcrypt/libmcrypt-2.5.8.tar.gz  
fi  
  
if [ -s mhash-0.9.9.9.tar.gz ]; then  
  echo "mhash-0.9.9.9.tar.gz [found]"  
  else  
  echo "Error: mhash-0.9.9.9.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/mhash/mhash-0.9.9.9.tar.gz  
fi  
  
if [ -s mcrypt-2.6.8.tar.gz ]; then  
  echo "mcrypt-2.6.8.tar.gz [found]"  
  else  
  echo "Error: mcrypt-2.6.8.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/web/mcrypt/mcrypt-2.6.8.tar.gz  
fi  
  
if [ "$isinstallphp53" = "n" ]; then  
    if [ -s phpmyadmin-latest.tar.gz ]; then  
      echo "phpmyadmin-latest.tar.gz [found]"  
      else  
      echo "Error: phpmyadmin-latest.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/datebase/phpmyadmin/phpmyadmin-latest.tar.gz  
    fi  
else  
    if [ -s phpMyAdmin-lasest.tar.gz ]; then  
      echo "phpMyAdmin-lasest.tar.gz [found]"  
      else  
      echo "Error: phpMyAdmin-lasest.tar.gz not found!!!download now......"  
      wget -c http://soft.vpser.net/datebase/phpmyadmin/phpMyAdmin-lasest.tar.gz  
    fi  
fi  
  
if [ -s p.tar.gz ]; then  
  echo "p.tar.gz [found]"  
  else  
  echo "Error: p.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/prober/p.tar.gz  
fi  
  
if [ -s autoconf-2.13.tar.gz ]; then  
  echo "autoconf-2.13.tar.gz [found]"  
  else  
  echo "Error: autoconf-2.13.tar.gz not found!!!download now......"  
  wget -c http://soft.vpser.net/lib/autoconf/autoconf-2.13.tar.gz  
fi  
  
if [ -s mysql-openssl.patch ]; then  
  echo "mysql-openssl.patch [found]"  
  else  
  echo "Error: mysql-openssl.patch not found!!!download now......"  
  wget -c http://soft.vpser.net/lnmp/ext/mysql-openssl.patch  
fi  
echo "============================check files=================================="  
}  
  
function InstallDependsAndOpt()  
{  
cd $cur_dir  
  
tar zxf autoconf-2.13.tar.gz  
cd autoconf-2.13/  
./configure --prefix=/usr/local/autoconf-2.13  
make && make install  
cd ../  
  
tar zxf libiconv-1.14.tar.gz  
cd libiconv-1.14/  
./configure  
make && make install  
cd ../  
  
cd $cur_dir  
tar zxf 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  
cd ../../  
  
cd $cur_dir  
tar zxf mhash-0.9.9.9.tar.gz  
cd mhash-0.9.9.9/  
./configure  
make && make install  
cd ../  
  
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  
  
cd $cur_dir  
tar zxf mcrypt-2.6.8.tar.gz  
cd mcrypt-2.6.8/  
./configure  
make && make install  
cd ../  
  
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then  
    ln -s /usr/lib64/libpng.* /usr/lib/  
    ln -s /usr/lib64/libjpeg.* /usr/lib/  
fi  
  
ulimit -v unlimited  
  
if [ ! `grep -l "/lib"    '/etc/ld.so.conf'` ]; then  
    echo "/lib" >> /etc/ld.so.conf  
fi  
  
if [ ! `grep -l '/usr/lib'    '/etc/ld.so.conf'` ]; then  
    echo "/usr/lib" >> /etc/ld.so.conf  
fi  
  
if [ -d "/usr/lib64" ] && [ ! `grep -l '/usr/lib64'    '/etc/ld.so.conf'` ]; then  
    echo "/usr/lib64" >> /etc/ld.so.conf  
fi  
  
if [ ! `grep -l '/usr/local/lib'    '/etc/ld.so.conf'` ]; then  
    echo "/usr/local/lib" >> /etc/ld.so.conf  
fi  
  
ldconfig  
  
cat >>/etc/security/limits.conf<> /etc/sysctl.conf  
}  
  
function InstallMySQL51()  
{  
echo "============================Install MySQL 5.1.73=================================="  
cd $cur_dir  
rm -f /etc/my.cnf  
tar zxf mysql-5.1.73.tar.gz  
cd mysql-5.1.73/  
if [ $installinnodb = "y" ]; then  
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase  
else  
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile  
fi  
make && make install  
cd ../  
  
groupadd mysql  
useradd -s /sbin/nologin -M -g mysql mysql  
  
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf  
sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf  
if [ $installinnodb = "y" ]; then  
sed -i 's:#innodb:innodb:g' /etc/my.cnf  
fi  
/usr/local/mysql/bin/mysql_install_db --user=mysql  
chown -R mysql /usr/local/mysql/var  
chgrp -R mysql /usr/local/mysql/.  
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql  
chmod 755 /etc/init.d/mysql  
  
cat > /etc/ld.so.conf.d/mysql.conf< /tmp/mysql_sec_script< /etc/ld.so.conf.d/mysql.conf< /tmp/mysql_sec_script< /etc/ld.so.conf.d/mariadb.conf< /tmp/mariadb_sec_script<>/usr/local/php/etc/php.ini<>/usr/local/php/etc/php.ini</usr/local/php/etc/php-fpm.conf</home/wwwroot/default/phpinfo.php<  
eof  
  
echo "Copy PHP Prober..."  
cd $cur_dir  
tar zxvf p.tar.gz  
cp p.php /home/wwwroot/default/p.php  
  
cp conf/index.html /home/wwwroot/default/index.html  
echo "============================Install PHPMyAdmin================================="  
if [ "$isinstallphp53" = "n" ]; then  
    tar zxf phpmyadmin-latest.tar.gz  
    mv phpMyAdmin-3.4.8-all-languages /home/wwwroot/default/phpmyadmin  
else  
    tar zxf phpMyAdmin-lasest.tar.gz  
    mv phpMyAdmin-*-all-languages /home/wwwroot/default/phpmyadmin  
fi  
cp conf/config.inc.php /home/wwwroot/default/phpmyadmin/config.inc.php  
sed -i 's/LNMPORG/LNMP.org'$RANDOM'VPSer.net/g' /home/wwwroot/default/phpmyadmin/config.inc.php  
mkdir /home/wwwroot/default/phpmyadmin/upload/  
mkdir /home/wwwroot/default/phpmyadmin/save/  
chmod 755 -R /home/wwwroot/default/phpmyadmin/  
chown www:www -R /home/wwwroot/default/phpmyadmin/  
echo "============================phpMyAdmin install completed================================="  
}  
  
function AddAndStartup()  
{  
echo "============================add nginx and php-fpm on startup============================"  
echo "Download new nginx init.d file......"  
wget -c http://soft.vpser.net/lnmp/ext/init.d.nginx  
cp init.d.nginx /etc/init.d/nginx  
chmod +x /etc/init.d/nginx  
  
chkconfig --level 345 php-fpm on  
chkconfig --level 345 nginx on  
if [ "$isinstallmysql55" = "md" ]; then  
    chkconfig --level 345 mariadb on  
else  
    chkconfig --level 345 mysql on  
fi  
  
if [ "$isinstallmysql55" = "md" ]; then  
    sed -i 's:/etc/init.d/mysql:/etc/init.d/mariadb:g' /root/lnmp  
fi  
echo "===========================add nginx and php-fpm on startup completed===================="  
echo "Starting LNMP..."  
if [ "$isinstallmysql55" = "md" ]; then  
    /etc/init.d/mariadb start  
else  
    /etc/init.d/mysql start  
fi  
/etc/init.d/php-fpm start  
/etc/init.d/nginx start  
  
#add iptables firewall rules  
if [ -s /sbin/iptables ]; then  
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  
/sbin/iptables -I INPUT -p tcp --dport 3306 -j DROP  
/sbin/iptables-save  
fi  
}  
  
function CheckInstall()  
{  
echo "===================================== Check install ==================================="  
clear  
isnginx=""  
ismysql=""  
isphp=""  
echo "Checking..."  
if [ -s /usr/local/nginx/conf/nginx.conf ] && [ -s /usr/local/nginx/sbin/nginx ]; then  
  echo "Nginx: OK"  
  isnginx="ok"  
  else  
  echo "Error: /usr/local/nginx not found!!!Nginx install failed."  
fi  
  
if [ "$isinstallmysql55" = "md" ]; then  
    if [ -s /usr/local/mariadb/bin/mysql ] && [ -s /usr/local/mariadb/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then  
      echo "MariaDB: OK"  
      ismysql="ok"  
      else  
      echo "Error: /usr/local/mariadb not found!!!MySQL install failed."  
    fi  
else  
    if [ -s /usr/local/mysql/bin/mysql ] && [ -s /usr/local/mysql/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then  
      echo "MySQL: OK"  
      ismysql="ok"  
      else  
      echo "Error: /usr/local/mysql not found!!!MySQL install failed."  
    fi  
fi  
  
if [ -s /usr/local/php/sbin/php-fpm ] && [ -s /usr/local/php/etc/php.ini ] && [ -s /usr/local/php/bin/php ]; then  
  echo "PHP: OK"  
  echo "PHP-FPM: OK"  
  isphp="ok"  
  else  
  echo "Error: /usr/local/php not found!!!PHP install failed."  
fi  
if [ "$isnginx" = "ok" ] && [ "$ismysql" = "ok" ] && [ "$isphp" = "ok" ]; then  
echo "Install lnmp 1.1 completed! enjoy it."  
echo "========================================================================="  
echo "LNMP V1.1 for CentOS/RadHat Linux Server, Written by Licess "  
echo "========================================================================="  
echo ""  
echo "For more information please visit http://www.lnmp.org/"  
echo ""  
echo "lnmp status manage: /root/lnmp {start|stop|reload|restart|kill|status}"  
echo "default mysql root password:$mysqlrootpwd"  
echo "phpinfo : http://yourIP/phpinfo.php"  
echo "phpMyAdmin : http://yourIP/phpmyadmin/"  
echo "Prober : http://yourIP/p.php"  
echo "Add VirtualHost : /root/vhost.sh"  
echo ""  
echo "The path of some dirs:"  
echo "mysql dir:   /usr/local/mysql"  
echo "php dir:     /usr/local/php"  
echo "nginx dir:   /usr/local/nginx"  
echo "web dir :     /home/wwwroot/default"  
echo ""  
echo "========================================================================="  
/root/lnmp status  
netstat -ntl  
else  
echo "Sorry,Failed to install LNMP!"  
echo "Please visit http://bbs.vpser.net/forum-25-1.html feedback errors and logs."  
echo "You can download /root/lnmp-install.log from your server,and upload lnmp-install.log to LNMP Forum."  
fi  
}  
  
InitInstall 2>&1 | tee /root/lnmp-install.log  
CheckAndDownloadFiles 2>&1 | tee -a /root/lnmp-install.log  
InstallDependsAndOpt 2>&1 | tee -a /root/lnmp-install.log  
if [ "$isinstallmysql55" = "n" ]; then  
    InstallMySQL51 2>&1 | tee -a /root/lnmp-install.log  
elif [ "$isinstallmysql55" = "y" ]; then  
    InstallMySQL55 2>&1 | tee -a /root/lnmp-install.log  
else  
    InstallMariaDB 2>&1 | tee -a /root/lnmp-install.log  
fi  
if [ "$isinstallphp53" = "n" ]; then  
    InstallPHP52 2>&1 | tee -a /root/lnmp-install.log  
else  
    InstallPHP53 2>&1 | tee -a /root/lnmp-install.log  
fi  
InstallNginx 2>&1 | tee -a /root/lnmp-install.log  
CreatPHPTools 2>&1 | tee -a /root/lnmp-install.log  
AddAndStartup 2>&1 | tee -a /root/lnmp-install.log  
CheckInstall 2>&1 | tee -a /root/lnmp-install.log  
» 转载请注明来源:若我若鱼 » 解读lanmp安装文件centos.sh

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen − 6 =