2025-02-25 08:40PM
1. 在 docker-compose.yml 文件中添加:
环境变量:path.repo=/opt/social_data/
目录挂载:/opt/social_data:/opt/social_data
完整文件内容如下:
version: '2.3'
services:
elasticsearch_8.6.1:
image: elasticsearch:8.6.1
container_name: elasticsearch_8.6.1
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms1512m -Xmx1512m"
- ELASTIC_PASSWORD=6868elasticsearch
- path.repo=/opt/social_data/ # 设置快照存储路径
ports:
- "127.0.0.1:9200:9200" # 仅允许本地访问
- "127.0.0.1:9300:9300" # 仅允许本地访问
volumes:
- /opt/social_data:/opt/social_data # 挂载宿主机目录
- /opt/docker_data/elastic_search_8.6.1_our_production:/usr/share/elasticsearch/data
2. 创建备份目录(确保 /opt/social_data_backup
目录存在并且权限正确)
$ sudo mkdir -p /opt/social_data_backup
$ sudo chown -R 1000:1000 /opt/social_data_backup
3. 重启容器(我这里是在/opt/elasticsearch-docker文件夹下面):
$ docker-compose down
$ docker-compose up -d
4. 进入 elasticsearch 的 docker 容器
$ docker exec -it elasticsearch_8.6.1 /bin/bash
5. 在elasticsearch.yml中添加 path.repo(我这里使用的是 cat 来增加 path.repo)
cat >> /usr/share/elasticsearch/config/elasticsearch.yml
输入你要添加的内容:path.repo: ["/opt/social_data"]
ctrl +d 退出
6. 创建备份目录(确保 /opt/social_data_backup
目录存在并且权限正确)
$ sudo mkdir -p /opt/social_data_backup
$ sudo chown -R 1000:1000 /opt/social_data_backup
7. 尝试创建快照存储库:
$ curl -u elastic:6868elasticsearch -X PUT "localhost:9200/_snapshot/social_data" -H 'Content-Type: application/json' -d '{
"type": "fs",
"settings": {
"compress": "true",
"location": "/opt/social_data"
}
}'
8. 检查恢复状态
$ curl -u elastic:6868elasticsearch -X GET "localhost:9200/_cat/recovery?v"
index shard time type stage source_host source_node target_host target_node repository snapshot files files_recovered files_percent files_total bytes bytes_recovered bytes_percent bytes_total translog_ops translog_ops_recovered translog_ops_percent
social_data 0 38.3s snapshot index n/a n/a 172.19.0.2 7996f5c2b322 social_data snapshot_1 453 24 5.3% 453 333.3gb 1.4gb 0.4% 333.3gb 0 0 100.0%
目前,只有 5.3%
的文件和 0.4%
的字节已被恢复,这表明恢复过程仍在进行中。
等待全部恢复完成之后,就进行下面的操作。
9. 验证是否导入成功
9.1 确认快照的状态,确保它已成功恢复(应显示为 SUCCESS,
分片状态: 确保所有分片都已完成,且没有失败的分片)
$ curl -u elastic:6868elasticsearch -X GET "localhost:9200/_snapshot/social_data/snapshot_1/_status?pretty"
{
"snapshots" : [
{
"snapshot" : "snapshot_1",
"repository" : "social_data",
"uuid" : "vl9we_DqTXS6a9AQA0D2Ag",
"state" : "SUCCESS",
"include_global_state" : false,
"shards_stats" : {
"initializing" : 0,
"started" : 0,
"finalizing" : 0,
"done" : 1,
"failed" : 0,
"total" : 1
},
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133637,
"time_in_millis" : 11223252
},
"indices" : {
"social_data" : {
"shards_stats" : {
"initializing" : 0,
"started" : 0,
"finalizing" : 0,
"done" : 1,
"failed" : 0,
"total" : 1
},
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133837,
"time_in_millis" : 11222251
},
"shards" : {
"0" : {
"stage" : "DONE",
"stats" : {
"incremental" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"total" : {
"file_count" : 453,
"size_in_bytes" : 357968141091
},
"start_time_in_millis" : 1739411133837,
"time_in_millis" : 11222251
}
}
}
}
}
}
]
}
9.2 检查索引状态(确认目标索引(例如 social_data
)在列表中,并且状态为 green
或 yellow
(表示可用))
$ curl -u elastic:666888elasticsearch -X GET "localhost:9200/_cat/indices?v"
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open social_data RTmd-ZA_Tly5mVym8JlX5Q 1 1 993084680 75058653 333.3gb 333.3gb
9.3 查看导入数据量和之前是否一致
$ curl -u elastic:6868elasticsearch -X GET "http://localhost:9200/social_data/_count"
{"count":993084680,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0}}
登录
请登录后再发表评论。
评论列表:
目前还没有人发表评论