otelやhttp2,3モジュール付きnginxをビルド
動的モジュールにして後付けではなく、モジュールを組み込んだnginxをビルドする
そのため、nginxのビルド前のauto/configureする前にnginx-otelを用意しておく必要がある
nginxをビルド
code:shell
sudo apt update && sudo apt install -y gcc make zlib1g-dev cmake build-essential libssl-dev zlib1g-dev libpcre3-dev pkg-config libc-ares-dev libre2-dev
code:shell
git clone --branch release-1.28.0 --depth 1 https://github.com/nginx/nginx.git
cd nginx
logの位置などは全部APTで入れたやつと同じにしておく
sbinパスだけnginx-otelとしておく
code:nginxリポジトリルート.sh
time auto/configure \
--prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx-otel \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/run/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--modules-path=/usr/lib/nginx/modules \
--with-compat \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--without-http_autoindex_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_auth_basic_module \
--without-http_mirror_module \
--without-http_referer_module
code:時間.sh
real 0m3.797s
user 0m2.156s
sys 0m1.713s
3秒くらい
ビルド
code:shell
time make -j$(nproc)
...
real 0m5.882s
user 0m17.649s
sys 0m5.303s
nproc 4 の時、6秒くらい
code:shell
objs/nginx -v
nginx version: nginx/1.28.0
ls -lh objs/nginx
-rwxrwxr-x 1 isucon isucon 4.7M Oct 31 17:38 objs/nginx
otel moduleをビルド
code:shell
cd ~
git clone --branch v0.1.2 --depth 1 https://github.com/nginxinc/nginx-otel.git
mkdir nginx-otel/build && cd nginx-otel/build
サイズ優先でやる(デバッグ情報を取り除く)
code:shell
time cmake -DNGX_OTEL_NGINX_BUILD_DIR=~/nginx/objs -DCMAKE_BUILD_TYPE=MinSizeRel ..
code:出力.sh
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
...
Building with nostd types...
-- Configuring done (63.6s)
-- Generating done (0.3s)
-- Build files have been written to: /home/isucon/nginx-otel/build
real 1m3.984s
user 0m33.726s
sys 0m5.002s
1分くらい
make
code:shell
time make -j$(nproc)
code:出力.sh
...
100% Building CXX object CMakeFiles/ngx_otel_module.dir/opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.cc.o
100% Linking CXX shared module ngx_otel_module.so
100% Built target ngx_otel_module
real 2m36.301s
user 8m49.082s
sys 1m26.073s
2分くらい
さらにデバッグに必要なシンボルを減らす
code:不要なシンボル削除.sh
cp ngx_otel_module.so ngx_otel_module.so.backup
strip --strip-unneeded ngx_otel_module.so
code:確認.sh
ls -lh ngx_otel_module*
-rwxrwxr-x 1 isucon isucon 2.9M Oct 31 18:39 ngx_otel_module.so
-rwxrwxr-x 1 isucon isucon 4.6M Oct 31 18:38 ngx_otel_module.so.backup
3MBくらいになる
固める
code:shell
cd ~
mkdir -p ~/nginx-otel-dist/sbin && mkdir ~/nginx-otel-dist/modules
cp ~/nginx/objs/nginx ~/nginx-otel-dist/sbin/
cp ~/nginx-otel/build/ngx_otel_module.so ~/nginx-otel-dist/modules/