有无懂哥试过静态编译或者尽可能静态编译 openresty - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
guanzhangzhang
V2EX    Linux

有无懂哥试过静态编译或者尽可能静态编译 openresty

  •  
  •   guanzhangzhang
    zhangguanzhang 2022-11-08 20:17:04 +08:00 3083 次点击
    这是一个创建于 1144 天前的主题,其中的信息可能已经有所发展或是发生改变。
    FROM alpine AS build ARG VERSION=openresty-1.21.4.1 ARG ADD_MODULE="\ https://github.com/openresty/array-var-nginx-module/archive/refs/tags/v0.05.tar.gz \ https://github.com/openresty/echo-nginx-module/archive/refs/tags/v0.63.tar.gz \ https://github.com/openresty/encrypted-session-nginx-module/archive/refs/tags/v0.09.tar.gz \ https://github.com/calio/form-input-nginx-module/archive/refs/tags/v0.12.tar.gz \ https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v0.34.tar.gz \ https://github.com/openresty/memc-nginx-module/archive/refs/tags/v0.19.tar.gz \ https://github.com/FRiCKLE/ngx_coolkit/archive/refs/tags/0.2.tar.gz \ https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.2.tar.gz \ https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.22.tar.gz \ https://github.com/openresty/lua-upstream-nginx-module/archive/refs/tags/v0.07.tar.gz \ https://github.com/openresty/stream-lua-nginx-module/archive/refs/tags/v0.0.11.tar.gz \ https://github.com/openresty/rds-csv-nginx-module/archive/refs/tags/v0.09.tar.gz \ https://github.com/openresty/rds-json-nginx-module/archive/refs/tags/v0.15.tar.gz \ https://github.com/openresty/redis2-nginx-module/archive/refs/tags/v0.15.tar.gz \ https://github.com/openresty/set-misc-nginx-module/archive/refs/tags/v0.33.tar.gz \ https://github.com/openresty/srcache-nginx-module/archive/refs/tags/v0.32.tar.gz \ https://github.com/openresty/xss-nginx-module/archive/refs/tags/v0.06.tar.gz \ " WORKDIR /opt RUN if [ -f /etc/apk/repositories ];then sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; fi && \ if [ -f /etc/apt/sources.list ];then sed -ri 's/(deb|security).debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; fi && \ if [ ! -e /etc/nsswitch.conf ];then echo 'hosts: files dns myhostname' > /etc/nsswitch.conf; fi && \ apk add --no-cache --virtual .build-deps \ gcc \ libc-dev \ make \ openssl-dev \ pcre-dev \ libxml2-dev libxslt-dev \ libjpeg-turbo-static libpng-static libwebp-static zlib-dev \ openssl-libs-static zlib-static \ linux-headers \ libxslt-dev \ gd-dev \ geoip-dev \ perl-dev \ libedit-dev \ bash \ alpine-sdk \ findutils RUN for m in ${ADD_MODULE};do \ wget $m -O-| tar zxf -; \ done && \ wget https://openresty.org/download/${VERSION}.tar.gz && tar zxf ${VERSION}.tar.gz && \ rm -f ${VERSION}.tar.gz RUN cd ${VERSION} && \ ./configure \ $(ls -l ../ | awk -vN=${VERSION} '$NF!=N&&$1~/^d/&&$NF~/.+?\.[0-9]+$/{printf " --add-module=../%s ",$NF}') \ --prefix=/usr/local/openresty/nginx \ --with-compat \ --with-file-aio \ --with-threads \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_geoip_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ #加不上 --with-http_image_filter_module \ --with-http_mp4_module \ --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 \ --with-mail \ --with-mail_ssl_module \ --with-pcre \ --with-pcre-jit \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-cc-opt='-static -s' \ --with-ld-opt=-static RUN cd ${VERSION} && \ mkdir /install_root && \ make 

    上面是我的步骤,但是 make 的时候 ld 报错,最终需求是如果不是静态编译,那把整个目录拷贝到另一个机器上也可以运行,信创的适配要求大概这样。

    nginx 静态编译没问题,但是 openresty module 挺多的,有没有老哥知道怎么尽可能的静态编译

    第 1 条附言    2022-11-09 16:26:20 +08:00
    1. 运行的系统可能是 glibc 的,也可能是 musl 的,所以需要是直接把 openresty 目录拷贝上去就能运行
    2. 并不是容器,只是我现在是容器里编译的,和 docker 无关,主要是要最终的构建产物
    3. openresty 官方的 Dockerfile 我看过了

    感谢大家,不过我打算放弃了,打算 musl 的搞个 musl 的 openresty 版本,glibc 的直接扣官方低 glibc 版本的 openresty docker 镜像文件了
    6 条回复    2022-11-09 16:27:28 +08:00
    alexsunxl
        1
    alexsunxl  
       2022-11-09 10:46:26 +08:00
    外面编译好了 ADD 进去呗
    lixile
        2
    lixile  
       2022-11-09 11:04:45 +08:00
    1 、静态编译需要看生成的 makefile configure 不一定原生写好了支持这中编译方式
    2 、移动后可行 需保持通操作系统 (主要是 libstdc++ ld libc ) 可以通过设置 RPATH 实现
    注意不是 RUNPATH ! 不是 RUNPATH ! 不是 RUNPATH !
    ysc3839
        3
    ysc3839  
       2022-11-09 11:40:57 +08:00
    首先避免使用系统包管理安装依赖,比如你给的这段命令中 apk add *-dev 都不能用,需要自己编译对应库的静态版本。其次 glibc 等没法静态链接的库尽量用低版本的环境编译,glibc 是新版本库兼容旧版本的程序的。
    boshi
        4
    boshi  
       2022-11-09 11:59:16 +08:00
    openresty 编译出错大多是版本依赖问题吧。昨天刚编译一个。
    ```
    /configure --prefix=/usr/local/openresty --with-ld-opt='-ljemalloc -Wl,-u,pcre_version' --user=www --group=www --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.1.1o --with-pcre=../pcre-8.45 --with-pcre-jit --add-module=../ngx_http_geoip2_module-3.4 --add-module=../nginx-rtmp-module-1.2.2 --add-module=../ngx_http_substitutions_filter_module --with-stream_ssl_module --with-stream_ssl_preread_module -j4
    ```
    atx
        5
    atx  
       2022-11-09 12:55:47 +08:00
    guanzhangzhang
        6
    guanzhangzhang  
    OP
       2022-11-09 16:27:28 +08:00
    @boshi 我这些模块列表是看官方镜像-V 查到的,所以加了这些模块,不过放弃了,打算扣官方的镜像试试
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2613 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 32ms UTC 01:48 PVG 09:48 LAX 17:48 JFK 20:48
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86