【问题标题】:sh: ./elastic-agent: not found when trying to run the elastic agent on Alpine Linuxsh: ./elastic-agent: 尝试在 Alpine Linux 上运行弹性代理时未找到
【发布时间】:2021-12-29 14:54:19
【问题描述】:

我正在尝试在运行另一个服务的 docker 容器上配置弹性代理。该容器基于 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 主机上运行,​​这可以通过内核版本或软件包 repos 看出:

# 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

看起来二进制文件可以正确链接到库:

# 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 可以阻止二进制文件在某些​​条件下启动吗?

感谢您的帮助!

【问题讨论】:

  • 有趣——你已经介绍了最明显的情况(缺少动态库是我看到人们在调查这种情况时跳过的最常见的事情)。 strace -f 是否提供更多详细信息?
  • @CharlesDuffy 感谢您的帮助! strace -f 似乎也没有多大帮助,我已将其输出添加到问题中

标签: docker elastic-stack alpine


【解决方案1】:

问题似乎是你下载的elastic-agent的编译版本需要libc。 Alpine linux 使用 muslc。

可以使用https://stackoverflow.com/a/38433396/5666087 在 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

【讨论】:

  • 解决了,谢谢!我今天学到了关于 Linux 基础库的另一件事。 ? 另一种选择是安装 libc6-compat 软件包,正如您链接的问题中的另一个答案所建议的那样
猜你喜欢
  • 2022-01-07
  • 2018-04-26
  • 2017-03-08
  • 2012-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-04
相关资源
最近更新 更多