mdserver-web/plugins/openresty/install.sh

225 lines
6.8 KiB
Bash
Raw Normal View History

2018-11-25 04:48:48 -05:00
#!/bin/bash
2023-11-08 02:28:52 -05:00
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin
2018-11-25 04:48:48 -05:00
export PATH
2023-11-08 12:32:59 -05:00
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/openresty && bash install.sh install 1.21.4.2
2023-08-22 05:37:53 -04:00
# cd /www/server/mdserver-web/plugins/openresty && bash install.sh install 1.21.4.2
2023-02-13 07:34:25 -05:00
2018-11-25 04:48:48 -05:00
curPath=`pwd`
rootPath=$(dirname "$curPath")
rootPath=$(dirname "$rootPath")
serverPath=$(dirname "$rootPath")
2023-11-08 12:32:59 -05:00
sysName=`uname`
2018-12-04 22:01:25 -05:00
action=$1
type=$2
2018-11-25 04:48:48 -05:00
2020-06-28 01:44:38 -04:00
VERSION=$2
install_tmp=${rootPath}/tmp/mw_install.pl
openrestyDir=${serverPath}/source/openresty
2019-02-02 09:13:51 -05:00
if id www &> /dev/null ;then
2022-11-01 08:27:20 -04:00
echo "www uid is `id -u www`"
echo "www shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `"
2019-02-02 09:13:51 -05:00
else
groupadd www
2020-09-28 00:52:11 -04:00
useradd -g www -s /bin/bash www
2019-02-02 09:13:51 -05:00
fi
2023-11-08 12:32:59 -05:00
if [ "$sysName" == "Darwin" ];then
BAK='_bak'
else
BAK=''
fi
2020-06-28 01:44:38 -04:00
Install_openresty()
{
2022-11-18 11:46:08 -05:00
if [ -d $serverPath/openresty ];then
exit 0
fi
2022-08-01 01:34:40 -04:00
# ----- cpu start ------
if [ -z "${cpuCore}" ]; then
cpuCore="1"
fi
if [ -f /proc/cpuinfo ];then
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
fi
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
cpuCore="${MEM_INFO}"
fi
else
cpuCore="1"
2022-08-01 01:34:40 -04:00
fi
2022-11-04 10:17:57 -04:00
2022-11-05 22:10:34 -04:00
if [ "$cpuCore" -gt "2" ];then
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
else
cpuCore="1"
2022-11-04 10:17:57 -04:00
fi
2022-08-01 01:34:40 -04:00
# ----- cpu end ------
2020-06-28 01:44:38 -04:00
mkdir -p ${openrestyDir}
2023-11-08 12:32:59 -05:00
echo '正在安装脚本文件...'
2020-06-28 01:44:38 -04:00
2023-02-24 05:08:46 -05:00
# wget -O openresty-1.21.4.1.tar.gz https://openresty.org/download/openresty-1.21.4.1.tar.gz
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
2023-03-20 00:04:54 -04:00
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://openresty.org/download/openresty-${VERSION}.tar.gz -T 3
2023-03-20 00:01:46 -04:00
fi
DOWNLOAD_SIZE=`wc -c ${openrestyDir}/openresty-${VERSION}.tar.gz | awk '{print $1}'`
if [ "$DOWNLOAD_SIZE" == "0" ];then
echo 'download failed, download again'
rm -rf ${openrestyDir}/openresty-${VERSION}.tar.gz
fi
# Last Download Method
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
2023-11-30 22:43:31 -05:00
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz http://dl.midoks.icu/soft/openresty/openresty-${VERSION}.tar.gz -T 3
2023-02-24 04:55:13 -05:00
fi
2020-06-28 01:44:38 -04:00
cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz
2023-08-22 05:37:53 -04:00
OPTIONS=''
2023-09-04 06:35:12 -04:00
if [ "$VERSION" == "1.19.3.1" ]; then
2023-11-08 12:32:59 -05:00
OPTIONS="${OPTIONS} --with-ipv6"
fi
opensslVersion="1.1.1p"
2024-04-16 11:00:42 -04:00
libresslVersion="3.9.1"
2023-11-08 12:32:59 -05:00
pcreVersion='8.38'
if [ "$sysName" == "Darwin" ];then
if [ ! -f ${openrestyDir}/pcre-${pcreVersion}.tar.gz ];then
wget --no-check-certificate -O ${openrestyDir}/pcre-${pcreVersion}.tar.gz https://netix.dl.sourceforge.net/project/pcre/pcre/${pcreVersion}/pcre-${pcreVersion}.tar.gz
fi
if [ ! -d ${openrestyDir}/pcre-${pcreVersion} ];then
cd ${openrestyDir} && tar -zxvf pcre-${pcreVersion}.tar.gz
fi
OPTIONS="${OPTIONS} --with-pcre=${openrestyDir}/pcre-${pcreVersion}"
if [ ! -f ${openrestyDir}/openssl-${opensslVersion}.tar.gz ];then
wget --no-check-certificate -O ${openrestyDir}/openssl-${opensslVersion}.tar.gz https://www.openssl.org/source/openssl-${opensslVersion}.tar.gz
fi
if [ ! -d ${openrestyDir}/openssl-${opensslVersion} ];then
cd ${openrestyDir} && tar -zxvf openssl-${opensslVersion}.tar.gz
fi
OPTIONS="${OPTIONS} --with-openssl=${openrestyDir}/openssl-${opensslVersion}"
# BREW_DIR=`which brew`
# BREW_DIR=${BREW_DIR/\/bin\/brew/}
# brew info openssl@1.1 | grep /opt/homebrew/Cellar/openssl@1.1 | cut -d \ -f 1 | awk 'END {print}'
# OPENSSL_LIB_DEPEND_DIR=`brew info openssl@1.1 | grep ${BREW_DIR}/Cellar/openssl@1.1 | cut -d \ -f 1 | awk 'END {print}'`
# OPTIONS="${OPTIONS} --with-openssl=${OPENSSL_LIB_DEPEND_DIR}"
2024-04-16 09:43:16 -04:00
else
2024-04-17 11:25:32 -04:00
if [ ! -f ${openrestyDir}/openssl-${opensslVersion}.tar.gz ];then
wget --no-check-certificate -O ${openrestyDir}/openssl-${opensslVersion}.tar.gz https://www.openssl.org/source/openssl-${opensslVersion}.tar.gz
fi
if [ ! -d ${openrestyDir}/openssl-${opensslVersion} ];then
cd ${openrestyDir} && tar -zxvf openssl-${opensslVersion}.tar.gz
fi
OPTIONS="${OPTIONS} --with-openssl=${openrestyDir}/openssl-${opensslVersion}"
2024-04-16 09:43:16 -04:00
if [ "$VERSION" == "1.25.3.1" ]; then
OPTIONS="${OPTIONS} --with-http_v3_module"
2023-09-04 06:15:21 -04:00
2024-04-16 10:58:18 -04:00
if [ ! -f ${openrestyDir}/libressl-${libresslVersion}.tar.gz ];then
wget --no-check-certificate -O ${openrestyDir}/libressl-${libresslVersion}.tar.gz https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${libresslVersion}.tar.gz
fi
if [ ! -d ${openrestyDir}/libressl-${libresslVersion} ];then
cd ${openrestyDir} && tar -zxvf libressl-${libresslVersion}.tar.gz
fi
2024-04-17 11:25:32 -04:00
2024-04-16 11:10:30 -04:00
OPTIONS="${OPTIONS} --with-cc-opt=-I${openrestyDir}/libressl-${libresslVersion}/libressl/build/include"
OPTIONS="${OPTIONS} --with-cc-opt=-I${openrestyDir}/libressl-${libresslVersion}/libressl/build/lib"
2024-04-16 10:58:18 -04:00
# --with-cc-opt="-I../libressl/build/include"
# --with-ld-opt="-L../libressl/build/lib"
2024-04-16 09:43:16 -04:00
fi
fi
2024-04-04 06:14:42 -04:00
2020-07-13 20:38:10 -04:00
# --with-openssl=$serverPath/source/lib/openssl-1.0.2q
2023-02-24 05:08:46 -05:00
cd ${openrestyDir}/openresty-${VERSION} && ./configure \
2022-06-22 12:48:52 -04:00
--prefix=$serverPath/openresty \
2023-08-22 05:37:53 -04:00
$OPTIONS \
2022-10-27 11:44:40 -04:00
--with-stream \
2020-06-28 01:44:38 -04:00
--with-http_v2_module \
2020-07-13 20:38:10 -04:00
--with-http_ssl_module \
2021-01-12 00:13:30 -05:00
--with-http_slice_module \
2022-09-02 11:16:41 -04:00
--with-http_stub_status_module \
2022-11-04 09:03:06 -04:00
--with-http_sub_module \
2022-09-02 11:16:41 -04:00
--with-http_realip_module
2022-10-12 13:10:03 -04:00
# --without-luajit-gc64
2022-10-12 16:18:47 -04:00
# --with-debug
2022-10-12 13:10:03 -04:00
# 用于调式
2022-06-22 08:46:10 -04:00
2023-09-04 06:23:08 -04:00
CMD_MAKE=`which gmake`
if [ "$?" == "0" ];then
gmake -j${cpuCore} && gmake install && gmake clean
else
make -j${cpuCore} && make install && make clean
2023-09-04 06:30:40 -04:00
fi
2022-06-22 08:46:10 -04:00
2022-06-22 12:48:52 -04:00
if [ -d $serverPath/openresty ];then
echo "${VERSION}" > $serverPath/openresty/version.pl
2022-06-29 22:51:54 -04:00
mkdir -p $serverPath/web_conf/php/conf
2022-07-04 21:04:14 -04:00
echo 'set $PHP_ENV 0;' > $serverPath/web_conf/php/conf/enable-php-00.conf
2022-06-28 13:07:25 -04:00
#初始化
2022-06-28 13:31:34 -04:00
cd ${rootPath} && python3 ${rootPath}/plugins/openresty/index.py start
cd ${rootPath} && python3 ${rootPath}/plugins/openresty/index.py initd_install
2023-11-08 12:32:59 -05:00
rm -rf $openrestyDir/openresty-${VERSION}
fi
if [ -d ${openrestyDir}/pcre-${pcreVersion} ];then
rm -rf ${openrestyDir}/pcre-${pcreVersion}
fi
if [ -d ${openrestyDir}/openssl-${opensslVersion} ];then
rm -rf ${openrestyDir}/openssl-${opensslVersion}
2022-06-22 12:48:52 -04:00
fi
2024-04-16 11:11:17 -04:00
if [ -d ${openrestyDir}/libressl-${libresslVersion} ];then
rm -rf ${openrestyDir}/libressl-${libresslVersion}
fi
2023-11-08 12:32:59 -05:00
echo '安装完成'
2020-06-28 01:44:38 -04:00
}
Uninstall_openresty()
{
2022-06-28 13:07:25 -04:00
2022-07-11 03:19:39 -04:00
if [ -f /usr/lib/systemd/system/openresty.service ] || [ -f /lib/systemd/system/openresty.service ];then
2022-06-28 13:07:25 -04:00
systemctl stop openresty
2022-07-03 10:08:21 -04:00
rm -rf /usr/systemd/system/openresty.service
2022-07-11 03:19:39 -04:00
rm -rf /lib/systemd/system/openresty.service
2022-06-28 13:31:34 -04:00
systemctl daemon-reload
fi
if [ -f $serverPath/openresty/init.d/openresty ];then
$serverPath/openresty/init.d/openresty stop
2022-06-18 03:44:17 -04:00
fi
2022-06-28 13:07:25 -04:00
rm -rf $serverPath/openresty
2023-11-08 12:32:59 -05:00
echo '卸载完成'
2020-06-28 01:44:38 -04:00
}
action=$1
if [ "${1}" == 'install' ];then
Install_openresty
else
Uninstall_openresty
fi