標籤:shell lnmp 一鍵安裝
前段時間維護伺服器,需要安裝LNMP環境,所以就整理了一下,做為指令碼,記錄下來。
#!/bin/sh#Copyright(c) 2010-2015 redapple ([email protected]) #install LNMP #Version 0.1.1#Date 20140813#------------增加yum源------------------------rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpmrpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm#------------安裝gcc------------------------yum install gcc-c++ gcc ncurses-devel wget openssl openssl-devel zlib-devel -y#--------------時間同步--------------------ntpdate tiger.sina.com.cnhwclock -w#----------------下載安裝pcre------------------[ ! -f pcre-8.35.tar.gz ] && wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gztar xf pcre-8.35.tar.gz cd pcre-8.35./configure --prefix=/usr/local/pcremake && make install#----------------下載安裝nginx------------------cd ..groupadd -r nginxuseradd -r -g nginx -s /bin/false -M nginx[ ! -f nginx-1.6.1.tar.gz ] && wget http://nginx.org/download/nginx-1.6.1.tar.gztar -xf nginx-1.6.1.tar.gzcd nginx-1.6.1./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-pcre --with-http_ssl_module --with-http_flv_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgimake && make install#----------------設定nginx啟動----------------cd ..cp nginx /etc/rc.d/init.dchmod +x /etc/rc.d/init.d/nginxchkconfig nginx on#----------------下載安裝mysql------------------yum install cmake ncurses-devel -ygroupadd mysqluseradd -g mysql mysql -s /bin/falsemkdir -p /data/mysqlchown -R mysql:mysql /data/mysql[ ! -f mysql-5.5.38.tar.gz ] && wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.38.tar.gztar xf mysql-5.5.38.tar.gz cd mysql-5.5.38cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0make && make install[ -f /etc/my.cnf ] && rm -rf /etc/my.cnfcp support-files/my-medium.cnf /etc/my.cnfsed -i ‘s#max_allowed_packet = 1M#max_allowed_packet = 16M#‘ /etc/my.cnf./scripts/mysql_install_db --user=mysql --datadir=/data/mysql[ -f /etc/init.d/mysqld ] && rm -rf /etc/init.d/mysqldcp ./support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldsed -i ‘46s#basedir=#basedir=/usr/local/mysql#‘ /etc/init.d/mysqldsed -i ‘47s#datadir=#datadir=/data/mysql#‘ /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld onecho "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile ln -s /usr/local/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlservice mysqld startps -ef |grep mysqld#----------------下載並安裝freetype------------------cd ..[ ! -f freetype-2.5.3.tar.gz ] && wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gztar -zxvf freetype-2.5.3.tar.gzcd freetype-2.5.3./configure --prefix=/usr/local/freetypemake && make install#----------------下載並安裝libmcrypt------------------cd ..[ ! -f libmcrypt-2.5.7.tar.gz ] && wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gztar -zxvf libmcrypt-2.5.7.tar.gzcd libmcrypt-2.5.7./configure make && make install#----------------下載並安裝jpegsrc.v9------------------cd ..[ ! -f jpegsrc.v9a.tar.gz ] && wget http://www.ijg.org/files/jpegsrc.v9a.tar.gztar -xf jpegsrc.v9a.tar.gzcd jpeg-9a./configure --prefix=/usr/local/jpegmake && make install#----------------下載並安裝php------------------cd ..yum install -y libcurl bzip2-devel bzip2 libxml2-devel curl curl-devel gd libpng zlib #---想讓編譯的php支援mcrypt、mhash擴充和libevent---------#yum install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt[ ! -f php-5.5.15.tar.gz ] && wget http://cn2.php.net/distributions/php-5.5.15.tar.gztar xf php-5.5.15.tar.gzcd php-5.5.15./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-xml --enable-mbstring --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-pcntl --enable-zip --enable-gd-native-ttf --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-gettext --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-xmlrpc --without-pear make && make installcp ./php.ini-production /usr/local/php/etc/php.inised -i ‘s#;date.timezone =#date.timezone = PRC#‘ /etc/php.inised -i ‘s#expose_php = On#expose_php = OFF#‘ /etc/php.ini#----------------配置php-fpm------------------cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confsed -i ‘s#user = nobody#user = nginx#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#group = nobody#group = nginx#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#pm.max_children = 5#pm.max_children = 150#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#pm.start_servers = 2#pm.start_servers = 8#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#pm.min_spare_servers = 1#pm.min_spare_servers = 5#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#pm.max_spare_servers = 3#pm.max_spare_servers = 10#‘ /usr/local/php/etc/php-fpm.confsed -i ‘s#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#‘ /usr/local/php/etc/php-fpm.confcp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpmchmod +x /etc/rc.d/init.d/php-fpmchkconfig --add php-fpmchkconfig php-fpm on#----------------配置nginx支援php------------------cd ..cat nginx.conf >/etc/nginx/nginx.confmkdir -p /etc/nginx/vhostscp default.conf /etc/nginx/vhosts#----------------檢查php和php-fpm------------------service php-fpm startservice nginx startps -ef | grep nginxps aux | grep php-fpm#----------------建立index.php的測試頁面------------------cat > /usr/html/index.php << EOF<?phpphpinfo();?>EOFecho "=============LNMP install OK !!!!============"
本文出自 “紅蘋果” 部落格,請務必保留此出處http://262242.blog.51cto.com/252242/1572004
LNMP一鍵安裝shell指令碼