弹性设计
小集群中的弹性
1:单节点和双节点,不能保证高可用,且当双节点时,两个节点都设置成master,当其中一个异常,另一个选举master时也会出现异常,所有双节点时,需要将一个设置成master,另一个设置成非master。
2:三节点时,为防止脑裂,discovery.zen.minimum_master_nodes设置成(master/2)+1,取整。此值默认为1
3:只要满足以下条件,集群就可以抵抗任何节点的丢失:
- 集群运行状况为绿色。
- 至少有两个数据节点。
- 除主分片外,每个索引还具有每个分片的至少一个副本。
- 该集群至少具有三个符合主机要求的节点,只要这些节点中的至少两个不是仅投票的符合主机要求的节点即可。
客户端被配置为将其请求发送到多个节点,或者被配置为使用负载均衡器,以在一组适当的节点之间平衡请求。 Elastic Cloud 服务提供了这样的负载均衡器。
较大组中的弹性
集群备份
备份数据
设置备份文件地址
在elasticsearch.yml 新增
path.repo: ["/home/es/snapshot"]
注册快照存储库
PUT _snapshot/ecopherebbs
{
"type": "fs",
"settings": {
"location": "/home/es/snapshot"
}
}
查看快照存储库保存结果
GET _snapshot
创建快照
异步创建
创建
PUT _snapshot/ecopherebbs/snapshot_20210631
{
"ignore_unavailable": true,
"include_global_state": true
}
查看状态
GET _snapshot/ecopherebbs/snapshot_20210631
#返回值
#"state" : "IN_PROGRESS" 进行中
#"state" : "SUCCESS" 完成
指定索引进行快照
PUT _snapshot/ecopherebbs/snapshot_20210630?wait_for_completion=true
{
"indices": "index1,index2",
"ignore_unavailable": true,
"include_global_state": true
}
- wait_for_completion=true时会一直阻塞直到快照完成,kibana执行时超时为30秒,超时后快照依然会在后台执行
- snapshot_20200729 就是指定的备份快照命中
- 请求体重indices指定需要备份的索引(多个用逗号隔开),也可以不指定,这样会备份所有的es索引库数据
在服务器查看备份的数据
[es@test12 snapshot]$ ls -lrt
总用量 1404
drwxrwxr-x. 62 es es 4096 6月 30 13:23 indices
-rw-rw-r--. 1 es es 460329 6月 30 13:24 meta--WCM58RpQNm5bEywCjO_cg.dat
-rw-rw-r--. 1 es es 1596 6月 30 13:24 snap--WCM58RpQNm5bEywCjO_cg.dat
-rw-rw-r--. 1 es es 1596 6月 30 13:26 snap-PTBkWV-pQ8CQ7l4RNxISfA.dat
-rw-rw-r--. 1 es es 460329 6月 30 13:26 meta-PTBkWV-pQ8CQ7l4RNxISfA.dat
-rw-rw-r--. 1 es es 302 6月 30 13:52 snap-N3zRMDnDTEqoiShEwjKosA.dat
-rw-rw-r--. 1 es es 460329 6月 30 13:52 meta-N3zRMDnDTEqoiShEwjKosA.dat
-rw-rw-r--. 1 es es 24990 6月 30 13:52 index-2
-rw-rw-r--. 1 es es 8 6月 30 13:52 index.latest
恢复数据
本机恢复
执行恢复要将之前的索引删除,否则会报错POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore
或者在恢复时执行新索引名称 官网描述
POST /_snapshot/my_backup/snapshot_1/_restore
{
"indices": "index_1",
"rename_pattern": "index_(.+)",
"rename_replacement": "restored_index_$1"
}
其他服务器恢复
- 配置第一步设置的目录
path.repo: [“/home/es/snapshot”] 创建仓库
PUT _snapshot/ecopherebbs
{
"type": "fs",
"settings": {
"location": "/home/es/snapshot-test"
}
}
执行恢复索引
POST _snapshot/ecopherebbs/snapshot_20210631_02/_restore
常见问题
报错 doesn’t match any of the locations specified by path.repo because this setting is empty
{
"error" : {
"root_cause" : [
{
"type" : "repository_exception",
"reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
}
],
"type" : "repository_exception",
"reason" : "[ecopherebbs] failed to create repository",
"caused_by" : {
"type" : "repository_exception",
"reason" : "[ecopherebbs] location [/home/es/snapshot] doesn't match any of the locations specified by path.repo because this setting is empty"
}
},
"status" : 500
}
- 解决方法:
在为es集群环境做灾备和恢复时候,首先需要创建创建一个仓库,并往仓库中存放快照(每个快照中会区分不同的索引)。但是在创建仓库的时候,要求仓库的地址必须在每个集群环境中的elasticsearch.yml中进行配置
备份集群配置
这个一般备份 ES_PATH_CONF目录中的一些配置即可。
备份安全配置
安全配置信息位于两个位置:文件和索引。
备份基于文件的安全配置编辑
Elasticsearch安全功能是使用Elasticsearch.yml和Elasticsearch.keystore文件中的xpack.security命名空间配置的。此外,在相同的ES_PATH_CONF目录中还有其他几个额外的配置文件。这些文件定义角色和角色映射,并配置文件域。某些设置指定安全敏感数据的文件路径,例如HTTP客户端和节点间通信的TLS密钥和证书,以及SAML、OIDC和Kerberos领域的私钥文件。所有这些都存储在ES_PATH_CONF中;路径设置是相对的。
跨集群复制
参考:
1:https://blog.csdn.net/wang7075202/category_10645690.html?spm=1001.2014.3001.5482
2:https://www.cnblogs.com/sh-jast/p/14956547.html
3:https://www.elastic.co/guide/en/elasticsearch/reference/7.x/high-availability-cluster-design-large-clusters.html