迁移编译后nginx环境准备

新环境运行条件


由于在编译时,植入了lua模块插件,所以在将编译后的nginx迁移至其它的环境或新环境运行时,需要如下条件

错误一

  1. nginx执行报错
    [root@9e1af72b3647 /]# nginx -V
    nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
  2. 解决方法
    ##克隆 luajit2
    [root@9e1af72b3647 ~]# git clone https://github.com/openresty/luajit2.git
    Cloning into 'luajit2'...
    remote: Enumerating objects: 19921, done.
    remote: Counting objects: 100% (19921/19921), done.
    remote: Compressing objects: 100% (3869/3869), done.
    remote: Total 19921 (delta 16107), reused 19806 (delta 16041), pack-reused 0
    Receiving objects: 100% (19921/19921), 7.92 MiB | 3.76 MiB/s, done.
    Resolving deltas: 100% (16107/16107), done.
    
    [root@9e1af72b3647 luajit2]# make -j8
    ==== Building LuaJIT 2.1.0-beta3 ====
    make -C src
    make[1]: Entering directory `/root/luajit2/src'
    CC        lj_init.o
    HOSTCC    host/minilua.o
    HOSTCC    host/buildvm_asm.o
    HOSTCC    host/buildvm_peobj.o
    HOSTCC    host/buildvm_lib.o
    HOSTCC    host/buildvm_fold.o
    CC        lj_assert.o
    CC        lj_gc.o
    CC        lj_char.o
    CC        lj_obj.o
    CC        lj_buf.o
    CC        lj_str.o
    CC        lj_tab.o
    CC        lj_func.o
    CC        lj_udata.o
    CC        lj_meta.o
    CC        lj_debug.o
    CC        lj_prng.o
    CC        lj_state.o
    CC        lj_vmevent.o
    CC        lj_vmmath.o
    CC        lj_strscan.o
    CC        lj_strfmt.o
    CC        lj_strfmt_num.o
    CC        lj_serialize.o
    CC        lj_api.o
    CC        lj_profile.o
    CC        lj_lex.o
    CC        lj_parse.o
    CC        lj_bcread.o
    CC        lj_bcwrite.o
    CC        lj_load.o
    CC        lj_ir.o
    CC        lj_opt_mem.o
    CC        lj_opt_narrow.o
    CC        lj_opt_dce.o
    CC        lj_opt_loop.o
    CC        lj_opt_split.o
    CC        lj_opt_sink.o
    CC        lj_mcode.o
    CC        lj_snap.o
    CC        lj_asm.o
    CC        lj_trace.o
    CC        lj_gdbjit.o
    CC        lj_ctype.o
    CC        lj_cdata.o
    CC        lj_cconv.o
    CC        lj_ccall.o
    CC        lj_ccallback.o
    CC        lj_carith.o
    CC        lj_clib.o
    CC        lj_cparse.o
    CC        lj_lib.o
    CC        lj_alloc.o
    CC        lib_aux.o
    CC        lib_package.o
    CC        lib_init.o
    CC        lj_str_hash.o
    CC        luajit.o
    HOSTLINK  host/minilua
    DYNASM    host/buildvm_arch.h
    HOSTCC    host/buildvm.o
    HOSTLINK  host/buildvm
    BUILDVM   lj_ffdef.h
    BUILDVM   lj_libdef.h
    BUILDVM   jit/vmdef.lua
    BUILDVM   lj_vm.S
    BUILDVM   lj_bcdef.h
    BUILDVM   lj_folddef.h
    BUILDVM   lj_recdef.h
    CC        lj_dispatch.o
    CC        lj_err.o
    CC        lj_crecord.o
    CC        lj_record.o
    CC        lib_base.o
    CC        lib_math.o
    CC        lib_bit.o
    CC        lib_string.o
    CC        lib_table.o
    CC        lib_io.o
    CC        lib_os.o
    CC        lib_debug.o
    CC        lib_jit.o
    CC        lib_ffi.o
    CC        lib_buffer.o
    ASM       lj_vm.o
    CC        lj_bc.o
    CC        lj_opt_fold.o
    CC        lj_ffrecord.o
    DYNLINK   libluajit.so
    AR        libluajit.a
    LINK      luajit
    OK        Successfully built LuaJIT
    make[1]: Leaving directory `/root/luajit2/src'
    ==== Successfully built LuaJIT 2.1.0-beta3 ====
    
    ## 检查引用的哪个分支,很重要
    [root@9e1af72b3647 luajit2]# git branch -a
    * v2.1-agentzh
      remotes/origin/HEAD -> origin/v2.1-agentzh
      remotes/origin/merge-20221205
      remotes/origin/merge1209
      remotes/origin/tab-order
      remotes/origin/v2.1-agentzh
    
    ## 安装 注意安装就好,因为之前编译的的时候指定了位置/usr/local/lib && /usr/local/include/luajit-2.1
    [root@ec7ea68b2fa3 luajit2]# make install
    ==== Installing LuaJIT 2.1.0-beta3 to /usr/local ====
    mkdir -p /usr/local/bin /usr/local/lib /usr/local/include/luajit-2.1 /usr/local/share/man/man1 /usr/local/lib/pkgconfig /usr/local/share/luajit-2.1.0-beta3/jit /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
    cd src && install -m 0755 luajit /usr/local/bin/luajit-2.1.0-beta3
    cd src && test -f libluajit.a && install -m 0644 libluajit.a /usr/local/lib/libluajit-5.1.a || :
    rm -f /usr/local/lib/libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so /usr/local/lib/libluajit-5.1.so.2
    cd src && test -f libluajit.so && \
      install -m 0755 libluajit.so /usr/local/lib/libluajit-5.1.so.2.1.0 && \
      ( ldconfig -n 2>/dev/null /usr/local/lib || : ) && \
      ln -sf libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so && \
      ln -sf libluajit-5.1.so.2.1.0 /usr/local/lib/libluajit-5.1.so.2 || :
    cd etc && install -m 0644 luajit.1 /usr/local/share/man/man1
    cd etc && sed -e "s|^prefix=.*|prefix=/usr/local|" -e "s|^multilib=.*|multilib=lib|" luajit.pc > luajit.pc.tmp && \
      install -m 0644 luajit.pc.tmp /usr/local/lib/pkgconfig/luajit.pc && \
      rm -f luajit.pc.tmp
    cd src && install -m 0644 lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h /usr/local/include/luajit-2.1
    cd src/jit && install -m 0644 bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua dis_mips64.lua dis_mips64el.lua vmdef.lua /usr/local/share/luajit-2.1.0-beta3/jit
    ln -sf luajit-2.1.0-beta3 /usr/local/bin/luajit
    ==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local ====

错误二

  1. jemalloc错误,第一次编译时植入了该模块
    [root@ec7ea68b2fa3 lib]# nginx -V
    nginx: error while loading shared libraries: libjemalloc.so.2: cannot open shared object file: No such file or directory
  2. 安装编译
    ## 解压
    [root@ec7ea68b2fa3 ~]# bzip2 -d jemalloc-5.3.0.tar.bz2 &&  tar -xvf jemalloc-5.3.0.tar
    
    ##编译
    [root@ec7ea68b2fa3 ~]# cd jemalloc-5.3.0 && ./configure
    
    ## 安装
    [root@ec7ea68b2fa3 jemalloc-5.3.0]# make -j4 && make install_bin install_include install_lib
    
    ## 刷新动态链接库
    [root@ec7ea68b2fa3 jemalloc-5.3.0]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf && ldconfig
    [root@ec7ea68b2fa3 jemalloc-5.3.0]# ldconfig -p | grep jemalloc
        libjemalloc.so.2 (libc6,x86-64) => /usr/local/lib/libjemalloc.so.2
        libjemalloc.so (libc6,x86-64) => /usr/local/lib/libjemalloc.so

错误三

  1. nginx运行环境缺失
    nginx: [alert] could not open error log file: open() "/var/log/nginx/nginx_error.log" failed (2: No such file or directory)
    2023/03/18 08:16:22 [emerg] 5721#5721: getpwnam("nginx") failed in /etc/tengine/nginx.conf:1
    nginx: configuration file /etc/tengine/nginx.conf test failed
    
    nginx: [emerg] getpwnam("nginx") failed in /etc/tengine/nginx.conf:1
    nginx: configuration file /etc/tengine/nginx.conf test failed
  2. 解决如下
    ## 创建主目录
    [root@ec7ea68b2fa3 ~]# mkdir -p /etc/tengine
    
    ## 创建日志目录
    [root@ec7ea68b2fa3 ~]# mkdir -p /var/log/nginx
    
    ## 创建运行用户
    [root@ec7ea68b2fa3 ~]# useradd nginx

错误四

  1. lua核心模块错误
    nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
        no field package.preload['resty.core']
        no file '/usr/local/lib/lua/resty/core.lua'
        no file '/opt/apps/waf/resty/core.lua'
        no file '/root/xuid/resty/core.lua'
        no file '/root/xuid/lib/resty/core.lua'
        no file '/usr/local/ngx_openresty/lualib/waf/lib/resty/core.lua'
        no file '/usr/local/tengine/script/thrid-party/resty/core.lua'
        no file '/usr/local/ngx_openresty/lualib/trace/resty/core.lua'
        no file '/usr/local/tengine/script/resty/core.lua'
        no file '/usr/local/tengine/script/thrid-party/resty/core.lua'
        no file '/opt/LuaJIT-2.1.0/lib/lua/resty/core.lua'
        no file '/resty/core.lua'
        no file '/srv/nginx/conf/lua/resty/core.lua'
        no file '/srv/nginx/conf/lua/lib/resty/core.lua'
        no file './resty/core.lua'
        no file '/usr/local/share/luajit-2.1.0-beta3/resty/core.lua'
        no file '/usr/local/share/lua/5.1 in /etc/tengine/nginx.conf:174

  2. lua-resty-core
    ## 克隆
    [root@ec7ea68b2fa3 ~]# git clone https://github.com/openresty/lua-resty-core.git
    Cloning into 'lua-resty-core'...
    remote: Enumerating objects: 4267, done.
    remote: Counting objects: 100% (509/509), done.
    remote: Compressing objects: 100% (281/281), done.
    remote: Total 4267 (delta 283), reused 420 (delta 228), pack-reused 3758
    Receiving objects: 100% (4267/4267), 1.13 MiB | 942.00 KiB/s, done.
    Resolving deltas: 100% (2511/2511), done.
    
    ## 确认分支 实际对应的是0.1.25
    [root@ec7ea68b2fa3 lua-resty-core]# git branch -a
    * master
    remotes/origin/0.1.23-x
    remotes/origin/0830
    remotes/origin/HEAD -> origin/master
    remotes/origin/balancer-by-lua-2
    remotes/origin/boringssl
    remotes/origin/ciphers
    remotes/origin/ec2
    remotes/origin/ffi_null
    remotes/origin/fix_bad_fd
    remotes/origin/keepalive
    remotes/origin/master
    remotes/origin/merge-20221205
    remotes/origin/pids
    remotes/origin/pipe
    remotes/origin/proxy_recreate_request
    remotes/origin/regex-cache-key
    remotes/origin/shdict-incr-init
    remotes/origin/shdict-list
    remotes/origin/ssl-cert-by-lua-2
    remotes/origin/ssl-session
    remotes/origin/ssl1.1.1i
    remotes/origin/truncated-retval
    remotes/origin/wins
    
    ## 安装
    [root@ec7ea68b2fa3 lua-resty-core]# make install PREFIX=/usr/local/openresty
    install -d /usr/local/openresty/lib/lua//resty/core/
    install -d /usr/local/openresty/lib/lua//ngx/
    install -d /usr/local/openresty/lib/lua//ngx/ssl
    install lib/resty/*.lua /usr/local/openresty/lib/lua//resty/
    install lib/resty/core/*.lua /usr/local/openresty/lib/lua//resty/core/
    install lib/ngx/*.lua /usr/local/openresty/lib/lua//ngx/
    install lib/ngx/ssl/*.lua /usr/local/openresty/lib/lua//ngx/ssl/
  3. lua-resty-lrucache
    ## 克隆
    [root@ec7ea68b2fa3 ~]# git clone https://github.com/openresty/lua-resty-lrucache.git
    Cloning into 'lua-resty-lrucache'...
    remote: Enumerating objects: 552, done.
    remote: Counting objects: 100% (56/56), done.
    remote: Compressing objects: 100% (30/30), done.
    remote: Total 552 (delta 23), reused 41 (delta 16), pack-reused 496
    Receiving objects: 100% (552/552), 114.82 KiB | 0 bytes/s, done.
    Resolving deltas: 100% (263/263), done.
    
    ## 切换分支
    [root@ec7ea68b2fa3 lua-resty-lrucache]# git branch -a
    * (detached from v0.13)
    master
    remotes/origin/HEAD -> origin/master
    remotes/origin/master
    remotes/origin/nyi
    
    ## 安装
    [root@ec7ea68b2fa3 lua-resty-lrucache]# make install PREFIX=/usr/local/openresty
    install -d //usr/local/openresty/lib/lua//resty/lrucache
    install lib/resty/*.lua //usr/local/openresty/lib/lua//resty/
    install lib/resty/lrucache/*.lua //usr/local/openresty/lib/lua//resty/lrucache/
  4. 修改nginx.conf
    lua_package_path '/usr/local/openresty/lib/lua/?.lua;;';

     

 

posted @ 2023-03-18 15:19  MacoPlus  阅读(586)  评论(0编辑  收藏  举报