一键安装LNMP环境,经过Centos 6.0 64位系统测试

前端之家收集整理的这篇文章主要介绍了一键安装LNMP环境,经过Centos 6.0 64位系统测试前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash 
#set -x 
#date: 2013-01-06 
#Description: 一键安装LNMP环境 
#Version: 0.1 
#Author: Wolf 
#定义命令搜索路径
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 
export PATH 
 
src_dir=/usr/src 
Nginx_dir=/usr/local/Nginx 
MysqL_dir=/usr/local/MysqL 
PHP_dir=/usr/local/PHP 
libmcrypt_dir=/usr/local/libmcypt 
#关闭SELiunx
echo "Disabled SELinux" 
if [ -s /etc/selinux/config ] 
then 
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 
fi 
/usr/sbin/setenforce 0 
# Check if user is root 
if [ "$UID" -ne 0 ] 
then 
    printf "Error: You must be root to run this script!\n" 
    exit 1 
fi 
 
    useradd -s /sbin/nologin MysqL 
 
#检查需要的软件包是否存在,如果没有就下载。
download_src(){ 
cd $src_dir 
if [ -s libiconv-1.13.1.tar.gz ]
then
	echo "libiconv-1.13.1.tar.gz found"
else
	echo "libiconv-1.13.1.tar.gz not found. download new...."
	wget http://mozbuildtools.googlecode.com/files/libiconv-1.13.1.tar.gz
fi
if [ -s mhash-0.9.9.9.tar.gz ]
then
	echo "mhash-0.9.9.9.tar.gz found"
else
	echo "mhash-0.9.9.9.tar.gz not found. download new....."
	wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
fi
if [ -s MysqL-5.5.25a.tar.gz ] 
then 
    echo "MysqL-5.5.25a.tar.gz found" 
else 
    echo "MysqL-5.5.25a.tar.gz not found. download new....."     
    wget http://MysqL.ntu.edu.tw/Downloads/MysqL-5.5/MysqL-5.5.25a.tar.gz  
fi 
if [ -s PHP-5.3.13.tar.gz ] 
then 
    echo "PHP-5.3.13.tar.gz found" 
else 
    echo "PHP-5.3.13.tar.gz not found. download new....." 
    wget http://cn2.PHP.net/distributions/PHP-5.3.13.tar.gz  
fi 
if [ -s google-perftools-1.6.tar.gz ]
then
	echo "google-perftools-1.6.tar.gz found"
else
	echo "google-perftools-1.6.tar.gz not found. download new....."
	wget http://gperftools.googlecode.com/files/google-perftools-1.6.tar.gz
fi
if [ -s cmake-2.8.4.tar.gz ] 
then 
    echo "cmake-2.8.4.tar.gz found......" 
else 
    echo "cmake-2.8.4.tar.gz not found. download new....." 
    wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz 
fi 
if [ -s Nginx-1.3.10.tar.gz ] 
then 
    echo "Nginx-1.3.10.tar.gz found." 
else 
    echo "Nginx-1.3.10.tar.gz not found. download new...." 
    wget http://www.Nginx.org/download/Nginx-1.3.10.tar.gz 
fi 
if [ -s libmcrypt-2.5.7.tar.gz ] 
then 
    echo "libmcrypt-2.5.7.tar.gz found" 
else 
    echo "libmcrypt-2.5.7.tar.gz not found. download new..." 
    wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/Production/libmcrypt-2.5.7.tar.gz 
fi 
if [ -s memcache-2.2.5.tgz ] 
then 
    echo "memcache-2.2.5.tgz found" 
else 
    echo "memcache-2.2.5.tgz not found. download new......" 
    wget http://vps.googlecode.com/files/memcache-2.2.5.tgz 
fi 
if [ -s eaccelerator-0.9.5.3.tar.bz2 ] 
then 
    echo "eaccelerator-0.9.5.3.tar.bz2 found" 
else 
    echo "eaccelerator-0.9.5.3.tar.bz2 not found. download new.." 
    wget http://autosetup1.googlecode.com/files/eaccelerator-0.9.5.3.tar.bz2 
fi 
if [ -s ImageMagick.tar.gz ] 
then 
    echo "ImageMagick.tar.gz found" 
else 
    echo "ImageMagick.tar.gz not found. download nrw." 
    wget http://www.imagemagick.org/download/ImageMagick.tar.gz 
fi 
if [ -s imagick-2.3.0.tgz ] 
then 
    echo "imagick-2.3.0.tgz found" 
else 
    echo  "imagick-2.3.0.tgz not found. download new" 
    wget http://lnmpp.googlecode.com/files/imagick-2.3.0.tgz 
fi 
} 
#初始化服务器
init_server(){ 
for src in dialog ntp vim-enhanced vixie-cron gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel net-snmp net-snmp-devel nss_ldap openldap-clients openldap-servers libtidy libtidy-devel wget libc-client libc-client-devel pcre pcre-devel 
do 
    yum -y install $src 
done 
ln -s /usr/lib64/libc-client.so* /usr/lib/ 
ln -s /usr/lib64/libldap* /usr/lib 
} 

 
#先检测MysqL是否已经安装,如果已经安装了就不再安装,如果没安装就安装MysqL
inst_MysqL(){ 
  
    tar zxvf cmake-2.8.4.tar.gz 
    cd $src_dir/cmake-2.8.4 
    ./configure && make && make install  
if ( -d $MysqL_dir ) 
then 
    echo "MysqL is installed" 
else 
    echo "MysqL not install. install run..." 
    cd $src_dir 
    tar zxvf MysqL-5.5.25a.tar.gz 
    cd MysqL-5.5.25a 
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL -DMysqL_DATADIR=/usr/local/MysqL/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMysqL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on 
    gmake && make install 
fi 
if ( -f /ect/my.cnf ) 
then 
    echo "MysqL config file my.cnf found. backup my.cnf to my.cnf.bak" 
    mv /etc/my.cnf /etc/my.cnf.bak 
    /bin/cp support-files/my-small.cnf /etc/my.cnf 
    /bin/cp support-files/MysqL.server /etc/rc.d/init.d/MysqLd 
    chmod 755 /etc/rc.d/init.d/MysqLd 
fi 
/usr/local/MysqL/scripts/MysqL_install_db --basedir=/usr/local/MysqL/ --datadir=/usr/local/MysqL/data/ --user=root --defaults-file=/etc/my.cnf 
} 
 
inst_libmcypt(){ 
if ( -d $libmcrypt_dir ) 
then 
        echo "libmcrypt is installed." 
else 
        cd $src_dir 
        tar zxvf libmcrypt-2.5.7.tar.gz 
        cd libmcrypt-2.5.7 
        ./configure --prefix=/usr/local/libmcypt && make && make install 
	/sbin/ldconfig
	cd libltdl/
	./configure --enable-ltdl-install
	make
	make install
fi 
cd $src_dir
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
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
} 
#先检测PHP是否已经编译安装,如果安装了就不再进行安装,如果没安装就安装PHP
inst_PHP(){ 
cd $src_dir
tar zxf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd $src_dir 
if ( -d $PHP_dir) 
then 
    echo "PHP is installed" 
else 
    echo "PHP not install. install run...." 
    cd $src_dir 
    tar zxvf PHP-5.3.13.tar.gz 
    cd PHP-5.3.13 
    ./configure --prefix=/usr/local/PHP --with-config-file-path=/usr/local/PHP/lib --with-MysqL=/usr/local/MysqL/bin/MysqL_config --with-enable-sysvsem --enable-fpm --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir=/usr --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --enable-gd-native-ttf --enable-gd-jis-conv --without-iconv --with-ldap --with-mcrypt=/usr/local/libmcypt --with-zlib-dir --with-snmp --enable-zip --with-curlwrappers --with-imap --with-kerberos --with-imap-ssl --with-freetype-dir --with-MysqL=/usr/local/MysqL 
    make && make install 
    cp PHP.ini-development /usr/local/PHP/lib/PHP.ini 
    cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf 
fi 
} 
#安装PHP扩展 
inst_PHP_ex(){ 
cd $src_dir 
tar zxf memcache-2.2.5.tgz 
cd memcache-2.2.5/ 
${PHP_dir}/bin/PHPize 
./configure --with-PHP-config=${PHP_dir}/bin/PHP-config 
make 
make install 
cd ../ 
 
tar jxf eaccelerator-0.9.5.3.tar.bz2 
cd eaccelerator-0.9.5.3 
${PHP_dir}/bin/PHPize 
./configure --enable-eaccelerator=shared --with-eaccelerator-shared-memory --with-PHP-config=${PHP_dir}/bin/PHP-config 
make 
make install 
cd $src_dir 
 
tar zxf ImageMagick.tar.gz 
cd ImageMagick-6.8.1-9/ 
./configure 
make 
make install 
cd ../ 
tar zxf imagick-2.3.0.tgz 
cd imagick-2.3.0/ 
${PHP_dir}/bin/PHPize 
./configure --with-PHP-config=${PHP_dir}/bin/PHP-config 
make 
make install 
cd .. 
echo "PHP extension installed successfully!" 
} 
#安装Nginx 
inst_Nginx(){ 
cd $src_dir
tar zxf google-perftools-1.6.tar.gz
cd google-perftools*
./configure
make
make install
cd $src_dir

if ( -d $Nginx_dir ) 
then 
    echo "Nginx is installed" 
else 
    cd $src_dir 
    tar zxvf Nginx-1.3.10.tar.gz 
    cd Nginx-1.3.10 
    ./configure --prefix=/usr/local/Nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_stub_status_module 
    make && make install     
fi 
} 
#生成一个PHP启动脚本,可以用service PHPd start | restart | stop | show 进行启动、重启、关闭、查看运行状态
PHPd(){
cat <<EOF >>PHPd
#!/bin/bash  
#Author: wolf
#Date: 2013-01-03
#  
#chkconfig: - 85 15  
#processname: PHP 
PHP=/usr/local/PHP/sbin/PHP-fpm  
conf=/usr/local/PHP/etc/PHP-fpm.conf  
case $1 in  
       start)  
              echo -n "Starting PHP"  
              $PHP  
              echo " done"  
       ;;  
      stop)  
              echo -n "Stopping PHP"  
              killall -9 PHP-fpm  
              echo " done"  
       ;;  
        restart)  
                $0 stop  
                $0 start  
       ;;  
       show)  
              ps -aux|grep PHP  
       ;;  
       *)  
              echo -n "Usage: $0 {start|restart|reload|stop|test|show}"  
       ;;  
esac
EOF
if [ -f PHPd ]
then
	/bin/cp PHPd /etc/rc.d/init.d/PHPd
	chmod +x /etc/rc.d/init.d/PHPd
fi
}
#生成Nginx启动脚本,可以用service Nginxd start | restart | stop | reload | test | show 进行重启、关闭、启动>、测试配置文件、查看状态和重新加载。
Nginxd(){
cat <<EOF >>Nginxd
#!/bin/bash  
#Author: wolf
#Date: 2013-01-03
#  
#chkconfig: - 85 15  
#description: Nginx is a World Wide Web server.  
#processname: Nginx  
Nginx=/usr/local/Nginx/sbin/Nginx  
conf=/usr/local/Nginx/conf/Nginx.conf   
case $1 in  
       start)  
              echo -n "Starting Nginx"  
              $Nginx -c $conf  
              echo " done"  
       ;;  
      stop)  
              echo -n "Stopping Nginx"  
              killall -9 Nginx  
              echo " done"  
       ;;  
       test)  
              $Nginx -t -c $conf  
       ;;  
        reload)  
              echo -n "Reloading Nginx"  
              ps auxww | grep Nginx | grep master | awk '{print $2}' | xargs kill -HUP  
              echo " done"  
       ;;  
        restart)  
                $0 stop  
                $0 start  
       ;;  
       show)  
              ps -aux|grep Nginx  
       ;;  
       *)  
              echo -n "Usage: $0 {start|restart|reload|stop|test|show}"  
       ;;  
esac
EOF
if [ -s Nginxd ]
then
	/bin/cp Nginxd /etc/rc.d/init.d/Nginxd
	chmod +x /etc/rc.d/init.d/Nginxd
fi
}
cat <<EOF
############################################
  1 install Nginx
  2 install PHP
  3 install MysqL
  4 install LNMP
############################################
############################################
请选择你要安装的服务(1 | 2 | 3 | 4)
EOF

echo "请输入一个数字: "
read num
case $num in  
   1) 
    echo "Nginx installing........... have a rest" 
    init_server 
    download_src 
    inst_Nginx 
    ;; 
   2) 
    echo "PHP installing....... have a rest" 
    download_src 
    init_server 
    inst_MysqL 
    inst_libmcypt 
    inst_PHP 
    inst_PHP_ex 
    ;; 
    3) 
    echo "MysqL installing...... have a rest" 
    init_server  
    download_src 
    inst_MysqL 
     ;; 
    4) 
    echo "LNMP installing......  have a rest" 
    download_src 
   init_server 
   inst_MysqL 
   inst_libmcypt 
   inst_PHP 
inst_PHP_ex
   inst_Nginx  
    ;; 
*)
echo "输入错误\n"         echo "选择你要安装的服务(1 | 2 | 3 | 4)"         
;;
esac
 
#检查安装是否成功
case $num in 
   4) 
    if [ -s /usr/local/Nginx ] && [ -s /usr/local/PHP ] && [ -s /usr/local/MysqL ] 
    then 
          echo "LNMP is install  completed" 
          echo "Nginx basedir: /usr/local/Nginx" 
          echo "PHP basedir: /usr/local/PHP" 
          echo "MysqL basedir: /usr/local/MysqL" 
          echo "MysqL datadir: /usr/local/MysqL/data" 
    else 
         echo "LNMP is install fail" 
    fi 
   ;; 
   3) 
    if [ -s /usr/local/MysqL ] 
    then 
        echo "Nginx is install completed" 
        echo "MysqL basedir: /usr/local/MysqL" 
        echo "MysqL datadir: /usr/local/MysqL/data" 
	PHPd
	Nginxd
    else 
        echo "Nginx is install fail" 
    fi 
    ;; 
   2) 
    if  [ -s /usr/local/PHP ] 
    then 
        echo "PHP is install completed" 
        echo "PHP basedir: /usr/local/PHP" 
	PHPd
    else 
        echo "PHP is install fail" 
    fi 
    ;; 
    1) 
    if [ -s /usr/local/Nginx ] 
    then 
        echo "Nginx is install completed" 
        echo "Nginx basedir: /usr/local/Nginx " 
	Nginxd
    else 
        echo "Nginx is install fail" 
    fi 
    ;; 
esac

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章