加载中

Elastic Agent 命令参考

Elastic Agent 提供了用于运行 Elastic Agent、管理 Fleet Server 和执行常见任务的命令。此处列出的命令适用于 Fleet 管理的独立 Elastic Agent。

限制

请注意运行 Elastic Agent 命令时的以下限制

  • 您可能需要以 root 用户(或 Windows 上的 Administrator)身份登录才能运行此处描述的命令。Elastic Agent 服务安装并运行后,请确保运行这些命令时不要在前面加上 ./,以免调用错误的二进制文件。
  • 不支持使用 Windows PowerShell ISE 运行 Elastic Agent 命令。
Fleet Server 命令选项

由于 Elastic Cloud Serverless 不支持自管理的 Fleet Server,因此在 Serverless 上无法使用配置 Fleet Server 的 elastic-agent enrollelastic-agent install 选项。

从 Elastic Agent 及其运行的组件/单元收集诊断信息。此命令会生成一个包含以下内容的归档文件:

  • version.txt - 版本信息
  • agent-info.yaml - 包含也发送到 Fleet 的 agent 本地元数据
  • pre-config.yaml - 变量替换前的预配置 - 这是来自磁盘或 Fleet 的 elastic-agent.yaml
  • otel.yaml - 与 otel 子命令一起使用的 OpenTelemetry 收集器配置文件
  • otel-merged.yaml - 提供给 OpenTelemetry 收集器的最终配置文件,包括任何内部生成的收集器组件
  • variables.yaml - 来自提供者的当前变量上下文
  • environment.yaml - Elastic Agent 进程可见的当前环境变量
  • computed-config.yaml - 变量替换后的配置
  • components-expected.yaml - 从 computed-config.yaml 计算出的预期组件模型
  • components-actual.yaml - 运行时管理器报告的实际运行组件模型
  • state.yaml - 所有运行组件的当前状态信息
  • 运行中的 elastic-agent 进程的 *.pprof.gz 文件,用于使用 go tool pprof 进行分析
    • goroutine.pprof.gz - goroutine 转储
    • heap.pprof.gz - 活对象的内存分配
    • allocs.pprof.gz - 过去内存分配的采样
    • threadcreate.pprof.gz - 导致创建新操作系统线程的跟踪
    • block.pprof.gz - 导致同步原语阻塞的堆栈跟踪
    • mutex.pprof.gz - 争用互斥体的持有者的堆栈跟踪
  • components/ 目录 - 每个运行组件进程的诊断信息
    • 通常每个输入-输出对对应一个目录,表示一个受监督的进程,包含
      • *.pprof.gz - 用于使用 go tool pprof 进行分析的配置文件;请参阅前面的描述
      • *_metrics.json - 从运行中的 Beat 进程捕获的度量快照
  • edot/ 目录 - Elastic 收集器诊断扩展的输出
    • otel-merged-actual.yaml - 运行中收集器的当前配置,应与前面描述的 otel-merged.yaml 文件匹配
    • *.profile.gz - 用于使用 go tool pprof 进行分析的配置文件;请参阅前面的描述

请注意,归档文件中凭据可能不会被编辑;它们可能以纯文本形式出现在归档文件中的配置或策略文件中。

此命令仅用于调试目的。归档文件的输出格式和结构可能会在不同版本之间发生变化。

elastic-agent diagnostics [--file <string>]
                          [--cpu-profile]
                          [--exclude-events]
                          [--help]
                          [global-flags]
		
--file
指定输出归档文件的名称。默认为 elastic-agent-diagnostics-<timestamp>.zip,其中时间戳是当前的 UTC 时间。
--help
显示 diagnostics 命令的帮助信息。
--cpu-profile
此外,对每个正在运行的组件运行 30 秒的 CPU 配置文件。这将为每个组件生成一个额外的 cpu.pprof 文件。
--p
--cpu-profile 的别名。
--exclude-events
从诊断归档文件中排除事件日志文件。

有关更多标志,请参阅 全局标志

elastic-agent diagnostics
		

将 Elastic Agent 注册到 Fleet。

使用此命令将 Elastic Agent 注册到 Fleet,而无需将 Agent 安装为服务。如果您从 DEB 或 RPM 包安装了 Elastic Agent,并计划使用 systemd 命令启动和管理服务,则需要这样做。此命令也适用于在安装 Elastic Agent 之前对其进行测试。

如果您已经安装了 Elastic Agent,请使用此命令修改 Elastic Agent 运行的设置。

提示

要注册 Elastic Agent 将其安装为服务,请改用 install 命令。将其安装为服务是最常见的场景。

我们建议您以 root 用户身份运行 enroll(或 install)命令,因为某些集成需要 root 权限才能收集敏感数据。此命令会覆盖 agent 目录中的 elastic-agent.yml 文件。

此命令包含设置 Fleet Server 的可选标志。

重要提示

此命令将 Elastic Agent 注册到 Fleet;它不会启动 Agent。要启动 Agent,可以 启动服务(如果存在),或使用 run 命令 从终端启动 Agent。

将 Elastic Agent 注册到 Fleet

elastic-agent enroll --url <string>
                     --enrollment-token <string>
                     [--ca-sha256 <string>]
                     [--certificate-authorities <string>]
                     [--daemon-timeout <duration>]
                     [--delay-enroll]
                     [--elastic-agent-cert <string>]
                     [--elastic-agent-cert-key <string>]
                     [--elastic-agent-cert-key-passphrase <string>]
                     [--force]
                     [--header <strings>]
                     [--help]
                     [--id <string>]
                     [--insecure ]
                     [--proxy-disabled]
                     [--proxy-header <strings>]
                     [--proxy-url <string>]
                     [--replace-token <string>]
                     [--staging <string>]
                     [--tag <string>]
                     [global-flags]
		

将 Elastic Agent 注册到 Fleet 并设置 Fleet Server

elastic-agent enroll --fleet-server-es <string>
                     --fleet-server-service-token <string>
                     [--fleet-server-service-token-path <string>]
                     [--ca-sha256 <string>]
                     [--certificate-authorities <string>]
                     [--daemon-timeout <duration>]
                     [--delay-enroll]
                     [--elastic-agent-cert <string>]
                     [--elastic-agent-cert-key <string>]
                     [--elastic-agent-cert-key-passphrase <string>]
                     [--fleet-server-cert <string>]
                     [--fleet-server-cert-key <string>]
                     [--fleet-server-cert-key-passphrase <string>]
                     [--fleet-server-client-auth <string>]
                     [--fleet-server-es-ca <string>]
                     [--fleet-server-es-ca-trusted-fingerprint <string>]
                     [--fleet-server-es-cert <string>]
                     [--fleet-server-es-cert-key <string>]
                     [--fleet-server-es-insecure]
                     [--fleet-server-host <string>]
                     [--fleet-server-policy <string>]
                     [--fleet-server-port <uint16>]
                     [--fleet-server-timeout <duration>]
                     [--force]
                     [--header <strings>]
                     [--help]
                     [--proxy-disabled]
                     [--proxy-header <strings>]
                     [--proxy-url <string>]
                     [--staging <string>]
                     [--tag <string>]
                     [--url <string>]
                     [global-flags]
		
  1. 如果未指定 fleet-server-cert* 标志,Elastic Agent 将自动生成一个包含机器主机名的自签名证书。使用自签名证书注册到 Fleet Server 的远程 Elastic Agent 必须指定 --insecure 标志。
  2. 在 Elasticsearch 中使用自签名证书时必需。
  3. 在使用自定义证书注册到 Fleet Server 时必需。URL 必须与用于生成 --fleet-server-cert 指定证书的 DNS 名称匹配。

有关自定义证书的更多信息,请参阅 为自管理 Fleet Server 配置 SSL/TLS

--ca-sha256 <string>
用于证书验证的逗号分隔的证书颁发机构哈希 PIN 列表。
--certificate-authorities <string>
用于服务器验证的逗号分隔的根证书列表。
--daemon-timeout <duration>
等待 Elastic Agent 守护进程的超时时间。
--delay-enroll
将注册延迟到 Elastic Agent 服务首次启动时进行。此设置在您不希望 Elastic Agent 在下次重启或手动启动服务之前进行注册时非常有用,例如,当您正在准备包含 Elastic Agent 的镜像或部署到网络访问可能无法立即获得的环境时。如果服务启动时 Fleet Server 无法访问,Elastic Agent 将无限期重试注册直到成功。
--elastic-agent-cert
用作 Elastic Agent 连接到 Fleet Server 的客户端证书的证书。
--elastic-agent-cert-key
用作 Elastic Agent 连接到 Fleet Server 的私钥。
--elastic-agent-cert-key-passphrase

包含 Elastic Agent 将用于连接到 Fleet Server 的互惠 TLS 私钥的密码短语的文件路径。该文件必须只包含密码短语的字符,没有换行符或额外的非打印字符。

仅当 --elastic-agent-cert-key 加密并需要密码短语才能使用时,才使用此选项。

--enrollment-token <string>
用于将 Elastic Agent 注册到 Fleet 的注册令牌。您可以对多个 Agent 使用相同的注册令牌。
--fleet-server-cert <string>
用于暴露的 Fleet Server HTTPS 端点的证书。
--fleet-server-cert-key <string>
用于暴露的 Fleet Server HTTPS 端点的私钥。
--fleet-server-cert-key-passphrase <string>
如果使用加密私钥,则为解密 Fleet Server 私钥的密码短语文件路径。
--fleet-server-client-auth <string>
noneoptionalrequired 之一。默认为 none。Fleet Server 用于客户端 mTLS 连接的 client_authentication 选项。如果指定 optionalrequired,则使用 --certificate-authorities 标志中指定的 CA 验证客户端证书。
--fleet-server-es <string>
当 Elastic Agent 启动时,启动一个 Fleet Server 进程,并连接到指定的 Elasticsearch URL。
--fleet-server-es-ca <string>
用于与 Elasticsearch 通信的证书颁发机构文件路径。这是使用 --fleet-server-es-ca-trusted-fingerprint 的替代方案。
--fleet-server-es-ca-trusted-fingerprint <string>
Elasticsearch 在 TLS 握手期间发送的证书链中存在的证书颁发机构的 SHA-256 指纹(哈希)。如果此证书在链中找到,它将被添加到受信任的 CA。这是使用 --fleet-server-es-ca 提供 CA 证书文件的替代方案。有关更多信息,请参阅 使用证书指纹
--fleet-server-es-cert
Fleet Server 连接到 Elasticsearch 时将使用的客户端证书路径。
--fleet-server-es-cert-key
Fleet Server 连接到 Elasticsearch 时将使用的私钥路径。
--fleet-server-es-insecure

允许 Fleet Server 在以下情况下连接到 Elasticsearch

  • 连接到 HTTP 服务器时。
  • 连接到 HTTPS 服务器且无法验证证书链时。内容已加密,但证书未经验证。

使用此标志时,证书验证将被禁用。

--fleet-server-host <string>
Fleet Server HTTP 绑定主机(覆盖策略)。
--fleet-server-policy <string>
在启动自管理 Fleet Server 时使用,以允许使用特定策略。
--fleet-server-port <uint16>
Fleet Server HTTP 绑定端口(覆盖策略)。
--fleet-server-service-token <string>
用于与 Elasticsearch 通信的服务令牌。与 --fleet-server-service-token-path 互斥。
--fleet-server-service-token-path <string>
用于与 Elasticsearch 通信的服务令牌文件。与 --fleet-server-service-token 互斥。
--fleet-server-timeout <duration>
等待 Fleet Server 准备好开始注册的超时时间。
--force

强制覆盖当前配置,不提示确认。此标志在使用自动化软件或脚本化部署时很有帮助。

注意

如果 Elastic Agent 已安装在主机上,使用 --force 可能会导致行为不可预测,Fleet 中出现重复的 Elastic Agent。

与 elasticsearch 通信中使用的请求头。
--help
显示 enroll 命令的帮助信息。
--id <string>

指定与 Fleet Server 注册 Elastic Agent 时使用的唯一标识符(Agent ID)。此设置在恢复以前注册的 Agent 或在无状态环境中 Agent 无法在重新部署之间保留注册数据时非常有用。

注意

如果具有相同 ID 的 Agent 已在 Fleet 中注册,则注册将失败,除非使用 --replace-token 标志提供了有效的替换令牌。

--insecure

允许 Elastic Agent 通过不安全连接连接到 Fleet Server。在以下情况下需要此设置

  • 连接到 HTTP 服务器时。API 密钥以明文形式发送。
  • 连接到 HTTPS 服务器且无法验证证书链时。内容已加密,但证书未经验证。
  • 使用 Elastic Agent 生成的自签名证书时。

我们强烈建议您使用安全连接。

--proxy-disabled
禁用代理支持,包括环境变量。
--proxy-header <strings>
用于 CONNECT 请求的代理头。
--proxy-url <string>
配置代理 URL。
--replace-token <string>

指定一个令牌,可用于在 Elastic Agent 注册到 Fleet Server 后替换它。首次使用特定 Agent ID 注册 Agent 时必须提供此令牌。随后,可以通过使用相同的 Agent ID 和替换令牌注册另一个 Agent 来替换该 Agent。一旦替换,原始 Agent 将无法再与 Fleet 通信。

注意

如果 Elastic Agent 在没有替换令牌的情况下注册,则不能被具有相同 ID 的另一个 Agent 替换。此机制通过要求替换令牌与 Fleet 中存储的哈希令牌匹配来防止意外或恶意接管。

--staging <string>
配置 Agent 从 staging 构建下载 artifacts。
--tag <string>

应用于 Fleet 管理的 Elastic Agent 的逗号分隔标签列表。您可以使用这些标签来过滤 Fleet 中的 Agent 列表。

注意

目前,无法删除或编辑现有标签。要更改标签,您必须取消注册 Elastic Agent,然后使用新标签重新注册。

--url <string>
用于将 Elastic Agent 注册到 Fleet 的 Fleet Server URL。

有关更多标志,请参阅 全局标志

将 Elastic Agent 注册到 Fleet

elastic-agent enroll \
  --url=https://cedd4e0e21e240b4s2bbbebdf1d6d52f.fleet.eu-west-1.aws.cld.elstc.co:443 \
  --enrollment-token=NEFmVllaa0JLRXhKebVKVTR5TTI6N2JaVlJpSGpScmV0ZUVnZVlRUExFQQ==
		

将 Elastic Agent 注册到 Fleet 并设置 Fleet Server

elastic-agent enroll --fleet-server-es=http://elasticsearch:9200 \
  --fleet-server-service-token=AbEAAdesYXN1abMvZmxlZXQtc2VldmVyL3Rva2VuLTE2MTkxMzg3MzIzMTg7dzEta0JDTmZUcGlDTjlwRmNVTjNVQQ \
  --fleet-server-policy=a35fd520-26f5-11ec-8bd9-3374690g57b6
		

使用 Fleet Server 启动 Elastic Agent(在自定义 CA 上运行)。此示例假定您已生成以下名称的证书

  • ca.crt: 根 CA 证书
  • fleet-server.crt: Fleet Server 证书
  • fleet-server.key: Fleet Server 私钥
  • elasticsearch-ca.crt: 用于连接到 Elasticsearch 的 CA 证书
elastic-agent enroll \
  --url=https://fleet-server:8220 \
  --fleet-server-es=https://elasticsearch:9200 \
  --fleet-server-service-token=AAEBAWVsYXm0aWMvZmxlZXQtc2XydmVyL3Rva2VuLTE2MjM4OTAztDU1OTQ6dllfVW1mYnFTVjJwTC2ZQ0EtVnVZQQ \
  --fleet-server-policy=a35fd520-26f5-11ec-8bd9-3374690g57b6 \
  --certificate-authorities=/path/to/ca.crt \
  --fleet-server-es-ca=/path/to/elasticsearch-ca.crt \
  --fleet-server-cert=/path/to/fleet-server.crt \
  --fleet-server-cert-key=/path/to/fleet-server.key \
  --fleet-server-port=8220
		

然后将另一个 Elastic Agent 注册到上一个示例中启动的 Fleet Server

elastic-agent enroll --url=https://fleet-server:8220 \
  --enrollment-token=NEFmVllaa0JLRXhKebVKVTR5TTI6N2JaVlJpSGpScmV0ZUVnZVlRUExFQQ== \
  --certificate-authorities=/path/to/ca.crt
		

使用特定的 Agent ID 和替换令牌替换已在 Fleet Server 中注册的 Elastic Agent

elastic-agent enroll \
  --url=https://fleet-server:8220 \
  --enrollment-token=ENROLLMENT_TOKEN_HASH \
  --id=MY_AGENT_ID \
  --replace-token=REPLACEMENT_TOKEN_HASH
		

显示特定命令的帮助信息。

elastic-agent help <command> [--help] [global-flags]
		
命令
命令名称。
--help
显示 help 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent help enroll
		

显示当前的 Elastic Agent 配置。使用此命令验证和排查 Elastic Agent 正在使用的配置,包括变量替换和计算出的组件模型。

如果未指定任何标志,该命令将显示完整的 Elastic Agent 配置。默认情况下,不执行变量替换,并显示原始配置。

使用 --variables 标志启用变量替换。仅当定义了 --variables 标志时,才使用第一组计算出的变量。这可能会阻止某些动态提供程序(如 Kubernetes 和 Docker)提供在给定更多时间后可能发现的所有可能变量。使用 --variables-wait 标志指定等待变量发现的时间量,然后再将变量用于配置。

使用 components 子命令查看组件模型。组件表示在 Elastic Agent 下运行的独立进程,例如 Filebeat 或 Endpoint Security。单元表示组件内的独立配置单元,例如 Filebeat 输入或 Metricbeat 模块。

elastic-agent inspect [--variables]
                      [--monitoring]
                      [--variables-wait <duration>]
                      [--help]
                      [global-flags]
elastic-agent inspect components [--show-config]
                                 [--show-spec]
                                 [--variables-wait <duration>]
                                 [--help]
                                 [<component_id>]
                                 [<component_id>/<unit_id>]
		
components

显示当前配置生成的组件模型。在计算组件模型时始终执行变量替换,并且无法禁用。默认情况下,仅使用第一组计算出的变量。使用 --variables-wait 标志可以为动态提供程序留出更多时间来发现变量。

此命令接受以下参数和标志

<component_id>
按 ID 选择特定组件。仅返回该组件及其所有单元。使用不带 ID 的 elastic-agent inspect components 查看所有可用的组件 ID。默认不显示单元的配置;使用 --show-config 显示。
<component_id>/<unit_id>
通过指定由斜杠分隔的组件 ID 和单元 ID 来选择组件内的特定单元。在此模式下,默认显示单元配置。
--show-config
显示所有单元的配置。默认情况下,单元配置是隐藏的,除非您使用 <component_id>/<unit_id> 格式选择特定单元。
--show-spec
显示组件的输入/输出运行时规范。默认情况下,运行时规范是隐藏的。
--variables-wait <duration>
在计算组件模型之前,等待指定的时间进行变量发现。这在使用 Kubernetes 或 Docker 等动态提供程序时很有用,这些提供程序可能需要额外的时间来发现所有可用变量。
--variables
渲染替换了变量的配置。未指定时,将显示不带变量替换的原始配置。
--monitoring
在输出中包含监控配置。此选项隐含 --variables,因为监控配置需要变量替换。
--variables-wait <duration>
在执行替换之前,等待指定的时间进行变量发现。这在使用 Kubernetes 或 Docker 等动态提供程序时很有用,这些提供程序可能需要额外的时间来发现所有可用变量。隐含 --variables。例如,--variables-wait 30s
--help
显示 inspect 命令的帮助信息。

有关更多标志,请参阅 全局标志

显示不带变量替换的原始 Elastic Agent 配置

elastic-agent inspect
		

显示替换了变量的配置

elastic-agent inspect --variables
		

显示替换了变量的配置,等待 30 秒以供动态提供程序发现变量

elastic-agent inspect --variables-wait 30s
		

显示包含监控设置的配置

elastic-agent inspect --monitoring
		

显示所有组件

elastic-agent inspect components
		

显示所有组件及其单元配置

elastic-agent inspect components --show-config
		

按 ID 显示特定组件

elastic-agent inspect components log-default
		

显示具有其运行时规范的特定组件

elastic-agent inspect components log-default --show-spec
		

显示组件内的特定单元

elastic-agent inspect components log-default/log-default
		

在计算组件之前,等待动态提供程序 30 秒

elastic-agent inspect components --variables-wait 30s
		

以完整超级用户特权运行 Elastic Agent。这是 Elastic Agent 的常见默认运行模式。当您在 unprivileged 模式下运行 Agent 后,privileged 命令允许您切换回以完整管理员特权运行 Agent。

有关详细信息,请参阅 在无管理权限下运行 Elastic Agent

elastic-agent privileged
		

将 Elastic Agent 永久安装在系统上,并使用系统的服务管理器对其进行管理。安装完成后,Agent 将自动启动。在 Linux(tar 包)上,此命令需要 systemd 等系统和服务管理器。

重要提示

如果您从 DEB 或 RPM 包安装了 Elastic Agent,则 install 命令将跳过安装本身,并作为 enroll 命令 的别名。使用 DEB 或 RPM 升级 Elastic Agent 后,Elastic Agent 服务需要重启。

您必须以 root 用户(或 Windows 上的 Administrator)身份运行此命令,才能将文件写入正确的位置。此命令会覆盖 agent 目录中的 elastic-agent.yml 文件。

运行此命令的语法因平台而异。此外,Agent 安装包有各种版本可用,允许您控制磁盘上的安装包大小和包含的组件集。有关特定于平台的示例和可用版本的详细信息,请参阅 安装 Elastic Agent

将 Elastic Agent 安装为服务,注册到 Fleet,并启动 elastic-agent 服务

elastic-agent install --url <string>
                      --enrollment-token <string>
                      [--base-path <string>]
                      [--ca-sha256 <string>]
                      [--certificate-authorities <string>]
                      [--daemon-timeout <duration>]
                      [--delay-enroll]
                      [--elastic-agent-cert <string>]
                      [--elastic-agent-cert-key <string>]
                      [--elastic-agent-cert-key-passphrase <string>]
                      [--force]
                      [--header <strings>]
                      [--help]
                      [--insecure ]
                      [--non-interactive]
                      [--privileged]
                      [--proxy-disabled]
                      [--proxy-header <strings>]
                      [--proxy-url <string>]
                      [--staging <string>]
                      [--tag <string>]
                      [--unprivileged]
                      [global-flags]
		

将 Elastic Agent 安装为服务,注册到 Fleet,并与 elastic-agent 服务一起启动一个 fleet-server 进程

elastic-agent install --fleet-server-es <string>
                      --fleet-server-service-token <string>
                      [--fleet-server-service-token-path <string>]
                      [--base-path <string>]
                      [--ca-sha256 <string>]
                      [--certificate-authorities <string>]
                      [--daemon-timeout <duration>]
                      [--delay-enroll]
                      [--elastic-agent-cert <string>]
                      [--elastic-agent-cert-key <string>]
                      [--elastic-agent-cert-key-passphrase <string>]
                      [--fleet-server-cert <string>]
                      [--fleet-server-cert-key <string>]
                      [--fleet-server-cert-key-passphrase <string>]
                      [--fleet-server-client-auth <string>]
                      [--fleet-server-es-ca <string>]
                      [--fleet-server-es-ca-trusted-fingerprint <string>]
                      [--fleet-server-es-cert <string>]
                      [--fleet-server-es-cert-key <string>]
                      [--fleet-server-es-insecure]
                      [--fleet-server-host <string>]
                      [--fleet-server-policy <string>]
                      [--fleet-server-port <uint16>]
                      [--fleet-server-timeout <duration>]
                      [--force]
                      [--header <strings>]
                      [--help]
                      [--non-interactive]
                      [--privileged]
                      [--proxy-disabled]
                      [--proxy-header <strings>]
                      [--proxy-url <string>]
                      [--staging <string>]
                      [--tag <string>]
                      [--unprivileged]
                      [--url <string>]
                      [global-flags]
		
  1. 如果未指定 fleet-server-cert* 标志,Elastic Agent 将自动生成一个包含机器主机名的自签名证书。使用自签名证书注册到 Fleet Server 的远程 Elastic Agent 必须指定 --insecure 标志。
  2. 在 Elasticsearch 侧使用自签名证书时必需。
  3. 在使用自定义证书注册到 Fleet Server 时必需。URL 必须与用于生成 --fleet-server-cert 指定证书的 DNS 名称匹配。

有关自定义证书的更多信息,请参阅 为自管理 Fleet Server 配置 SSL/TLS

--base-path <string>

将 Elastic Agent 安装在 默认 位置之外。指定安装的自定义基本路径。

目前 --base-path 选项不支持 Elastic Defend

--ca-sha256 <string>
用于证书验证的逗号分隔的证书颁发机构哈希 PIN 列表。
--certificate-authorities <string>
用于服务器验证的逗号分隔的根证书列表。
--daemon-timeout <duration>
等待 Elastic Agent 守护进程的超时时间。
--delay-enroll
将注册延迟到 Elastic Agent 服务首次启动时进行。此设置在您不希望 Elastic Agent 在下次重启或手动启动服务之前进行注册时非常有用,例如,当您正在准备包含 Elastic Agent 的镜像时。
--elastic-agent-cert
用作 Elastic Agent 连接到 Fleet Server 的客户端证书的证书。
--elastic-agent-cert-key
用作 Elastic Agent 连接到 Fleet Server 的私钥。
--elastic-agent-cert-key-passphrase

包含 Elastic Agent 将用于连接到 Fleet Server 的互惠 TLS 私钥的密码短语的文件路径。该文件必须只包含密码短语的字符,没有换行符或额外的非打印字符。

仅当 --elastic-agent-cert-key 加密并需要密码短语才能使用时,才使用此选项。

--enrollment-token <string>
用于将 Elastic Agent 注册到 Fleet 的注册令牌。您可以对多个 Agent 使用相同的注册令牌。
--fleet-server-cert <string>
用于暴露的 Fleet Server HTTPS 端点的证书。
--fleet-server-cert-key <string>
用于暴露的 Fleet Server HTTPS 端点的私钥。
--fleet-server-cert-key-passphrase <string>
如果使用加密私钥,则为解密 Fleet Server 私钥的密码短语文件路径。
--fleet-server-client-auth <string>
noneoptionalrequired 之一。默认为 none。Fleet Server 用于客户端 mTLS 连接的 client_authentication 选项。如果指定 optionalrequired,则使用 --certificate-authorities 标志中指定的 CA 验证客户端证书。
--fleet-server-es <string>
当 Elastic Agent 启动时,启动一个 Fleet Server 进程,并连接到指定的 Elasticsearch URL。
--fleet-server-es-ca <string>
用于与 Elasticsearch 通信的证书颁发机构文件路径。这是使用 --fleet-server-es-ca-trusted-fingerprint 的替代方案。
--fleet-server-es-ca-trusted-fingerprint <string>
Elasticsearch 在 TLS 握手期间发送的证书链中存在的证书颁发机构的 SHA-256 指纹(哈希)。如果此证书在链中找到,它将被添加到受信任的 CA。这是使用 --fleet-server-es-ca 提供 CA 证书文件的替代方案。有关更多信息,请参阅 使用证书指纹
--fleet-server-es-cert
Fleet Server 连接到 Elasticsearch 时将使用的客户端证书路径。
--fleet-server-es-cert-key
Fleet Server 连接到 Elasticsearch 时将使用的私钥路径。
--fleet-server-es-insecure

允许 Fleet Server 在以下情况下连接到 Elasticsearch

  • 连接到 HTTP 服务器时。
  • 连接到 HTTPS 服务器且无法验证证书链时。内容已加密,但证书未经验证。

使用此标志时,证书验证将被禁用。

--fleet-server-host <string>
Fleet Server HTTP 绑定主机(覆盖策略)。
--fleet-server-policy <string>
在启动自管理 Fleet Server 时使用,以允许使用特定策略。
--fleet-server-port <uint16>
Fleet Server HTTP 绑定端口(覆盖策略)。
--fleet-server-service-token <string>
用于与 Elasticsearch 通信的服务令牌。与 --fleet-server-service-token-path 互斥。
--fleet-server-service-token-path <string>
用于与 Elasticsearch 通信的服务令牌文件。与 --fleet-server-service-token 互斥。
--fleet-server-timeout <duration>
等待 Fleet Server 准备好开始注册的超时时间。
--force

强制覆盖当前配置,不提示确认。此标志在使用自动化软件或脚本化部署时很有帮助。

注意

如果 Elastic Agent 已安装在主机上,使用 --force 可能会导致行为不可预测,Fleet 中出现重复的 Elastic Agent。

与 elasticsearch 通信中使用的请求头。
--help
显示 enroll 命令的帮助信息。
--insecure

允许 Elastic Agent 通过不安全连接连接到 Fleet Server。在以下情况下需要此设置

  • 连接到 HTTP 服务器时。API 密钥以明文形式发送。
  • 连接到 HTTPS 服务器且无法验证证书链时。内容已加密,但证书未经验证。
  • 使用 Elastic Agent 生成的自签名证书时。

我们强烈建议您使用安全连接。

--non-interactive
以非交互模式安装 Elastic Agent。此标志在使用自动化软件或脚本化部署时很有帮助。如果 Elastic Agent 已安装在主机上,安装将终止。
--privileged
以完整超级用户特权运行 Elastic Agent。这是 Elastic Agent 的常见默认运行模式。当您在 unprivileged 模式下运行 Agent 后,--privileged 选项允许您切换回以完整管理特权运行 Agent。

有关详细信息,请参阅 --unprivileged 选项和 在无管理权限下运行 Elastic Agent

--proxy-disabled
禁用代理支持,包括环境变量。
--proxy-header <strings>
用于 CONNECT 请求的代理头。
--proxy-url <string>
配置代理 URL。
--staging <string>
配置 Agent 从 staging 构建下载 artifacts。
--tag <strings>

应用于 Fleet 管理的 Elastic Agent 的逗号分隔标签列表。您可以使用这些标签来过滤 Fleet 中的 Agent 列表。

注意

目前,无法删除或编辑现有标签。要更改标签,您必须取消注册 Elastic Agent,然后使用新标签重新注册。

--unprivileged

在没有完整超级用户特权的情况下运行 Elastic Agent。此选项适用于限制 Linux 或 macOS 系统上的 root 访问权限,或 Windows 系统上的 admin 访问权限的组织。有关在此模式下运行 Elastic Agent 的详细信息和限制,请参阅 在无管理权限下运行 Elastic Agent

如果 Agent 当前注册的策略包含需要管理访问权限的集成(例如 Elastic Defend 集成),则会阻止更改为 unprivileged 模式。

要以预先存在的用户或组(例如在 Active Directory 账户下)运行 Elastic Agent 而无需超级用户特权,您可以指定用户或组以及要使用的密码。

例如

elastic-agent install --unprivileged  --user="my.path\username" --password="mypassword"
		
elastic-agent install --unprivileged  --group="my.path\groupname" --password="mypassword"
		
--url <string>
用于将 Elastic Agent 注册到 Fleet 的 Fleet Server URL。

有关更多标志,请参阅 全局标志

将 Elastic Agent 安装为服务,注册到 Fleet,并启动 elastic-agent 服务

elastic-agent install \
  --url=https://cedd4e0e21e240b4s2bbbebdf1d6d52f.fleet.eu-west-1.aws.cld.elstc.co:443 \
  --enrollment-token=NEFmVllaa0JLRXhKebVKVTR5TTI6N2JaVlJpSGpScmV0ZUVnZVlRUExFQQ==
		

将 Elastic Agent 安装为服务,注册到 Fleet,并与 elastic-agent 服务一起启动一个 fleet-server 进程

elastic-agent install --fleet-server-es=http://elasticsearch:9200 \
  --fleet-server-service-token=AbEAAdesYXN1abMvZmxlZXQtc2VldmVyL3Rva2VuLTE2MTkxMzg3MzIzMTg7dzEta0JDTmZUcGlDTjlwRmNVTjNVQQ \
  --fleet-server-policy=a35fd620-26f6-11ec-8bd9-3374690f57b6
		

使用 Fleet Server 启动 Elastic Agent(在自定义 CA 上运行)。此示例假定您已生成以下名称的证书

  • ca.crt: 根 CA 证书
  • fleet-server.crt: Fleet Server 证书
  • fleet-server.key: Fleet Server 私钥
  • elasticsearch-ca.crt: 用于连接到 Elasticsearch 的 CA 证书
elastic-agent install \
  --url=https://fleet-server:8220 \
  --fleet-server-es=https://elasticsearch:9200 \
  --fleet-server-service-token=AAEBAWVsYXm0aWMvZmxlZXQtc2XydmVyL3Rva2VuLTE2MjM4OTAztDU1OTQ6dllfVW1mYnFTVjJwTC2ZQ0EtVnVZQQ \
  --fleet-server-policy=a35fd520-26f5-11ec-8bd9-3374690g57b6 \
  --certificate-authorities=/path/to/ca.crt \
  --fleet-server-es-ca=/path/to/elasticsearch-ca.crt \
  --fleet-server-cert=/path/to/fleet-server.crt \
  --fleet-server-cert-key=/path/to/fleet-server.key \
  --fleet-server-port=8220
		

然后安装另一个 Elastic Agent 并将其注册到上一个示例中启动的 Fleet Server

elastic-agent install --url=https://fleet-server:8220 \
  --enrollment-token=NEFmVllaa0JLRXhKebVKVTR5TTI6N2JaVlJpSGpScmV0ZUVnZVlRUExFQQ== \
  --certificate-authorities=/path/to/ca.crt
		

将 Elastic Agent 作为 OpenTelemetry 收集器的 Elastic 发行版 (EDOT Collector) 运行。

elastic-agent otel [flags]
elastic-agent otel [command]
		
注意

您也可以运行 ./otelcol 命令,该命令会调用 ./elastic-agent otel 并将任何参数传递给它。

validate
验证 OpenTelemetry 收集器配置,而不运行收集器。
--config=file:/path/to/first --config=file:path/to/second
配置文件位置。每个标志条目只能设置一个位置,例如 --config=file:/path/to/first --config=file:path/to/second
--feature-gates 标志
以逗号分隔的功能门标识符列表。以 - 为前缀表示禁用该功能。以 + 为前缀或不带前缀表示启用该功能。
-h, --help
获取 otel 子命令的帮助。使用 elastic-agent otel [command] --help 获取有关命令的更多信息。
--set string
设置任意组件配置属性。组件必须在配置文件中定义,并且该标志具有更高的优先级。数组配置属性将被覆盖,映射将被合并。例如,--set=processors::batch::timeout=2s

使用提供的 otel.yml 配置文件将 Elastic Agent 作为 EDOT Collector 运行。

./elastic-agent otel --config otel.yml
		

将 Elastic Agent EDOT Collector 配置中的默认详细程度设置从 detailed 更改为 normal

./elastic-agent otel --config otel.yml --set "exporters::debug::verbosity=normal"
		

重启当前运行的 Elastic Agent 守护进程。

elastic-agent restart [--help] [global-flags]
		
--help
显示 restart 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent restart
		

启动 elastic-agent 进程。

elastic-agent run [global-flags]
		

无论何时您在命令行上运行 elastic-agent,这些标志都有效。

-c <string>
要使用的配置文件。如果未指定,Elastic Agent 将使用 {path.config}/elastic-agent.yml
--e
记录到 stderr 并禁用 syslog/文件输出。
--environment <environmentVar>
Agent 将运行的环境。
--path.config <string>
Elastic Agent 查找其配置文件的目录。默认值因平台而异。
--path.home <string>

Elastic Agent 的根目录。path.home 决定了配置文件和数据目录的位置。

如果未指定,Elastic Agent 将使用当前工作目录。

--path.logs <string>
Elastic Agent 日志输出的路径。默认值因平台而异。
--v
将日志级别设置为 INFO。
elastic-agent run -c myagentconfig.yml
		

返回正在运行的 Elastic Agent 守护进程以及 Elastic Agent 中每个进程的当前状态。还会返回 Fleet Server 的最后已知状态。output 选项控制信息的详细程度和格式。

elastic-agent status [--output <string>]
                     [--help]
                     [global-flags]
		
--output <string>
human(默认)、fulljsonyaml 格式输出状态信息。当 Elastic Agent 处于 HEALTHY 状态时,human 返回有限的信息。如果任何组件或单元不处于 HEALTHY 状态,则会显示该组件或单元的完整详细信息。fulljsonyaml 始终返回完整的状态信息。组件映射到在 Elastic Agent 下运行的独立进程,例如 Filebeat 或 Endpoint Security。单元映射到该进程内的独立配置单元,例如 Filebeat 输入或 Metricbeat 模块。

当输出为 jsonyaml 时,状态码以数值形式返回。状态码可以使用下表进行映射

+

代码 状态
0 正在启动
1 正在配置
2 正常
3 降级
4 失败
5 正在停止
6 正在升级
7 回滚
--help
显示 status 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent status
		

从系统中永久卸载 Elastic Agent。

您必须以 root 用户(或 Windows 上的 Administrator)身份运行此命令才能删除文件。

重要提示

务必在 Elastic Agent 安装目录之外的目录中运行 uninstall 命令。

例如,在 Windows 系统上,安装位置是 C:\Program Files\Elastic\Agent。从 C:\Program Files\Elastic\tmp,甚至您的默认主目录运行卸载命令

C:\"Program Files"\Elastic\Agent\elastic-agent.exe uninstall
		
提示

您必须以 root 用户身份运行此命令。

sudo /Library/Elastic/Agent/elastic-agent uninstall
		
提示

您必须以 root 用户身份运行此命令。

sudo /opt/Elastic/Agent/elastic-agent uninstall
		

以管理员身份打开 PowerShell 提示符(右键单击 PowerShell 图标并选择 Run As Administrator)。

在 PowerShell 提示符下,运行

C:\"Program Files"\Elastic\Agent\elastic-agent.exe uninstall
		
elastic-agent uninstall [--force] [--help] [global-flags]
		
--force
卸载 Elastic Agent 且不提示确认。此标志在使用自动化软件或脚本化部署时很有帮助。
--skip-fleet-audit
跳过与 Fleet Server 的审计。
--help
显示 uninstall 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent uninstall
		

在没有完整超级用户特权的情况下运行 Elastic Agent。此选项适用于限制 Linux 或 macOS 系统上的 root 访问权限,或 Windows 系统上的 admin 访问权限的组织。有关在此模式下运行 Elastic Agent 的详细信息和限制,请参阅 在无管理权限下运行 Elastic Agent

如果正在运行的 Elastic Agent 当前已注册到包含 Elastic Defend 集成的策略,则会阻止将其更改为 unprivileged 模式。

要以预先存在的用户或组(例如在 Active Directory 账户下)运行 Elastic Agent 而无需超级用户特权,请添加 --user--group 参数以及 --password 参数。

无管理员权限运行 Elastic Agent

elastic-agent unprivileged
		

以预先存在的用户身份运行 Elastic Agent 而无需管理权限

elastic-agent unprivileged --user="my.pathl\username" --password="mypassword"
		

以预先存在的组身份运行 Elastic Agent 而无需管理权限

elastic-agent unprivileged --group="my.pathl\groupname" --password="mypassword"
		

将当前运行的 Elastic Agent 升级到指定版本。这仅适用于以独立模式运行的 Agent。注册到 Fleet 的 Agent 应该通过 Fleet 进行升级。

elastic-agent upgrade <version> [--source-uri <string>] [--help] [flags]
		
version
要升级到的 Elastic Agent 版本。
--source-uri <string>
下载新版本的源 URI。默认情况下,Elastic Agent 使用 Elastic Artifacts URL。
此处也接受文件路径。示例:file://<文件路径>
--skip-verify
跳过包验证过程。不建议使用此选项,因为它不安全。
--pgp-path <string>
使用本地存储的 PGP 密钥副本验证升级包。
--pgp-uri <string>
使用指定的在线 PGP 密钥验证升级包。
--help
显示 upgrade 命令的帮助信息。

有关使用 --skip-verify--pgp-path <string>--pgp-uri <string> 包验证选项的详细信息,请参阅 验证 Elastic Agent 包签名

有关更多标志,请参阅 全局标志

elastic-agent upgrade 7.10.1
		

显示正在运行的 Elastic Agent 的日志。

elastic-agent logs [--follow] [--number <int>] [--component <string>] [--no-color] [--help] [global-flags]
		
--follow-f
跟踪日志更新,直到命令中断(例如使用 Ctrl-C)。
--number <int>-n <int>
要打印的日志行数。如果启用了日志跟踪,则会影响初始输出。
--component <string>-C <string>
根据组件名称过滤日志。
--no-color
根据每个条目的日志级别禁用颜色。
--help
显示 logs 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent logs -n 100 -f -C "system/metrics-default"
		

显示 Elastic Agent 的版本。

elastic-agent version [--help] [global-flags]
		
--help
显示 version 命令的帮助信息。

有关更多标志,请参阅 全局标志

elastic-agent version
		

用于管理 Elastic Agent 注册表项的 Windows 特定子命令。这些命令需要管理员权限。

elastic-agent windows [command]
		
registry update
在 Windows 的“添加/删除程序”列表中创建或更新 Elastic Agent 条目,并配置注册表项访问控制列表 (ACL),以便无特权升级可以自动更新它。同时移除任何过时的 MSI 生成的条目。在从 9.4.0 之前的版本以无特权模式升级后,运行此命令一次。
registry remove
从 Windows 的“添加/删除程序”列表中移除 Elastic Agent 条目。当您需要手动清理注册表条目时,例如在故障排除期间或手动卸载之前,运行此命令。

在 Windows 的“添加/删除程序”列表中创建或更新 Elastic Agent 条目

elastic-agent windows registry update
		

从 Windows 的“添加/删除程序”列表中移除 Elastic Agent 条目

elastic-agent windows registry remove
		
© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.