1 Star 1 Fork 0

pantian/lnmp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lnmp.sh 11.66 KB
一键复制 编辑 原始数据 按行查看 历史
xiaoshenghuo 提交于 2017-04-14 23:43 . php7.1.14
#!/bin/sh
# LNMP 一安装包 ,本shell脚本为方便快速搭建LNMP开发环境而写的脚本,因为shell水平有限,有望高手指点与指错。安装过程完全是编译安装,所以过程会比较慢,大概要30分钟左右
# nginx tengine-2.1.0
# php 5.6.7
# mysql 5.6
# 启动
# mysql: service mysqld start
# nginx: service nginx start
# 反馈信息
# 作者:潘田
# E_mail: pt444@126.com
# QQ:405336302
#
yum -y install cmake pcre make apr* autoconf automake curl-devel 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 libselinux-devel krb6-devel zlib-devel libXpm* freetype libjpeg* libpng* ncurses* libtool* libxml2 libxml2-devel patch freetype-devel wget gzip libtool bzip2* appropriate* libpng* pcre*
yum -y install bzip3 bzip2-devel bzip2-libs curl libcurl libcurl-devel openjpeg openjpeg-devel openjpeg-libs libjpeg*
yum -y install libpng* freetype freetype-devel pcre pcre-devel ncurses ncurses-devel cmake
#当前目录
cDir=`pwd`'/'
#检测是否已安装相关依赖,没有安装的将自动安装
function chkYumInstall_lib(){
if [ $# -lt 1 ];then
echo 'nothing to do'
else
for loop
do
is_installed=`rpm -q $loop|awk '{print $4}'`
if [ "$is_installed" = 'not' ];then
yum -y install $loop
if [ $? = 0 ];then
echo "安装$loop成功"
else
echo "安装$loop失败"
fi
else
echo "$loop is installed"
fi
done
fi
}
#LNMP 安装目录
install_dir="/usr/local/lnmp2/"
#php 安装目录
php_version='php-7.1.14';
php_install_dir=$install_dir$php_version"/"
#php-fpm 目录
php_fpm_file=$php_install_dir'sbin/php-fpm'
php_fpm_config=$php_install_dir'etc/php-fpm.conf'
#mysql 安装目录
#mysql_install_dir=$install_dir'mysqli-5.6'
mysql_version='mysql-5.7.13'
mysql_install_dir=$install_dir$mysql_version
#检测nginx是否安装了
function chkInstall(){
# chkResult=`whereis nginx |awk '{print $2}'`
sbinFile="$install_dir/$1"
echo $sbinFile
if [ -e $sbinFile ];then
return 0
else
return 1
fi
}
mysqlUser='mysql'
mysqlGroup='mysql'
nginxUser='nginx'
nginxGroup='nginx'
#用户组名与用户名相同
function createUser(){
user=$1
oldGroup=`cat /etc/group|grep $user |awk -F ":" '{print $1}'`
if [ "$user" != "$oldGroup" ];then
echo '创建用户组:'$user
groupadd $user
fi
oldUser=`cat /etc/passwd|grep $user |awk -F ":" '{print $1}'`
echo "oldUser=$oldUser"
if [ "$user" != "$oldUser" ];then
echo "创建用户:$user"
useradd -g $user -m $user -s /sbin/nologin
fi
}
createUser $mysqlUser
createUser $nginxUser
function install_nginx(){
app='nginx'
install_dir="$install_dir$app"
if [ "$1" = 'reinstall' ];then
echo '删除'$install_dir
rm -Rf $install_dir
fi
echo $install_dir
if [ ! -d $install_dir ];then
service $app stop
mkdir $install_dir
fi
chkInstall 'sbin'
if [ $? = 1 ];then
#source_dir='nginx-1.7.3'
source_dir='tengine-2.1.0'
source_file=$source_dir'.tar.gz'
cd $cDir
if [ ! -e $source_file ];then
download_source_url="http://nginx.org/download/$source_file"
echo 'download source'$soucre_file
wget $download_source_url
fi
tar -zxvf $source_file
echo '进入目录'$source_dir
cd $source_dir
pwd
nginx_group='nginx'
nginx_user='nginx'
createUser $nginx_user
./configure\
--prefix=$install_dir\
--user=$nginx_user\
--group=$nginx_group\
--with-http_ssl_module\
--with-http_spdy_module\
--with-pcre\
--with-http_gzip_static_module\
--with-http_stub_status_module
if [ "$?" = "0" ];then
make && make install
if [ "$?" = '0' ];then
serviceFile=/etc/rc.d/init.d/nginx
nginxPIDFile=$install_dir"/logs/nginx.pid"
echo "#!/bin/sh
#chkconfig 23456 80 90
#description nginx auto run
">$serviceFile
echo "
function start(){
sleep 1
echo 'start php-fpm ...'
$php_fpm_file -y $php_fpm_config
if [ \$? = 0 ];then
echo 'start php-fpm ============================[ok]'
else
echo 'start php-fpm ============================[fail]'
fi
pid=\`ps -ef |grep nginx |awk '\$8==\"$app:\"&& \$3==\"1\"{print \$2}'\`
if [ \"\$pid\" != \"\" ];then
echo '$app is running ...'
else
$install_dir'/sbin/nginx'
if [ \$? = 0 ];then
echo '$app start =======================[ok]'
return 0
else
echo '$app start =======================[fail]'
fi
fi
return 1
}
">>$serviceFile
echo "
function stop(){
pid=\`ps -ef |grep nginx |awk '\$8==\"$app:\"&& \$3==\"1\"{print \$2}'\`
echo \$pid
if [ -z "$pid" ] && [ -f $nginxPIDFile ];then
pid=\`cat $nginxPIDFile\`
fi
echo \$pid
php_fpm_file='/var/run/php_fpm.pid'
if [ -f \$php_fpm_file ];then
php_pid=\`cat \$php_fpm_file\`
if [ ! -z \$php_pid ];then
kill -QUIT \$php_pid
if [ \$? = 0 ];then
echo 'stop php-fpm ===========================[ok]'
else
echo 'stop php-fpm ==========================[fail]'
fi
else
echo 'php-fpm not run'
fi
else
echo 'php-fpm not run'
fi
if [ ! -z \$pid ];then
kill -QUIT \$pid
if [ \$? = 0 ];then
echo '$app stop ==========================[ok]'
return 0
else
echo '$app stop ==========================[fail]'
return 1
fi
else
echo '$app is not run'
fi
}
">>$serviceFile
echo "
function restart(){
stop
sleep 1
start
return 0
}
">>$serviceFile
echo "
function remove(){
service $app stop
if [ \$? = 0 ] && [ -d $install_dir ];then
rm -Rf $install_dir
if [ \$? = 0 ] && [ -f $serviceFile ];then
rm -Rf $serviceFile
fi
echo '$app is removed '
return 0
else
echo 'remove $app failed'
return 1
fi
}
">>$serviceFile
echo "
case \$1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
remove)
echo 'confirm remvoe $app :y/n'
read confirm
if [ \"\$confirm\" = 'y' ];then
remove
else
echo 'nothing to do'
fi
;;
*)
start
;;
esac
">>$serviceFile
chmod +x $serviceFile
#配置文件修改
nginxConfFile=$install_dir'/conf/nginx.conf'
#默认web根目录
document_root=$install_dir'/html/'
sed -i "1a user $nginxUser;" $nginxConfFile
sed -i "66 s/#//g" $nginxConfFile
sed -i "67 s/#//g" $nginxConfFile
sed -i "68 s/#//g" $nginxConfFile
sed -i "69 s/#//g" $nginxConfFile
sed -i "70 s/#//g" $nginxConfFile
sed -i "71 s/#//g" $nginxConfFile
sed -i "72 s/#//g" $nginxConfFile
dou=${document_root//\//\\\/}
sed -i "70 s/\/scripts/$dou/g" $nginxConfFile
echo "$app install successed"
fi
else
echo 'create configure fail'
fi
else
echo "$app is installed"
fi
}
function php_fpm_stop(){
php_fpm_pid=`ps -ef |grep php-fpm |awk '$9=="master"{print $2}'`
if [ ! -z "$php_fpm_pid" ];then
kill -QUIT $php_fpm_pid
if [ $? = 0 ];then
echo 'php_fpm is stoped ===========================[ ok ]'
return 0
else
echo 'php_fpm stop fail ===========================[ failed ] '
return 1
fi
else
echo 'php-fpm is not runnign'
return 1
fi
}
#安装mysql
function install_mysql(){
yum -y install gcc gcc-devel gcc-c++ gcc-c++-devel autoconf* automake* zlib* libxml* ncurses-devel ncurses libgcrypt* libtool* cmake openssl openssl-devel bison bison-devel unzip
cd $cDir
mysql=$mysql_version
mysql_tarFile=$mysql'.tar.gz'
if [ -f $mysql_tarFile ];then
echo '解压'$mysql_tarFile
tar -zxf $mysql_tarFile
else
echo '文件不存在'$mysql_tarFile
exit 1
fi
if [ -d $mysql_install_dir ];then
echo '删除'$mysql_install_dir
# rm -Rf $mysql_install_dir
fi
mkdir -p $mysql_install_dir
cd $mysql
cmake \
-DCMAKE_INSTALL_PREFIX=$mysql_install_dir\
-DMYSQL_DATADIR=$mysql_install_dir/data\
-DSYSCONFDIR=$mysql_install_dir/etc\
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=$mysql_install_dir/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
make && make install
if [ $? != 0 ];then
echo '安装失败'
exit 1
fi
chown -R $mysqlUser:$mysqlGroup $mysql_install_dir
$mysql_install_dir/scripts/mysql_install_db\
--basedir=$mysql_install_dir\
--datadir=$mysql_install_dir/data\
--user=$mysqlUser
cp $mysql_install_dir/support-files/mysql.server /etc/init.d/mysqld
rm -Rf /etc/my.cnf
cp $mysql_install_dir/my.cnf /etc/my.cnf
ln -s $mysql_install_dir/lib/mysql /usr/lib/mysql
ln -s $mysql_install_dir/include/mysql /usr/include/mysql
chkconfig mysqld on
if [ $? = 0 ];then
echo '安装成功'$mysql
fi
}
#安装php
function install_php(){
php_app='php'
if [ $1 = 'reinstall' ];then
php_fpm_stop
rm -Rf $php_isntall_dir
fi
if [ ! -d $php_install_dir ];then
#创建 php 安装目录
mkdir -p $php_install_dir
if [ $? = 0 ];then
echo "create $app install dir success"
fi
fi
cd $cDir
#安装 libmcrypt
is_install_libmcrypt=`whereis libmcrypt |awk '{print $4}'`
if [ -z "$is_install_libmcrypt" ];then
libmcrypt_dir='libmcrypt-2.5.7'
libmcrypt_tar_file=$libmcrypt_dir'.tar.gz'
if [ ! -e "$libmcrypt_tar_file" ];then
echo 'download libmcrypt pack'
wget "http://down1.chinaunix.net/distfiles/$libmcrypt_tar_file"
fi
tar -zxvf $libmcrypt_tar_file
cd $libmcrypt_dir
./configure
make && make install
if [ $? = 0 ] ;then
echo 'install libmcrypt successed'
else
echo 'isntall libmcrypt failed '
return 1
fi
else
echo 'libmcrypt is installed'
fi
#install php
cd $cDir
php_install_dir
php_dir=$php_version
php_tar_file=$php_dir'.tar.gz'
if [ ! -e "$php_tar_file" ];then
wget "http://cn2.php.net/distributions/php-5.5.14.tar.gz"
fi
tar -zxf $php_tar_file
cd $php_dir
pwd
./configure\
--prefix=$php_install_dir\
--with-mysql=$mysql_install_dir\
--with-mysqli=$mysql_install_dir/bin/mysql_config\
--with-bz2\
--with-curl\
--with-curlwrappers\
--enable-ftp\
--enable-sockets\
--with-iconv\
--with-openssl\
--with-gd\
--without-pear\
--with-mcrypt\
--with-jpeg-dir\
--with-gif-dir\
--with-png-dir\
--with-freetype-dir\
--with-bz2\
--with-libXML-dir\
--with-zlib\
--with-zlib-dir\
--enable-sysvsem\
--enable-sigchild\
--enable-pdo\
--with-mhash\
--enable-fastCGI\
--enable-soap\
--with-pdo-mysql=$mysql_install_dir\
--enable-mbstring\
--enable-bcmath\
--enable-shmop\
--enable-inline-optimization\
--enable-mbregex\
--enable-gd-native-ttf\
--enable-pcntl\
--enable-session\
--enable-calendar\
--with-gettext\
--enable-xml\
--enable-dom\
--enable-magic-quotes\
--enable-exif\
--enable-fpm
if [ $? = 0 ];then
make
if [ $? = 0 ];then
make install
if [ $? = 0 ];then
rm -Rf $php_fpm_config
cp -f $php_install_dir/etc/php-fpm.conf.default $php_fpm_config
if [ $? = 0 ];then
sed -i "148 s/user = nobody/user = $nginxUser/g" $php_fpm_config
sed -i "149 s/group = nobody/group = $nginxGroup/g" $php_fpm_config
sed -i "25a pid = \/var\/run\/php_fpm.pid" $php_fpm_config
fi
echo 'php install successed'
else
echo 'error: php make install failed'
exit 1
fi
else
echo 'error: php make fail'
exit 1
fi
else
echo 'error: php reate configre failed'
exit 1
fi
}
case $1 in
reinstall)
echo '重新安装'
install_mysql $1
install_php $1
install_nginx $1
;;
*)
install_mysql
install_php
install_nginx
# if [ $chk_is_install = 0 ];then
# echo "$app is installed"
# else
# echo "$app not installed"
# fi
;;
esac
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/pantian/lnmp.git
git@gitee.com:pantian/lnmp.git
pantian
lnmp
lnmp
master

搜索帮助