🐈

ラズパイでfluent-bitをビルドする

2022/05/31に公開

fluent-bitのdockerイメージはarmv7はあるのですが、armv6であるラズパイゼロで動かしたいので、ソースコードからビルドしてみました。
ラズパイ3でビルドしてラズパイゼロに持っていきます。

基本的にこちらの手順に従います。
https://docs.fluentbit.io/manual/installation/sources/build-and-install

ソースコードの入手と展開

$ git clone https://github.com/fluent/fluent-bit.git
$ cd fluent-bit/
$ git tag
$ git checkout -b w1.9.3 v1.9.3

ビルド

$ vi CMakeLists.txt 

FLB_EXAMPLESFLB_SHARED_LIBNoに変更。

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9eca7a696..29857812f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,8 +83,8 @@ option(FLB_UTF8_ENCODER        "Build with UTF8 encoding support" Yes)
 option(FLB_PARSER              "Build with Parser support"    Yes)
 option(FLB_TLS                 "Build with SSL/TLS support"   Yes)
 option(FLB_BINARY              "Build executable binary"      Yes)
-option(FLB_EXAMPLES            "Build examples"               Yes)
-option(FLB_SHARED_LIB          "Build shared library"         Yes)
+option(FLB_EXAMPLES            "Build examples"                No)
+option(FLB_SHARED_LIB          "Build shared library"          No)
 option(FLB_VALGRIND            "Enable Valgrind support"       No)
 option(FLB_TRACE               "Enable trace mode"             No)
 option(FLB_TESTS_RUNTIME       "Enable runtime tests"          No)

必要なツールをインストール。

$ sudo apt install flex bison

ビルド。

$ cd build/
$ cmake ../
$ make
$ make -j`nproc`

しかし、最後に以下のようなリンクエラーが発生。

/usr/bin/ld: ../library/libcmetrics.a(cmt_atomic_gcc.c.o): in function `cmt_atomic_compare_exchange':
/home/koba/src/fluent-bit/lib/cmetrics/src/cmt_atomic_gcc.c:30: undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld: ../library/libcmetrics.a(cmt_atomic_gcc.c.o): in function `cmt_atomic_store':
/home/koba/src/fluent-bit/lib/cmetrics/src/cmt_atomic_gcc.c:36: undefined reference to `__atomic_store_8'
/usr/bin/ld: ../library/libcmetrics.a(cmt_atomic_gcc.c.o): in function `cmt_atomic_load':
/home/koba/src/fluent-bit/lib/cmetrics/src/cmt_atomic_gcc.c:41: undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/fluent-bit-bin.dir/build.make:341: bin/fluent-bit] Error 1
make[1]: *** [CMakeFiles/Makefile2:6733: src/CMakeFiles/fluent-bit-bin.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

リンクエラーのワークアラウンド

cmakeはよくわからないので、対症療法で。

$ vi src/CMakeFiles/fluent-bit-bin.dir/link.txt

末尾に -latomic を追加する。

$ make

これでビルドできた。

動作確認

$ cd bin/
$ ./fluent-bit --version
Fluent Bit v1.9.3
Git commit: 9eb4996b7d134227b568aefa5fa0f9ddd6a7b9ce
$ ldd ./fluent-bit 
	linux-vdso.so.1 (0x7efb6000)
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so (0x76ee2000)
	libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x76eb6000)
	libssl.so.1.1 => /lib/arm-linux-gnueabihf/libssl.so.1.1 (0x76e36000)
	libcrypto.so.1.1 => /lib/arm-linux-gnueabihf/libcrypto.so.1.1 (0x76c16000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x76ba7000)
	libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x76b93000)
	libatomic.so.1 => /lib/arm-linux-gnueabihf/libatomic.so.1 (0x76b7a000)
	libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x76b4d000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x769f9000)
	/lib/ld-linux-armhf.so.3 (0x76ef7000)
$ ./fluent-bit -i cpu -o stdout
Fluent Bit v1.9.3
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/05/31 22:41:32] [ info] [fluent bit] version=1.9.3, commit=9eb4996b7d, pid=32015
[2022/05/31 22:41:32] [ info] [storage] version=1.2.0, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/05/31 22:41:32] [ info] [cmetrics] version=0.3.1
[2022/05/31 22:41:32] [ info] [sp] stream processor started
[2022/05/31 22:41:32] [ info] [output:stdout:stdout.0] worker #0 started
[0] cpu.0: [1654004493.083842553, {"cpu_p"=>0.000000, "user_p"=>0.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
[0] cpu.0: [1654004494.083656147, {"cpu_p"=>0.000000, "user_p"=>0.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
[0] cpu.0: [1654004495.083669537, {"cpu_p"=>0.000000, "user_p"=>0.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
[0] cpu.0: [1654004496.083718536, {"cpu_p"=>0.000000, "user_p"=>0.000000, "system_p"=>0.000000, "cpu0.p_cpu"=>0.000000, "cpu0.p_user"=>0.000000, "cpu0.p_system"=>0.000000, "cpu1.p_cpu"=>0.000000, "cpu1.p_user"=>0.000000, "cpu1.p_system"=>0.000000, "cpu2.p_cpu"=>0.000000, "cpu2.p_user"=>0.000000, "cpu2.p_system"=>0.000000, "cpu3.p_cpu"=>0.000000, "cpu3.p_user"=>0.000000, "cpu3.p_system"=>0.000000}]
$ sudo cp ./fluent-bit /usr/local/bin

fluent-bitをラズパイゼロに持っていって、同様に動くことを確認。

おまけ

ラズパイゼロでlddでは以下のような出力になる。

$ ldd ./fluent-bit 
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6f81000)
	libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6f55000)
	libssl.so.1.1 => /lib/arm-linux-gnueabihf/libssl.so.1.1 (0xb6ed5000)
	libcrypto.so.1.1 => /lib/arm-linux-gnueabihf/libcrypto.so.1.1 (0xb6cb5000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6c46000)
	libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6c32000)
	libatomic.so.1 => /lib/arm-linux-gnueabihf/libatomic.so.1 (0xb6c19000)
	libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6bec000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6a98000)
	/lib/ld-linux-armhf.so.3 (0xb6f94000)
	/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so => /usr/lib/arm-linux-gnueabihf/libarmmem-v6l.so (0xb6f81000)

${PLATFORM}のところがラズパイ3だとv7l、ラズパイゼロではv6lに展開される。

Discussion