测试环境:CentOS Linux release 7.6.1810 (Core) 虚拟机一台
重要提示:一定要仔细看看官方文档!一定要仔细看看官方文档!一定要仔细看看官方文档!
Nginx 安装一般都需要 pcre、zlib、jemalloc、openssl这个库,查看http://nginx.org/en/docs/configure.html 文档
--with-pcre
forces the usage of the PCRE library.
--with-pcre=
path
sets the path to the sources of the PCRE library.
--with-zlib=
path
sets the path to the sources of the zlib library.
--with-openssl=
path
sets the path to the OpenSSL library sources.
jemalloc没有提及,可以采用上面方式安装。
pcre、zlib、jemalloc、openssl 手动安装,不指定安装路径,使用默认安装路径
#!/bin/bash
clear
function sttyPrintln(){
local message="$1"
shift 1
local program="$1"
shift
printf "%-50s%30s\n" "$message" "$program"
}
function unpackageTar(){
local programName="$1"
shift
if [[ -d "./${programName}" ]]; then
sttyPrintln '删除历史安装缓存...' $programName
rm -rf "./${programName}"
fi;
if [[ -r "./${programName}.tar.gz" ]]; then
sttyPrintln '组件解压文件路径...' $programName
tar -zxf "./${programName}.tar.gz"
elif [[ -r "./${programName}.tgz" ]]; then
sttyPrintln '组件解压文件路径...' $programName
tar -zxf "./${programName}.tgz"
elif [[ -r "./${programName}.tar.bz2" ]]; then
sttyPrintln '组件解压文件路径...' $programName
tar -jxf "./${programName}.tar.bz2"
else
sttyPrintln "组件$programName无法找到,即将退出安装..."
fi;
}
function configureInstall(){
local tmpPackage="$1"
shift 1
local programName=${tmpPackage//'.tar.gz'/''}
programName=${programName//'.tgz'/''}
if [[ -d "./${programName}" ]]; then
cd "./${programName}"
sttyPrintln '组件开始编译安装...' $programName
if [[ -r "./config" ]]; then
./config
elif [[ -r "./configure" ]]; then
./configure
else
sttyPrintln "Configure文件无法找到,即将退出安装..." ${programName}
fi
make
echo "$sudoPasswd" | sudo -S make install
sttyPrintln '依赖组件安装完成...' $installPath"/"${programName}
cd ..
sleep 3
else
sttyPrintln "组件解压文件无法找到,即将退出安装..." "./${programName}"
exit 1
fi;
}
sttyPrintln '开始安装 Tengine 及其相关组件...'
bachPath=$(pwd)
sudoPasswd='wntime'
baseInstall='/usr/programs'
sttyPrintln '创建程序安装目录...' $baseInstall
echo $sudoPasswd | sudo -S mkdir -p $baseInstall
echo $sudoPasswd | sudo -S chown -R wntime:wntime $baseInstall
sttyPrintln '准备编译安装环境...'
echo $sudoPasswd | sudo -S yum install gcc gcc-c++ wget perl unzip autogen autoconf bzip2 lua-devel -y
program='pcre-8.43'
unpackageTar $program
configureInstall $program $baseInstall
program='openssl-1.1.1c'
unpackageTar $program
configureInstall $program $baseInstall
program='zlib-1.2.11'
unpackageTar $program
configureInstall $program $baseInstall
program='jemalloc-5.2.1'
unpackageTar $program
configureInstall $program $baseInstall
安装 Tengine 2.2.3
program='tengine-2.2.3'
unpackageTar $program
sttyPrintln '组件开始编译安装...' $program
cd "./$program"
./configure --prefix="$baseInstall/$program" \
--with-ld-opt=-Wl,-rpath, \
--user=wntime \
--group=wntime \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_mp4_module \
--with-http_secure_link_module \
--with-http_sysguard_module \
--with-http_concat_module \
--with-http_lua_module \
--with-http_upstream_check_module \
--with-pcre
--with-zlib
--with-jemalloc
--with-openssl
make
# echo "$sudoPasswd" | sudo -S make install
make install
sttyPrintln 'Tengine 及其相关组件安装完成...'
这种方式可能报以下错误:
openssl:error while loading shared libraries:libssl.so.1.1:cannot open shared object file:No such file or directory
解决方式:
function createLink(){
local file="$1"
if [[ -r "/usr/local/lib64/$file" ]]; then
echo "wntime" | sudo -S ln -s /usr/local/lib64/$file /usr/lib64/$file
fi;
}
cd $baseInstall/$program
if [[ -r "./sbin/nginx" ]]; then
files=$(ldd ./sbin/nginx | grep 'not found' | awk '{print $1}')
for item in $files; do
sttyPrintln '创建软连接文件...' $item
createLink $item
done;
else
sttyPrintln './sbin/nginx无法找到,Tengine 安装失败...'
exit 1
fi;
至此完成 Tengine的安装
tengine-2.2.3]$ ./sbin/nginx -m
Tengine version: Tengine/2.2.3 (nginx/1.8.1)
nginx: loaded modules:
nginx: ngx_core_module (static)
nginx: ngx_errlog_module (static)
nginx: ngx_conf_module (static)
nginx: ngx_dso_module (static)