linux shell脚本之lnmp的搭建

前端之家收集整理的这篇文章主要介绍了linux shell脚本之lnmp的搭建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/bash#this script is source packages installed lnmp for redhat or centos 6.xmalyum -y installwget#"============download the source package=============="wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gzwget http://Nginx.org/download/Nginx-1.3.8.tar.gzwget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gzwget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gzwget http://cdn.MysqL.com/Downloads/MysqL-5.5/MysqL-5.5.30.tar.gzwget http://ncu.dl.sourceforge.net/project/qdbm/qdbm/1.8.77/qdbm-1.8.77.tar.gzwget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gzwget http://fossies.org/linux/www/gd-2.0.35.tar.gzwget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/downloadwget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/downloadwget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/downloadwget http://cronolog.org/download/cronolog-1.6.2.tar.gzwget http://cn2.PHP.net/distributions/PHP-5.4.14.tar.gzwget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.11/pcre-8.11.tar.gz#"=============download all======================"printf"========install the compile tool=============\n"yum -y installgcc gcc-c++ openssl-devel ncurses ncurses-devel zlib-devel bzip2bzip2-devel curl-devel libjpeg-devel libxml2* libpng* freetype* libxslt*#yum -y groupinstall "Development" "Development Tools" #or use this command instead of the above#tar the source package 解压源代码包到指定的目录tarzxvf pcre-8.11.tar.gz -C /usr/local/src/tarzxvf libevent-2.0.21-stable.tar.gz -C /usr/local/src/tarzxvf Nginx-1.3.8.tar.gz -C /usr/local/src/tarzxvf cmake-2.8.6.tar.gz -C /usr/local/src/tarzxvf bison-2.5.1.tar.gz -C /usr/local/src/tarzxvf MysqL-5.5.30.tar.gz -C /usr/local/src/tarzxvf libiconv-1.14.tar.gz -C /usr/local/src/tarzxvf qdbm-1.8.77.tar.gz -C /usr/local/src/tarzxvf gd-2.0.35.tar.gz -C /usr/local/src/tarzxvf mcrypt-2.6.8.tar.gz -C /usr/local/src/@H_962_403@tarzxvf cronolog-1.6.2.tar.gz -C /usr/local/src/tarzxvf PHP-5.4.14.tar.gz -C /usr/local/src/tarjxvf libmcrypt-2.5.8.tar.bz2 -C /usr/local/src/tarjxvf mhash-0.9.9.9.tar.bz2 -C /usr/local/src/#Compile the unpack the source code package 编译解压的源代码echo"===========Nginx Relevant source package is installed========== "echo"##### pcre install#####"cd/usr/local/src/pcre-8.11/./configure--prefix=/usr/local/pcre&& make&& makeinstallprintf"====pcre is ok====\n"echo"#####libevent install######"cd/usr/local/src/libevent-2.0.21-stable/./configure--prefix=/usr/local/libevent&& make&& makeinstallprintf"====libevent is ok====\n"echo"####Nginx install######"groupadd -r Nginxuseradd-r -g Nginx -s /bin/false-M Nginxcd/usr/local/src/Nginx-1.3.8/###before you configure,you can see "./configure ?help" see carefully "?with-pcre=DIR set path to PCRE library sources"在编译之前可以先help看看./configure--prefix=/usr/local/Nginx--with-pcre=/usr/local/src/pcre-8.11/ --sbin-path=/usr/local/Nginx/sbin/Nginx--pid-path=/usr/local/Nginx/logs/Nginx.pid \--with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --user=Nginx --group=Nginx \--http-proxy-temp-path=/var/tmp/Nginx/proxy/--http-fastcgi-temp-path=/var/tmp/Nginx/fcgi/--lock-path=/var/lock/Nginx.lock --http-client-body-temp-path=/var/tmp/Nginx/client/\&& make&& makeinstallprintf"======Nginx is ok!!======\n"mkdir-pv /var/tmp/Nginx/#write startup Nginx files by yourself 自己手动写Nginx的启动脚本cat>> /etc/init.d/Nginx<< EOF#!/bin/bash# Nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: ? 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features,but it’s not for everyone.# processname: Nginx# pidfile: /var/run/Nginx.pid# config: /usr/local/Nginx/conf/Nginx.confNginxd=/usr/local/Nginx/sbin/NginxNginx_config=/usr/local/Nginx/conf/Nginx.confNginx_pid=/usr/local/Nginx/logs/Nginx.pidRETVAL=0prog="Nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no"] && exit0[ -x $Nginxd ] || exit0# Start Nginx daemons functions.start() {if[ -e $Nginx_pid ];thenecho"Nginx already running…."exit1fiecho-n $"Starting $prog: "daemon $Nginxd -c ${Nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch/var/lock/subsys/Nginxreturn$RETVAL}# Stop Nginx daemons functions.stop() {echo-n $"Stopping $prog: "killproc $NginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm-f /var/lock/subsys/Nginx/usr/local/Nginx/logs/Nginx.pid}reload() {echo-n $"Reloading $prog: "#kill -HUP `cat ${Nginx_pid}`killproc $Nginxd -HUPRETVAL=$?echo}# See how we were called.case"$1"instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo"Usage: $prog {start|stop|restart|reload|status|help}"exit1esacexit$RETVALEOFchmod+x /etc/init.d/Nginxchkconfig --add Nginxchkconfig --level 35 Nginx onservice Nginx restartecho"===========MysqL Relevant source package is installed========== "useradd-M -s /sbin/nologinMysqLecho"##### cmake install#####"cd/usr/local/src/cmake-2.8.6./bootstrap&& gmake && gmake installprintf"====cmake is ok====\n"echo"##### bison install#####"cd/usr/local/src/bison-2.5.1/./configure&& make&& makeinstallprintf"====bison is ok====\n"echo"##### MysqL install#####"cd/usr/local/src/MysqL-5.5.30/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL-DMysqL_UNIX_ADDR=/tmp/MysqL.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \-DMysqL_DATADIR=/var/MysqL/data&& make&& makeinstallprintf"====MysqL is ok====\n"#set up the MysqL configuration file and initialize the database 建立MysqL配置文件和初始化数据库#cp usr/local/MysqL/support-files/my-huge.cnf /etc/my.cnf ##if you memory is greater than 2G,please choose this 内存大于2G就copy这个配置文件cp/usr/local/MysqL/support-files/my-medium.cnf /etc/my.cnfcp/usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd/usr/local/MysqL/scripts/MysqL_install_db--user=MysqL --basedir=/usr/local/MysqL/--datadir=/var/MysqL/data/usr/local/MysqL/bin/MysqLd_safe--user=MysqLchmod-R 755 /usr/local/MysqLchown-R MysqL:MysqL /usr/local/MysqLchown-R MysqL:MysqL /var/MysqL/datachkconfig --add MysqLdchkconfig --level 35 MysqLd onservice MysqLd restartread-p "please set up password for MysqL:"pwd/usr/local/MysqL/bin/MysqLadmin-u root password $pwdexportPATH=$PATH:/usr/local/MysqL/bin/echo"PATH=$PATH:/usr/local/MysqL/bin">> /etc/profileln-s /usr/local/MysqL/bin/* /usr/local/bin/ln-s /usr/local/MysqL/lib/* /usr/libln-s /usr/local/MysqL/include/MysqL/* /usr/include/echo"===========PHP Relevant source package is installed========== "echo"####libiconv install####"cd/usr/local/src/libiconv-1.14/./configure--prefix=/usr/local/libiconv&& make&& makeinstallprintf"====libiconv is ok====\n"echo"####qdbm install#####"cd/usr/local/src/qdbm-1.8.77/./configure--prefix=/usr/local/qdbm--enable-devel --enable-zlib --enable-iconv && make&&makeinstallprintf"====qdbm is ok====\n"echo"####gd install####"cd/usr/local/src/gd-2.0.35/./configure--prefix=/usr/local/gd2--with-jpeg --with-png --with-zlib --with-freetype &&make&& makeinstallprintf"====gd is ok====\n"sed-i '/\*gd_free/a\void (*data);'/usr/local/gd2/include/gd_io.hecho"/usr/local/gd2/lib">> /etc/ld.so.confldconfigecho"####libmcrypt and libltdl install####"cd/usr/local/src/libmcrypt-2.5.8/./configure--prefix=/usr/local/libmcrypt&& make&& makeinstall@H_494_1404@ldconfigcd/usr/local/src/libmcrypt-2.5.8/libltdl./configure--prefix=/usr/local/libltdl--enable-ltdl-install&& make&& makeinstallln-sf /usr/local/lib/libmcrypt.* /usr/libln-sf /usr/local/bin/libmcrypt-config/usr/binprintf"====libmcrypt and libltdl is ok====\n"echo"####mhash install####"cd/usr/local/src/mhash-0.9.9.9/./configure--prefix=/usr/local/mhash&& make&& makeinstallln-sf /usr/local/lib/libmhash.* /usr/lib/printf"====mhash is ok====\n"echo"####mcrypt install####"cd/usr/local/src/mcrypt-2.6.8//sbin/ldconfig./configure--prefix=/usr/local/mcrypt&& make&& makeinstallprintf"====mcrypt is ok====\n"echo"####cronolog install####"cd/usr/local/src/cronolog-1.6.2./configure--prefix=/usr/local/cronolog&& make&& makeinstallprintf"====cronolog is ok====\n"echo"####PHP install#####"ln-sf /usr/local/MysqL/lib/libMysqLclient.so.18 /usr/libln-sf /usr/local/qdbm/lib/libqdbm.so* /usr/libcd/usr/local/src/PHP-5.4.14./configure--prefix=/usr/local/PHP5--with-config-file-path=/usr/local/PHP5/etc--with-MysqL=/usr/local/MysqL\--with-iconv=/usr/local/libiconv--with-gd=/usr/local/gd2--with-iconv-dir=/usr/local--with-pdo-MysqL=/usr/local/MysqL\--with-libxml-dir=/usr--with-qdbm=/usr/local/qdbm--with-mime-magic=/usr/share/file/magic--with-jpeg-dir--with-png-dir--with-freetype-dir\--with-bz2 --with-zlib --without-pear --with-xmlrpc --with-zlib-dir--with-curl --with-curlwrappers --with-mcrypt=/usr/local/libmcrypt--with-mhash \--with-ttf --with-xsl --with-gettext --with-pear --with-openssl --enable-discard-path --enable-gd-native-ttf \--enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-xml \--enable-soap --enable-calendar --enable-wddx --enable-dba --enable-gd-native-ttf--enable-calendar --enable-safe-mode \--enable-ftp--enable-fpm --enable-zip --enable-mbstring --enable-bcmath --enable-sockets --enable-exif --enable-magic-quotes --disable-rpath --disable-debug \&& make&& makeinstallprintf"====PHP is ok====\n"ln-s /usr/local/PHP5/bin/* /usr/local/bin/ln-s /usr/local/PHP5/sbin/* /usr/local/sbin/cp/usr/local/src/PHP-5.4.14/PHP.ini-production /usr/local/PHP5/PHP.ini#Configure Nginx support PHP 配置Nginx支持PHP环境cp/usr/local/PHP5/etc/PHP-fpm.conf.default /usr/local/PHP5/etc/PHP-fpm.confsed-i '/run/s/;//g'/usr/local/PHP5/etc/PHP-fpm.confsed-i '/^ /d'/usr/local/PHP5/etc/PHP-fpm.confsed-i 's/nobody/Nginx/g'/usr/local/PHP5/etc/PHP-fpm.confsed-i '/start/s/2/20/'/usr/local/PHP5/etc/PHP-fpm.confsed-i '/min/s/1/5/'/usr/local/PHP5/etc/PHP-fpm.confsed-i '/max_spare/s/3/25/'/usr/local/PHP5/etc/PHP-fpm.confsed-i '/max_children/s/5/35/'/usr/local/PHP5/etc/PHP-fpm.conf/usr/local/sbin/PHP-fpm#启动PHP-fpm进程#test Nginx MysqL PHP work tegethersed-i '/\<user\>/a user Nginx;'/usr/local/Nginx/conf/Nginx.conf #把user改为Nginx用户sed-i '/\<index\>/s/index.html index.htm/index.html index.htm index.PHP/g'/usr/local/Nginx/conf/Nginx.conf #添加支持index.PHP#这下面的六句自己手动的添加Nginx配置文件里面去/usr/local/Nginx/conf/Nginx.conf# location ~ \.PHP$ {

猜你在找的Shell相关文章