shell脚本实战
----一键部署LNMP架构
LNMP使用shell实战部署,直接上主题,首先需要准备的包文件,我这里命名为zhunbei的文件。
zhunbei文件内容:
gcc gcc-c++ automake autoconf libtool make openssl openssl-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel mysql-server
以上为zhunbei文件中的需要安装的安装包,为下面的LNMP的shell脚本做铺垫。
LNMPshell脚本编写:
#!/bin/bash
#定义变量
AA=/soft
BB=$(cat /zhunbei.txt)
#检测目录(没有则创建)
if [ ! -d /soft ]
then
mkdir /soft
fi
#下载软件包
wget http://ftp.exim.llorien.org/pcre/pcre-8.36.tar.gz -P $AA
wget http://zlib.net/zlib-1.2.8.tar.gz -P $AA
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz -P $AA
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz -P $AA
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz -P $AA
wget http://museum.php.net/php5/php-5.6.1.tar.gz -P $AA
for a in $BB/*
do
yum -y install $BB
done
cd $AA
for i in $AA/*.tar.gz
do
tar -xzf $i -C $AA
done
#安装pcre
cd $AA/pcre-8.36/
./configure && make && make install
#安装zlib
cd $AA/zlib-1.2.8/
./configure && make && make install
#安装nginx
cd $AA/tengine-2.1.2/
./configure --sbin-path=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-pcre=/soft/pcre-8.36 --with-zlib=/soft/zlib-1.2.8 --with-openssl=/soft/openssl-1.0.1c
make && make install
#启动nginx服务
/usr/local/nginx/nginx
#安装libmcrypt
cd $AA/libmcrypt-2.5.7/
./configure --prefix=/usr/local && make && make install
#安装php软件包
cd $AA/php-5.6.1/
./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --enable-opcache=no
make && make install
#配置PHP-fpm配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#重启nginx服务
/usr/local/nginx/nginx -s reload
启动php-fpm服务
/usr/local/php/sbin/php-fpm
启动mysql
service mysqld start
给shell 执行权限就可以安装部署了!