lnmp 脚本自动安装

环境centos 6.5 版本

下载地址: lnmp.tar.gz 百度网盘下载

脚本执行过程中会有警告信息提示,不影响安装使用忽略即可!

lnmp组合包下载下来后解压到根目录!(当然你也可以修改脚本中路径,不解压到根目录)

执行脚本位置:/lnmp/install/install.sh


下面是脚本的大概信息:

#!/bin/bash

################################
# T:        lnmp 安装
# N\M :     jinchuang
# S\M:      需要将lnmp.tar.gz包解压到根目录下面
# B\C:      安装后的程序目录 /lnmp/lnmp/*
# S:        源码包路径 /lnmp/source/
# C:        需要的配置文件路径 /lnmp/etc/
# S:        需要的启动脚本路径 /lnmp/server/
################################

#变量定义

color=`echo -e "\033[36m!!请输入正确的编号!! \033[0m"`

################################

while true
do
echo "**************-----------------****************
1: 更换yum源和安装相关包
2: 安装nginx
3: 安装mysql
4: 安装php
5: 调整nginx支持php
6: exit !
**************-----------------****************"
read -p "输入编号:" n
case $n in

#*********** 更换yum源、安装需要的相关的包 **********#
1)

#iptables 和 selinux
service iptables stop >/dev/null
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

#更换yum源|阿里云的源和epel的源#
cd /etc/yum.repos.d/
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
echo "更换yum 源 ..."
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 2>&1 >/dev/null
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo 2>&1 >/dev/null

#yum安装相关依赖包#
echo "安装需要相关的包 ..."
yum -y install vim wget lfzsz ntp tar make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ gcc-gfortran libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 libtool flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof libmcrypt-devel mcytpt mhash libxslt-devel libcurl-devel 2>&1 >/dev/null
echo "包安装完成"
;;
#*********** 安装nginx **********#
2)
#解压需要的源码包#

cd /lnmp/source
tar -zxf nginx-1.9.8.tar.gz
tar -zxf pcre-8.35.tar.gz
tar -zxf openssl-1.0.2h.tar.gz
tar -zxf zlib-1.2.8.tar.gz

#nginx 安装#
mkdir /var/nginx
useradd nginx -M -s /sbin/nologin

#install nginx
cd nginx-1.9.8
echo "nginx configure 中 ..."
./configure \
--prefix=/lnmp/lnmp/nginx \
--lock-path=/var/nginx/nginx.lock \
--user=nginx \
--group=nginx \
--http-client-body-temp-path=/var/nginx/client/ \
--http-proxy-temp-path=/var/nginx/proxy/ \
--http-fastcgi-temp-path=/var/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/nginx/uwsgi \
--http-scgi-temp-path=/var/nginx/scgi \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-file-aio \
--with-http_image_filter_module \
--with-http_realip_module \
--with-pcre=/lnmp/source/pcre-8.35 \
--with-stream \
--with-openssl=/lnmp/source/openssl-1.0.2h \
--with-zlib=/lnmp/source/zlib-1.2.8 2>&1 >/dev/null
echo "nginx configure 完成"
echo "make && make install 中 ..."
make 2>&1 >/dev/null
make install 2>&1 >/dev/null
echo "nginx make install 完成"
echo "copy 启动脚本 ..."
cp /lnmp/server/nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx

# start nginx server|获取服务状态码
echo "启动 Nginx"
service nginx start
ip=`ifconfig eth0 |awk -F "[:| ]+" '/inet addr:/{print $4}'`
str=`curl -I -m 10 http://$ip -o /dev/null -s -w %{http_code}`
if [ $? == "0" ]
then
echo "nginx 服务启动成功,状态码:$str"
else
echo "nginx 服务启动失败,状态码:$str"
fi
echo "#######################
程序目录:/lnmp/lnmp/nginx
配置文件:/lnmp/lnmp/nginx/conf/"
sleep 5

;;
#*********** 安装mysql **********#
3)
#创建用户
useradd mysql -M -s /sbin/nologin
mkdir -p /var/log/mysql
#解压相关包
cd /lnmp/source
tar -xf cmake-3.4.3.tar.gz
tar -xf mysql-5.6.4-m7.tar.gz

#install cmake
cd /lnmp/source/cmake-3.4.3
echo "cmake configure ..."
./configure 2>&1 >/dev/null
echo "camke configure 完成"
echo "gmake && gmake install ..."
gmake 2>&1 >/dev/null
gmake install 2>&1 >/dev/null
echo "cmake 安装完成"
#install mysql
cd /lnmp/source/mysql-5.6.4-m7
echo "cmake mysql ..."
cmake \
-DCMAKE_INSTALL_PREFIX=/lnmp/lnmp/mysql \
-DMYSQL_DATADIR=/lnmp/lnmp/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/lnmp/lnmp/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system 2>&1 >/dev/null
echo " cmake mysql 完成"
echo " mysql make && make install ..."
make 2>&1 >/dev/null
make install 2>&1 >/dev/null
echo " mysql make install 完成"
echo "copy mysql 配置文件 授权..."
mv /etc/my.cnf /etc/my.cnf.bak
cp /lnmp/etc/my.cnf /etc/
chmod +w /lnmp/lnmp/mysql
chown -R mysql:mysql /lnmp/lnmp/mysql

#初始化mysql
echo "初始化数据库 ..."
/lnmp/lnmp/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/lnmp/lnmp/mysql --datadir=/lnmp/lnmp/mysql/data --user=mysql 2>&1 >/dev/null

cp /lnmp/source/mysql-5.6.4-m7/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

#start mysql
echo "启动 mysql"
service mysqld start
echo "############################
程序目录: /lnmp/lnmp/mysql
配置文件: /etc/my.cnf"
sleep 5
;;
#*********** 安装php **********#
4)
#创建程序运行用户(nginx 安装过则不需要此步骤)
useradd nginx -M -s /sbin/nologin

# 解压包
cd /lnmp/source
tar -xf php-5.6.20.tar.gz
tar -xf libiconv-1.14.tar.gz

# install libiconv
cd libiconv-1.14
echo "configure libiconv ..."
./configure --prefix=/lnmp/lnmp/libiconv 2>&1 >/dev/null
echo "configure libiconv 完成"
echo "libiconv make && make install ..."
make 2>&1 >/dev/null
make install 2>&1 >/dev/null
echo "libiconv make && make install 完成"

# install php
cd /lnmp/source/php-5.6.20
echo "configure php ..."
./configure \
--prefix=/lnmp/lnmp/php-5.6.20 \
--with-config-file-path=/lnmp/lnmp/php-5.6.20/etc \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-bz2 \
--with-curl \
--with-gd \
--with-mcrypt \
--with-openssl \
--with-mhash \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir=/lnmp/lnmp/libiconv \
--with-gettext \
--with-libxml-dir=/lnmp/lnmp \
--with-zlib \
--with-xsl \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-libdir=lib64 \
--enable-dom \
--enable-xml \
--enable-fpm \
--enable-bcmath \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--enable-mbregex \
--enable-mbstring \
--enable-calendar \
--enable-gd-native-ttf \
--enable-static 2>&1 >/dev/null
echo "configure php 完成"
echo "php make && make install ..."
make 2>&1 >/dev/null
make install 2>&1 >/dev/null

#安装后配置文件和启动改动
echo "copy 文件,添加启动脚本..."
cp php.ini-production /lnmp/lnmp/php-5.6.20/etc/php.ini
cp /lnmp/lnmp/php-5.6.20/etc/php-fpm.conf.default /lnmp/lnmp/php-5.6.20/etc/php-fpm.conf
mkdir -p /lnmp/lnmp/php-5.6.20/log
cp /lnmp/server/php-fpm /etc/init.d/
chmod +x /etc/init.d/php-fpm
echo "启动 php"
service php-fpm start
echo "#####################
程序目录:/lnmp/lnmp/php-5.6.20
php-fpm.conf/php.ini : /lnmp/lnmp/php-5.6.20/etc"
sleep 5
;;
#********** nginx 支持 php *********#
5)
mv /lnmp/lnmp/nginx/conf/nginx.conf /lnmp/lnmp/nginx/conf/nginx.conf.bak
cp /lnmp/etc/nginx.conf /lnmp/lnmp/nginx/conf/
service nginx restart
echo " nginx 已经支持 php"
;;

#*********** 退出 **********#
6)
exit 1
;;

*)
echo "$color"
;;
esac
done

 

分享