sh: ./elastic-agent: 尝试 运行 Alpine Linux 上的弹性代理时未找到
sh: ./elastic-agent: not found when trying to run the elastic agent on Alpine Linux
我正在尝试在 docker 容器 运行 另一个服务上配置 Elastic Agent。该容器基于 Alpine Linux,但我无法 运行 下载并解压缩代理后的 elastic-agent 代理命令:它抱怨“找不到”文件,而该文件实际上存在!
这是一个最小的可复制示例
docker run --rm -it alpine sh
# cd /opt
# wget https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.14.2-linux-x86_64.tar.gz
# tar xvf elastic-agent-7.14.2-linux-x86_64.tar.gz
# cd elastic-agent-7.14.2-linux-x86_64/
# ./elastic-agent
sh: ./elastic-agent: not found
# ls -la
total 8452
drwxr-xr-x 3 root root 4096 Nov 18 17:38 .
drwxr-xr-x 1 root root 4096 Nov 18 17:38 ..
-rw-r--r-- 1 root root 41 Sep 15 17:00 .build_hash.txt
-rw-r--r-- 1 root root 41 Sep 15 17:00 .elastic-agent.active.commit
-rw-r--r-- 1 root root 13675 Sep 15 16:54 LICENSE.txt
-rw-r--r-- 1 root root 8586842 Sep 15 16:54 NOTICE.txt
-rw-r--r-- 1 root root 866 Sep 15 17:00 README.md
drwxr-xr-x 3 root root 4096 Nov 18 17:38 data
lrwxrwxrwx 1 root root 39 Nov 18 17:38 elastic-agent -> data/elastic-agent-574c21/elastic-agent
-rw-r--r-- 1 root root 9020 Sep 15 16:55 elastic-agent.reference.yml
-rw------- 1 root root 9017 Sep 15 16:55 elastic-agent.yml
# ./data/elastic-agent-574c21/elastic-agent
sh: ./data/elastic-agent-574c21/elastic-agent: not found
我运行正在 x86_64 主机上运行,可以从内核版本或软件包存储库中看出:
# uname -a
Linux 59ae07b0dca8 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 Linux
# apk update
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
v3.14.3-14-g9234faeb0d [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
v3.14.3-12-g13e0706e2c [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
OK: 14942 distinct packages available
看来二进制文件可以 link 正确地添加到库中:
# ldd ./data/elastic-agent-574c21/elastic-agent
/lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
也有权限执行
# ls -la /usr/local/bin/elastic-agent-7.14.2-linux-x86_64/data/elastic-agent-574c21/
total 57244
drwxr-xr-x 3 root root 4096 Nov 18 17:38 .
drwxr-xr-x 3 root root 4096 Nov 18 17:38 ..
drwxr-xr-x 2 root root 4096 Nov 18 17:38 downloads
-rwxr-xr-x 1 root root 58603536 Sep 15 17:00 elastic-agent
strace
似乎也无济于事
# strace -f ./elastic-agent
execve("./elastic-agent", ["./elastic-agent"], 0x7fff9e17bee8 /* 7 vars */) = -1 ENOENT (No such file or directory)
strace: exec: No such file or directory
+++ exited with 1 +++
我错过了什么吗? Alpine 能否在某些情况下阻止二进制文件启动?
感谢您的帮助!
问题好像是您下载的elastic-agent
的编译版本需要libc。 Alpine linux 使用 muslc.
可以使用 在 alpine 中安装 glibc。然后 elastic-agent
似乎起作用了。
FROM alpine
WORKDIR /opt
RUN wget -qO - https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.14.2-linux-x86_64.tar.gz \
| tar xz
# Add glibc
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
&& apk add glibc-2.28-r0.apk \
&& rm glibc-2.28-r0.apk
和运行生成的图像(假设它被命名为elastic
):
docker run --rm -it elastic /opt/elastic-agent-7.14.2-linux-x86_64/elastic-agent
我正在尝试在 docker 容器 运行 另一个服务上配置 Elastic Agent。该容器基于 Alpine Linux,但我无法 运行 下载并解压缩代理后的 elastic-agent 代理命令:它抱怨“找不到”文件,而该文件实际上存在!
这是一个最小的可复制示例
docker run --rm -it alpine sh
# cd /opt
# wget https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.14.2-linux-x86_64.tar.gz
# tar xvf elastic-agent-7.14.2-linux-x86_64.tar.gz
# cd elastic-agent-7.14.2-linux-x86_64/
# ./elastic-agent
sh: ./elastic-agent: not found
# ls -la
total 8452
drwxr-xr-x 3 root root 4096 Nov 18 17:38 .
drwxr-xr-x 1 root root 4096 Nov 18 17:38 ..
-rw-r--r-- 1 root root 41 Sep 15 17:00 .build_hash.txt
-rw-r--r-- 1 root root 41 Sep 15 17:00 .elastic-agent.active.commit
-rw-r--r-- 1 root root 13675 Sep 15 16:54 LICENSE.txt
-rw-r--r-- 1 root root 8586842 Sep 15 16:54 NOTICE.txt
-rw-r--r-- 1 root root 866 Sep 15 17:00 README.md
drwxr-xr-x 3 root root 4096 Nov 18 17:38 data
lrwxrwxrwx 1 root root 39 Nov 18 17:38 elastic-agent -> data/elastic-agent-574c21/elastic-agent
-rw-r--r-- 1 root root 9020 Sep 15 16:55 elastic-agent.reference.yml
-rw------- 1 root root 9017 Sep 15 16:55 elastic-agent.yml
# ./data/elastic-agent-574c21/elastic-agent
sh: ./data/elastic-agent-574c21/elastic-agent: not found
我运行正在 x86_64 主机上运行,可以从内核版本或软件包存储库中看出:
# uname -a
Linux 59ae07b0dca8 5.10.47-linuxkit #1 SMP Sat Jul 3 21:51:47 UTC 2021 x86_64 Linux
# apk update
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
v3.14.3-14-g9234faeb0d [https://dl-cdn.alpinelinux.org/alpine/v3.14/main]
v3.14.3-12-g13e0706e2c [https://dl-cdn.alpinelinux.org/alpine/v3.14/community]
OK: 14942 distinct packages available
看来二进制文件可以 link 正确地添加到库中:
# ldd ./data/elastic-agent-574c21/elastic-agent
/lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f1868c2f000)
也有权限执行
# ls -la /usr/local/bin/elastic-agent-7.14.2-linux-x86_64/data/elastic-agent-574c21/
total 57244
drwxr-xr-x 3 root root 4096 Nov 18 17:38 .
drwxr-xr-x 3 root root 4096 Nov 18 17:38 ..
drwxr-xr-x 2 root root 4096 Nov 18 17:38 downloads
-rwxr-xr-x 1 root root 58603536 Sep 15 17:00 elastic-agent
strace
似乎也无济于事
# strace -f ./elastic-agent
execve("./elastic-agent", ["./elastic-agent"], 0x7fff9e17bee8 /* 7 vars */) = -1 ENOENT (No such file or directory)
strace: exec: No such file or directory
+++ exited with 1 +++
我错过了什么吗? Alpine 能否在某些情况下阻止二进制文件启动?
感谢您的帮助!
问题好像是您下载的elastic-agent
的编译版本需要libc。 Alpine linux 使用 muslc.
可以使用 在 alpine 中安装 glibc。然后 elastic-agent
似乎起作用了。
FROM alpine
WORKDIR /opt
RUN wget -qO - https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-7.14.2-linux-x86_64.tar.gz \
| tar xz
# Add glibc
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
&& apk add glibc-2.28-r0.apk \
&& rm glibc-2.28-r0.apk
和运行生成的图像(假设它被命名为elastic
):
docker run --rm -it elastic /opt/elastic-agent-7.14.2-linux-x86_64/elastic-agent