下面,我们来了解一下 OpenResty 的安装方法。
使用包管理系统直接安装
安装 OpenResty 最简单的方式就是通过各个操作系统中自带的包管理工作来安装了。
例如,对于 MacOS,可以使用 brew 来安装,对于 CentOS,可以使用 yum 来安装,对于 Ubuntu 而言,可以使用 apt 来安装等等。
需要注意的是,在使用包管理工具来安装 OpenResty 时,我们通过用的不是操作系统内置的源,而是会使用 OpenResty 提供的仓库。
以 MacOS 系统为例,安装方式如下:
brew tap openresty/brewbrew install openresty
以 CentOS 系统为例,安装方式如下:
# add the yum repo:wget https://openresty.org/package/centos/openresty.reposudo mv openresty.repo /etc/yum.repos.d/# update the yum index:sudo yum check-update# installsudo yum install openrestysudo yum install openresty-resty# query related packagesudo yum --disablerepo="*" --enablerepo="openresty" list available
源码编译安装
我们都知道,包管理器直接安装的 OpenResty 是没有办法自主控制编译选项的。
这对我们的使用场景是非常不友好的。
下面,我们就来看一下如何通过源码的方式来编译 OpenResty 吧。
Step1: 安装 pcre
wget http://www.missshi.cn:8089/pcre-8.42.tar.bz2tar xjf pcre-8.42.tar.bz2cd pcre-8.42./configure --prefix=/home/work/openresty-dependency/pcre --disable-cpp --enable-jit --enable-utf --enable-unicode-propertiesmake -j24 V=1make installrm -rf /home/work/openresty-dependency/pcre/binrm -rf /home/work/openresty-dependency/pcre/sharerm -f /home/work/openresty-dependency/pcre/lib/*.larm -f /home/work/openresty-dependency/pcre/lib/*pcrecpp*rm -f /home/work/openresty-dependency/pcre/lib/*pcreposix*rm -rf /home/work/openresty-dependency/pcre/lib/pkgconfig
Step2: 安装 zlib
wget http://www.zlib.net/zlib-1.2.11.tar.xztar xf zlib-1.2.11.tar.xzcd zlib-1.2.11./configure --prefix=/home/work/openresty-dependency/zlibmake -j24 \CFLAGS='-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -g' \SFLAGS='-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -g'make installrm -rf /home/work/openresty-dependency/zlib/share/rm -f /home/work/openresty-dependency/zlib/lib/*.larm -rf /home/work/openresty-dependency/zlib/lib/pkgconfig/
Step3: 安装 openssl
wget https://www.openssl.org/source/openssl-1.1.0j.tar.gzwget http://www.missshi.cn:8089/openssl-1.1.0d-sess_set_get_cb_yield.patch --no-check-certificatewget http://www.missshi.cn:8089/openssl-1.1.0j-parallel_build_fix.patch --no-check-certificatetar zxf openssl-1.1.0j.tar.gzcd openssl-1.1.0jpatch -p1 < ../openssl-1.1.0d-sess_set_get_cb_yield.patchpatch -p1 < ../openssl-1.1.0j-parallel_build_fix.patch./config \no-threads shared zlib -g \enable-ssl3 enable-ssl3-method \--prefix=/home/work/openresty-dependency/openssl \--libdir=lib \-I%/home/work/openresty-dependency/zlib/include \-L%/home/work/openresty-dependency/zlib/lib \-Wl,-rpath,/home/work/openresty-dependency/zlib/lib:/home/work/openresty-dependency/openssl/libmake -j24make install_swrm -f /home/work/openresty-dependency/openssl/bin/c_rehashrm -rf /home/work/openresty-dependency/openssl/lib/pkgconfig
Step4: 编译安装 OpenResty
wget https://openresty.org/download/openresty-1.15.8.1.tar.gztar zxf openresty-1.15.8.1.tar.gzcd openresty-1.15.8.1./configure \--prefix=/home/work/openresty \--with-cc-opt="-DNGX_LUA_ABORT_AT_PANIC \-I/home/work/openresty-dependency/zlib/include \-I/home/work/openresty-dependency/pcre/include \-I/home/work/openresty-dependency/openssl/include" \--with-ld-opt="-L/home/work/openresty-dependency/zlib/lib \-L/home/work/openresty-dependency/pcre/lib \-L/home/work/openresty-dependency/openssl/lib \-Wl,-rpath,/home/work/openresty-dependency/zlib/lib:/home/work/openresty-dependency/pcre/lib:/home/work/openresty-dependency/openssl/lib" \--with-pcre-jit \--without-http_rds_json_module \--without-http_rds_csv_module \--without-lua_rds_parser \--with-stream \--with-stream_ssl_module \--with-stream_ssl_preread_module \--with-http_v2_module \--without-mail_pop3_module \--without-mail_imap_module \--without-mail_smtp_module \--with-http_stub_status_module \--with-http_realip_module \--with-http_addition_module \--with-http_auth_request_module \--with-http_secure_link_module \--with-http_random_index_module \--with-http_gzip_static_module \--with-http_sub_module \--with-http_dav_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-threads \--with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT' \-j24make -j24make install
至此,我们的 OpenResty 就已经成功安装完成了,快来试试吧!
Ps: 上述用到源码包如果下载不下来,可以访问 package 下载。
