问题:
我正在尝试在ES实例ES1上创建快照,并还原到另一个实例ES2。当远程URL需要基本身份验证时,它无法恢复。
ES版本:6.5.4
成功和失败案例:
成功案例:当暴露ES1存储库文件夹的网站在互联网上打开(无身份验证(时,列表/恢复工作正常。例如,当回购URL是";http://snapshots.example-server.com">
失败案例:当我向同一个URL添加基本身份验证时,它不起作用。例如,当回购URL是:";http://用户名:密码@snapshots.example-server.com">
当我尝试使用基本身份验证在URL存储库中列出快照时,我得到的错误是:
{
"error": {
"root_cause": [
{
"type": "repository_exception",
"reason": "[remote-repo] could not read repository data from index blob"
}
],
"type": "repository_exception",
"reason": "[remote-repo] could not read repository data from index blob",
"caused_by": {
"type": "i_o_exception",
"reason": "Server returned HTTP response code: 401 for URL: http://username:password@snapshots.example-server.com/index.latest"
}
},
"status": 500
}
设置:
设置ES1:
步骤1:修改配置文件:
path.repo: ["/path/to/es1_repo"]
步骤2:创建回购:
PUT /_snapshot/es1_repo
{
"type": "fs",
"settings": {
"location": "/path/to/es1_repo"
}
}
步骤3:使存储库路径可从internet访问:我在ES1机器上设置了一个nginx服务器,以公开"/path/to/es1_repo”
目录列表,比如说:http://snapshots.example-server.com.它已启用基本身份验证。例如,您可以访问回购http://username:password@snapshots.example-server.com,您会看到目录列表。
步骤4:创建快照:
PUT /_snapshot/es1_repo/snapshot_1?wait_for_completion=true
{
"indices": "the_index_name",
"ignore_unavailable": true,
"include_global_state": false
}
设置ES2:
步骤5:添加到弹性配置:
repositories.url.allowed_urls: "http://username:password@snapshots.example-server.com"
步骤6:注册回购
PUT _snapshot/remote-repo
{
"type": "url",
"settings": {
"url": "http://username:password@snapshots.example-server.com"
}
}
步骤7:检查快照是否可访问:
GET _snapshot/remote-repo/_all
在此步骤中,将显示粘贴在顶部的错误。如果我禁用基本身份验证,它可以正常工作。
这里可能有什么问题?
您应该制作这些:
- 将elasticsearch.yaml或docker环境中的存储库添加到白名单中
repositories.url.allowed_urls: "http://snapshots.example-server.com"
- 创建快照存储库
PUT _snapshot/remote-repo
{
"type": "url",
"settings": {
"url": "http://snapshots.example-server.com",
"client": "your_client",
}
}
- 将用户名和密码添加到Elasticsearch密钥库
bin/elasticsearch-keystore add url.client.your_client.username
bin/elasticsearch-keystore add url.client.your_client.password