提示:此脚本是在一个干净的环境下,是完全可以安装成功的

/*------------------------------------------------------------------------------------------------------------------------

#!/bin/bash
#install lnmp
set -x #显示执行过程
set -e #遇到错误就退出,不继续执行
#安装开发库相关的依赖包
yum install make apr* autoconf automake curl-devel wget lrzsz gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel t1lib-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype freetype-devel libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel ncurses-devel bzip2 vim libcurl-devel libvpx-devel cmake -y --skip-broken


#下载lnmp的相关软件
echo -e "\033[32m*****************1.downloading******************** \033[0m "
mkdir /mnt/soft/ && cd /mnt/soft/
wget http://nginx.org/download/nginx-1.10.1.tar.gz
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
wget http://downloads.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
wget https://pypi.python.org/packages/e7/a8/7556133689add8d1a54c0b14aeff0acb03c64707ce100ecd53934da1aa13/pip-8.1.2.tar.gz#md5=87083c0b9867963b29f7aba3613e8f4a

wget https://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz
wget http://cn2.php.net/get/php-5.6.25.tar.gz/from/this/mirror -O php.tar.gz

#解压
echo -e "\033[32m*****************2.tar file******************** \033[0m "
cd /mnt/soft/
tar -zxvf pcre-8.38.tar.gz -C /usr/local/src
tar -zxvf openssl-1.0.1t.tar.gz -C /usr/local/src
tar -zxvf zlib-1.2.8.tar.gz -C /usr/local/src
tar -zxvf nginx-1.10.1.tar.gz -C /usr/local/src
tar -zxvf php.tar.gz -C /usr/local/src
tar -zxvf libmcrypt-2.5.8.tar.gz -C /usr/local/src
tar -zxvf setuptools-26.0.0.tar.gz -C /usr/local/src/
tar -zxvf pip-8.1.2.tar.gz -C /usr/local/src/
tar -zxvf mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

#安装nginx
echo -e "\033[32m*****************3.install nginx******************** \033[0m "
groupadd www
useradd www -g www
cd /usr/local/src
cd nginx* && ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_sub_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1t/ --with-zlib=/usr/local/src/zlib-1.2.8/ --with-pcre=/usr/local/src/pcre-8.38
make -j4 && make -j4 install
echo "nginx is installed" > /tmp/install.log

#安装supervisord进程管理服务
echo -e "\033[32m*****************4.install supervisord******************** \033[0m "
cd /usr/local/src/setuptools*
python setup.py install
cd /usr/local/src/pip*
python setup.py install
pip2.7 install supervisor
echo_supervisord_conf > /etc/supervisord.conf
echo "supervisord is installed" >> /tmp/install.log


#安装mysql
echo -e "\033[32m*****************5.install mysql******************** \033[0m "
#install mysql && php
#install mysqld first for support mysql
groupadd mysql && useradd -g mysql --system mysql
mkdir /mnt/logs/mysql -p
mkdir /mnt/data/mysql -p && chown mysql.mysql /mnt/data/mysql
cd /usr/local && mv mysql-5.7.15-* mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/mysql /usr/bin/
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mnt/data/mysql/ --explicit_defaults_for_timestamp
#添加配置文件到my.cnf
cat <<EOF > /etc/my.cnf
[client]
port=3306
socket=/dev/shm/mysql.sock

[mysqld]
basedir=/usr/local/mysql
datadir=/mnt/data/mysql
socket=/dev/shm/mysql.sock
pid-file=/mnt/data/mysql/mysql.pid
log_error=/mnt/logs/mysql/mysql-error.log

port=3306
server_id=1
user=mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
skip-grant-tables
EOF
/etc/init.d/mysqld start
mysql -e 'update mysql.user set authentication_string=password(" ") where
user="root";' #修改数据库密码为空
sed -i '/skip-grant-tables/d' /etc/my.cnf
/etc/init.d/mysqld restart
echo "mysql is installed okay,and it is initialized " >>/tmp/install.log

#安装php
echo -e "\033[32m*****************6.install php******************** \033[0m "
#install php
cd /usr/local/src/libmcrypt*
./configure --prefix=/usr/local/libmcrypt
make -j4 && make -j4 install
cd /usr/local/src/php*
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-session --with-mcrypt=/usr/local/libmcrypt --with-curl --enable-ctype --disable-fileinfo
make -j4 && make -j4 install
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/src/php-5.6.25/php.ini-development /usr/local/php/etc/php.ini
echo "php is installed okay" >>/tmp/install.log
echo -e "\033[32m*******************8***********install completed(lnmp环境安装完成)******************** \033[0m "

 

 

 

 

 

 

--------------------------------------------------------------------------------------------------------------------------*/