正在加载

Elastic Agent 命令参考

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

限制

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

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

<hr>

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

  • version.txt - 版本信息

  • pre-config.yaml - 变量替换前的预配置

  • variables.yaml - 提供商提供的当前变量上下文

  • computed-config.yaml - 变量替换后的计算配置

  • components-expected.yaml - 从 computed-config.yaml 中得出的预期计算组件模型

  • components-actual.yaml - 运行时管理器报告的实际运行组件模型

  • state.yaml - 所有正在运行组件的当前状态信息

  • Components Directory - 每个正在运行组件的诊断信息

    • goroutine.txt - goroutine 转储
    • heap.txt - 活跃对象的内存分配
    • allocs.txt - 过去内存分配的采样
    • threadcreate.txt - 导致创建新 OS 线程的跟踪
    • block.txt - 导致同步原语阻塞的堆栈跟踪
    • mutex.txt - 争用互斥锁持有者的堆栈跟踪
    • Unit Directory - 如果给定单元提供了特定诊断信息,则会放在此处。

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

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

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

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

elastic-agent diagnostics

<hr>

将 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]
                     [--insecure ]
                     [--proxy-disabled]
                     [--proxy-header <strings>]
                     [--proxy-url <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>
逗号分隔的证书颁发机构哈希固定列表,用于证书验证。
--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。用于客户端 mTLS 连接的 Fleet Server 的 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 <string>
用于自签名 Elasticsearch 证书的证书颁发机构的 SHA-256 指纹 (哈希)。此指纹将用于验证 Fleet Server 和 Elastic Agent 启动的任何输入在通信中提供的自签名证书。在 Elasticsearch 中使用自签名证书时,此标志为必需。
--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,行为不可预测。

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

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

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

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

--proxy-disabled
禁用代理支持,包括环境变量。
--proxy-header <strings>
与 CONNECT 请求一起使用的代理请求头。
--proxy-url <string>
配置代理 URL。
--staging <string>
配置 Agent 从 staging build 下载工件。
--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

使用自定义 CA 启动 Elastic Agent 并运行 Fleet Server。此示例假设您已生成具有以下名称的证书

  • 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

<hr>

显示特定命令的帮助。

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

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

elastic-agent help enroll

<hr>

显示当前 Elastic Agent 配置。

如果未指定任何参数,则显示完整的 Elastic Agent 配置。

elastic-agent inspect [--help]
elastic-agent inspect components [--show-config]
                             [--show-spec]
                             [--help]
                             [id]
components

显示该组件的当前配置。此命令接受额外的标志

--show-config
用于显示所有单元中的配置。
--show-spec
用于获取组件的输入/输出运行时规范。
--help
显示 inspect 命令的帮助。

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

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

<hr>

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

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

elastic-agent privileged

<hr>

将 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 Agents

要安装 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>
逗号分隔的证书颁发机构哈希固定列表,用于证书验证。
--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。用于客户端 mTLS 连接的 Fleet Server 的 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 <string>
用于自签名 Elasticsearch 证书的证书颁发机构的 SHA-256 指纹 (哈希)。此指纹将用于验证 Fleet Server 和 Elastic Agent 启动的任何输入在通信中提供的自签名证书。在 Elasticsearch 中使用自签名证书时,此标志为必需。
--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,行为不可预测。

--header <strings>
与 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 模式下运行时,--privileged 选项允许您切换回以完整的管理权限运行 Agent。

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

--proxy-disabled
禁用代理支持,包括环境变量。
--proxy-header <strings>
与 CONNECT 请求一起使用的代理请求头。
--proxy-url <string>
配置代理 URL。
--staging <string>
配置 Agent 从 staging build 下载工件。
--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 模式。

[预览] 要在没有超级用户权限的情况下以预先存在的用户或组身份运行 Elastic Agent,例如在 Active Directory 帐户下,您可以指定要使用的用户或组以及密码。

例如

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

使用自定义 CA 启动 Elastic Agent 并运行 Fleet Server。此示例假设您已生成具有以下名称的证书

  • 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

<hr>

警告

此功能处于技术预览阶段,在未来版本中可能会更改或移除。Elastic 将努力修复所有问题,但技术预览阶段的功能不属于正式 GA 功能的支持 SLA 范围。

将 Elastic Agent 作为 OpenTelemetry Collector 运行。

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

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

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

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

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

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

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

<hr>

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

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

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

elastic-agent restart

<hr>

启动 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

<hr>

返回正在运行的 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

<hr>

从系统中永久卸载 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

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

在 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

<hr>

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

请注意,如果代理当前已注册包含 Elastic Defend 集成的策略,则阻止将正在运行的 Elastic Agent 更改为 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"

<hr>

将当前正在运行的 Elastic Agent 升级到指定版本。这仅应与在 standalone 模式下运行的 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。
--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

<hr>

显示正在运行的 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"

<hr>

显示 Elastic Agent 的版本。

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

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

elastic-agent version

<hr>

© . All rights reserved.