1. install Notes
- 本文所需软件包,存放与解压目录均为
/usr/local/src; - 可自行选择编译安装或非编译安装,即
5-3 或 5-2 ; - 本文是在
yum -y install nginx基础上,进行升级的,仅初步验证其可行性;
2. install LuaJIT
cd /usr/local/src/
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
tar -zxvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5
make && make install PREFIX=/usr/local/luajit
vim ~/.bashrc
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
ln -s /usr/local/luajit/bin/luajit-2.0 /usr/bin/luajit-2.0
ln -s /usr/local/luajit/bin/luajit /usr/bin/luajit
# 在 nginx make install 时要求,即 5-3时所需
ln -s /usr/local/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
3. ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -zxvf v0.3.0.tar.gz
4. lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
tar -zxvf v0.10.15.tar.gz
# ./configure: error: unsupported LuaJIT version; ngx_http_lua_module requires LuaJIT 2.x.
# 即安装LuaJIT并配置环境变量, 可能也不行, 需进行如下配置
cd lua-nginx-module-0.10.15
vim config
# 直接声明这两个变量
LUAJIT_LIB=/usr/local/luajit/lib
LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
5. nginx and module
1. 安装必要模块
yum -y install gcc gcc-c++ openssl openssl-devel pcre pcre-devel
yum -y install zlib zlib-devel libxml2 libxml2-dev lua-devel
# 编译安装时运行
yum -y install redhat-rpm-config gd-devel libxslt-devel perl-ExtUtils-Embed geoip-devel gperftools
2. 非编译安装
# nginx version 1.20.1
yum -y install nginx
# 查看配置信息
nginx -V
# 查看nginx路径
whereis nginx
# 查询是否安装nginx
rpm -q nginx
# 查询nginx安装包的版本
rpm -qi nginx
# 查询nginx安装的文件路径
rpm -ql nginx
# 查询nginx软件包的配置文件
rpm -qc nginx
# 查询nginx的帮助文档
rpm -qd nginx
3. 编译安装
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
# 查看该源码所支持的模块
./configure --help
# 后面标记enable的,代表已有此模块(编译时,不需要添加)
# 后面标记disable的,代表不支持此模块(如果有需要,编译时要自己添加)
# 进行配置,可根据需要自定义所需模块,示例如下
./configure --prefix=/usr/share/nginx \
--add-module=/usr/local/src/ngx_devel_kit-0.3.0 \
--add-module=/usr/local/src/lua-nginx-module-0.10.13
# 构建与安装
make && make install
# 以下是可能需要进行的操作
ln -s /usr/share/nginx/sbin/nginx /usr/sbin/nginx
4. 进行平滑升级
# 通过以下命令,获取 yum -y install nginx 配置信息
nginx -V
# 进行配置操作(添加实际所需模块)
# 具体配置信息,可见后续 5-6,方便复制操作
# 以下问题是可能在配置过程中出现的问题与处理
# ./configure: error: the invalid value in --with-ld-opt
yum -y install redhat-rpm-config
# ./configure: error: the HTTP XSLT module requires the libxml2/libxslt library.
yum -y install libxslt-devel
# ./configure: error: the HTTP image filter module requires the GD library.
yum -y install gd-devel
# ./configure: error: perl module ExtUtils::Embed is required
yum -y install perl-ExtUtils-Embed
# ./configure: error: the GeoIP module requires the GeoIP library.
yum -y install geoip-devel
# ./configure: error: the Google perftools module requires the Google perftools library.
yum -y install gperftools
# 构建与查看构建产物
make
cd /usr/local/src/nginx-1.20.1/objs
ls
# 替换nginx可执行命令文件,可先备份/usr/sbin/nginx,以便进行恢复
cp /usr/local/src/nginx-1.20.1/objs/nginx /usr/sbin/nginx
5. 初步验证测试
server {
listen 8000;
listen [::]:8000;
server_name _;
location / {
default_type text/html;
lua_code_cache off;
content_by_lua 'ngx.say("My lua Test")';
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
6. 升级所需配置
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/usr/local/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/lua-nginx-module-0.10.15