加载中

使用 Logstash 迁移 Elasticsearch 数据

Logstash 是一个数据采集引擎,它使用庞大的插件生态系统来从各种源采集、处理数据并将其转发到各种目标。在此,我们重点介绍如何使用 Elasticsearch 输入插件从您的 Elastic Cloud Hosted 部署中读取数据,并使用 Elasticsearch 输出插件将数据写入您的 Elastic Cloud Serverless 项目。

熟悉 Elastic Cloud Hosted、Elasticsearch 和 Logstash 会有所帮助,但并非必需。

基础迁移

本指南重点介绍如何将静态数据从 Elastic Cloud Hosted 部署迁移到 Elastic Cloud Serverless 项目。

Elasticsearch 输入插件提供了其他配置选项,可以支持更高级的用例以及在其他部署类型之间进行迁移。关于这些选项的更多信息,请参阅本主题末尾部分。

  • 包含待迁移数据的 Elastic Cloud Hosted 部署
  • 已配置并运行的 Elastic Cloud Serverless 项目
  • 本地计算机或服务器上已安装 Logstash
  • 用于与两个部署进行身份验证的 Logstash 格式 API 密钥
重要提示

Kibana 资产必须使用 Kibana 导出/导入 API 单独迁移或手动重新创建。模板、数据流定义和 ILM 策略必须在开始数据迁移之前就绪。

可视化组件(如仪表板和可视化图表)可以在迁移数据后进行迁移。

创建一个新的 Logstash 管道配置文件 (migration.conf),使用 Elasticsearch 输入Elasticsearch 输出

  • 输入 (input) 从您的 Elastic Cloud Hosted 读取数据。
  • 输出 (output) 将数据写入您的 Elastic Cloud Serverless 项目。
input {
  elasticsearch {
    cloud_id => "<HOSTED_DEPLOYMENT_CLOUD_ID>"
    api_key  => "<HOSTED_API_KEY>"
    index    => "index_pattern*"
    docinfo  => true                             # Includes metadata about each document, such as its original index name or doc ID. This metadata can be used to preserve index information on the destination cluster.
  }
}
		
  1. 使用云 ID (Cloud ID) 将 Logstash 连接到您的 Elastic Cloud Hosted 部署。
  2. 用于验证连接的 API 密钥。
  3. 索引或索引模式(例如 logs-,metrics-)。
提示

要同时迁移多个索引,请在索引名称中使用通配符。例如,index => "logs-*" 会迁移所有以 logs- 开头的索引。

output {
  elasticsearch {
    hosts       => [ "https://<SERVERLESS_HOST_URL>:443" ]
    api_key     => "<SERVERLESS_API_KEY>"
    index       => "%{[@metadata][input][elasticsearch][_index]}"
  }

  stdout { codec => rubydebug { metadata => true } }
}
		
  1. Serverless 项目的 URL,设置端口为 443
  2. 用于 Serverless 项目的 API 密钥(Logstash 格式)
  3. 保留原始索引名称的说明
提示

创建 Logstash API 密钥时,请务必在 API 密钥格式下拉菜单中选择 Logstash。此选项会将 API 密钥格式化为 Logstash 所需的正确 id:api_key 格式。

启动 Logstash

bin/logstash -f migration.conf
		

运行 Logstash 后,确认数据已成功迁移

  1. 登录到您的 Elastic Cloud Serverless 项目。
  2. 导航至“索引管理” (Index Management) 并选择相关索引。
  3. 确认迁移的数据可见。

Elasticsearch 输入插件包含更多配置选项,提供了更大的灵活性,并可处理更高级的迁移。对于迁移用例特别相关的一些选项包括:

  • size - 控制每次滚动 (scroll) 检索的文档数量。值越大,吞吐量越高,但占用的内存越多。
  • slices - 启用从源索引进行并行读取。
  • scroll - 调整 Elasticsearch 保持滚动上下文 (scroll context) 存活的时间。

Elasticsearch 输入插件支持类似游标 (cursor) 的分页功能,解锁了更高级的迁移特性,包括在 Logstash 重启后恢复迁移任务的能力,以及对持续进行的数据迁移的支持。跟踪字段选项包括:

  • tracking_field - 插件记录某次运行中检索到的最后一个文档的字段值。
  • tracking_field_seed - 如果未设置 last_run_metadata_path,则设置 tracking_field 的起始值。

有关更多详细信息和代码示例,请查看 Elasticsearch 输入插件文档:跟踪跨运行的字段值

© . 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.