一、索引管理

1、 创建索引

PUT test-2019-03

{

"settings": {

"index": {

"number_of_shards": 10,

"number_of_replicas": 1,

"routing": {

"allocation": {

"include": {

"type": "hot"

}

}

}

}

}

}

2、 删除索引

DELETE test-2019-03

DELETE test*

支持通配符*

3、 修改索引

修改副本数:

PUT test-2019-03/_settings

{

"index": {

"number_of_replicas": 0

}

}

4、 重构索引ReIndex

POST _reindex

{

"source": {

"index": ["test-2018-07-*"]

},

"dest": {

"index": "test -2018-07"

}

}

查看reIndex任务:

GET _tasks?detailed=true&actions=*reindex

5、 删除数据delete_by_query

POST indexApple-2019-02/_delete_by_query?conflicts=proceed

{

"query": {

"bool" : {

"must" : {

"term" : { "appIndex" : "apple" }

},

"filter" : {

"range": {

"timestamp": {

"gte": "2019-02-23 08:00:00",

"lte": "2019-02-23 22:00:00",

"time_zone" :"+08:00"

}

}

}

}

}

}

查看delete_by_query任务:

GET _tasks?detailed=true&actions=*/delete/byquery

二、集群设置

ES cluster的settings:

curl -XPUT http://<domain>:<port>/_cluster/settings

1、Shard Allocation Settings

{"persistent":{"cluster.routing.allocation.enable": “all”}}

设置集群哪种分片允许分配,4个选项:

all - (default) Allows shard allocation for all kinds of shards.

primaries - Allows shard allocation only for primary shards.

new_primaries - Allows shard allocation only for primary shards for new indices.

none - No shard allocations of any kind are allowed for any indices.

{"persistent":{"cluster.routing.allocation.node_concurrent_recoveries": 8}}
设置在节点上并发分片恢复的个数(写和读)。

{"persistent":{"cluster.routing.allocation.node_initial_primaries_recoveries":
16}} 
设置节点重启后有多少并发数从本地恢复未分配的主分片。

{"persistent":{"indices.recovery.max_bytes_per_sec":
"500mb"}}
设置索引恢复时每秒字节数。

2、Shard Rebalancing Settings

{"persistent":{"cluster.routing.
rebalance.enable": “all”}}

设置集群哪种分片允许重平衡,4个选项:

all -
(default) Allows shard balancing for all kinds of shards.

primaries -
Allows shard balancing only for primary shards.

replicas -
Allows shard balancing only for replica shards.

none - No
shard balancing of any kind are allowed for any indices.

{"persistent":{"cluster.routing.
allocation. allow_rebalance ": “all”}}

always -
Always allow rebalancing.

indices_primaries_active -
Only when all primaries in the cluster are allocated.

indices_all_active -
(default) Only when all shards (primaries and replicas) in the cluster are
allocated.

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance":
8}}
设置在集群上并发分片重平衡的个数,只控制“重平衡”过程的并发数,对集群“恢复”和其他情况下的并发数没有影响。

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance":
0}}

禁用集群“rebalance”

{"transient":{"cluster.routing.allocation.cluster_concurrent_rebalance":
null}}
启用集群“rebalance”

3、Disk-based Shard Allocation

#调整数据节点的低水位值为80%
{"transient":{"cluster.routing.allocation.disk.watermark.low":"80%"}}
#调整数据节点的高水位值为90%
{"transient":{"cluster.routing.allocation.disk.watermark.high":"90%"}}
#取消用户设置,集群恢复这一项的默认配置
{"transient":{"cluster.routing.allocation.disk.watermark.low":
null}}
{"transient":{"cluster.routing.allocation.disk.watermark.high":
null}}

4、排除节点

#通过IP,排除集群中的某个节点:节点IP:10.100.0.11
{"transient":{"cluster.routing.allocation.exclude._ip":"10.100.0.11"}}
#通过IP,排除集群中的多个节点:节点IP:10.10.0.11,10.100.0.12
{"transient":{"cluster.routing.allocation.exclude._ip":"10.100.0.11,10.100.0.12"}}
#取消节点排除的限制
{"transient":{"cluster.routing.allocation.exclude._ip":
null}}

设置索引不分配到某些IP:

PUT test/_settings

{

"index.routing.allocation.exclude._ip":
"192.168.2.*"

}

默认支持的属性:

_name      Match nodes by node name

_host_ip  Match nodes by host IP address (IP associated
with hostname)

_publish_ip       Match nodes by publish IP address

_ip    Match either _host_ip or _publish_ip

_host        Match nodes by hostname

集群滚动重启

1、准备工作
##提前打开如下信息,有些API是需要观察的各项指标(出现问题则停止重启),其余是配合检查的API:
##查看集群UNASSIGEN shards原因
curl http://0.0.0.0:9200/_cluster/allocation/explain?pretty

###集群配置
curl http://0.0.0.0:9200/_cluster/settings?pretty

###pending-tasks
curl http://0.0.0.0:9200/_cluster/pending_tasks?pretty

###集群健康
curl http://0.0.0.0:9200/_cluster/health?pretty
2、重启client-node
#start
步骤1:关闭其中一个client节点
步骤2:重启节点
步骤3:检查节点是否加入集群
步骤4:重复步骤2-3重启其他节点
#end

3、重启master-node
#start
步骤1:明确master节点IP
步骤2:关闭master-node组的一个非master节点
步骤3:重启节点
步骤4:检查节点是否加入集群(确保已经加入集群)
步骤5:重复步骤2-4,重启另外的master-node组的一个非master节点
步骤6:关闭master节点
步骤7:重启master节点
##在master节点选举过程中,集群功能不可用(包括了:索引功能、search功能,API功能堵塞等),集群并不会立即选举出master节点(默认进行选举的时间为3s, 由于网络的问题,往往将master选举的时间延长)
步骤8:检查集群装填,检查节点是否加入集群。
##当master选举出来,集群功能将全部正常。
#end

4、重启data-node
#start
步骤1:禁用分片分配
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d
'{"transient": {"cluster.routing.allocation.enable":
"new_primaries"}}'
##禁用分片分配期间,集群新建索引将无法分配副本分片,允许新建索引主分片的分配
步骤2:执行同步刷新
curl -XPOST "http://0.0.0.0:9200/_flush/synced?pretty"
##对于在此刻不在更新的索引,此操作将通过synced值来确认主副分片是否数据一致(加快了分片加入集群的时间);对于在此刻索引发生变化的分片,此操作对节点加入集群的索引恢复没有作用
步骤3:关闭一个data-node节点
步骤4:重启节点
步骤5:检查节点是否加入集群
步骤6:启用分片分配
curl -X PUT http://0.0.0.0:9200/_cluster/settings?pretty -d '{"transient":
{"cluster.routing.allocation.enable": "all"}}'
步骤7:检查集群状态是否为green
##在启用了分片分配后,UNASSIGEN shards会瞬间减少(不会瞬间减少为0,因为在大的ES集群中,每个节点都会有在更新的索引分片);之后会出现一些initializing shards,这部分分片会需要等待一段时间才会减少为0(分片同步过程中)
步骤8:重复步骤3-7,重启其他节点
步骤9:节点全部重启完毕后,检查集群配置,确保没有禁用分片分配
#end
参考资料:

ES官方重启教程
https://www.elastic.co/guide/en/elasticsearch/reference/1.4/cluster-nodes-shutdown.html#_rolling_restart_of_nodes_full_cluster_restart

参考:

https://www.elastic.co/guide/en/elasticsearch/reference/6.2/index.html

Elasticsearch集群运维的更多相关文章

  1. PB 级大规模 Elasticsearch 集群运维与调优实践

    PB 级大规模 Elasticsearch 集群运维与调优实践 https://mp.weixin.qq.com/s/PDyHT9IuRij20JBgbPTjFA | 导语 腾讯云 Elasticse ...

  2. 400+节点的 Elasticsearch 集群运维

    本文首发于InfoQ https://www.infoq.cn/article/1sm0Mq5LyY_021HGuXer 作者:Anton Hägerstrand 翻译:杨振涛 目录: 数据量 版本 ...

  3. PB级大规模Elasticsearch集群运维与调优实践

    导语 | 腾讯云Elasticsearch 被广泛应用于日志实时分析.结构化数据分析.全文检索等场景中,本文将以情景植入的方式,向大家介绍与腾讯云客户合作过程中遇到的各种典型问题,以及相应的解决思路与 ...

  4. PB级大规模Elasticsearch集群运维与调优实践【>>戳文章免费体验Elasticsearch服务30天】

    [活动]Elasticsearch Service免费体验馆>> Elasticsearch Service自建迁移特惠政策>>Elasticsearch Service新用户 ...

  5. Elasticsearch 学习之携程机票ElasticSearch集群运维驯服记(强烈推荐)

    转自: https://mp.weixin.qq.com/s/wmSTyIGCVhItVNPHcH7nsA 一.整体架构 为什么采用ES作为搜索引擎呢?在做任何事情的时候,不要一上来就急着了解怎么做这 ...

  6. 集群运维ansible

    ssh免密登录 集群运维 生成秘钥,一路enter cd ~/.ssh/ ssh-keygen -t rsa 讲id_rsa.pub文件追加到授权的key文件中 cat ~/.ssh/id_rsa.p ...

  7. 阿里巴巴大规模神龙裸金属 Kubernetes 集群运维实践

    作者 | 姚捷(喽哥)阿里云容器平台集群管理高级技术专家 本文节选自<不一样的 双11 技术:阿里巴巴经济体云原生实践>一书,点击即可完成下载. 导读:值得阿里巴巴技术人骄傲的是 2019 ...

  8. 使用Chef管理windows集群 | 运维自动化工具

    但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...

  9. 灵雀云:etcd 集群运维实践

    [编者的话]etcd 是 Kubernetes 集群的数据核心,最严重的情况是,当 etcd 出问题彻底无法恢复的时候,解决问题的办法可能只有重新搭建一个环境.因此围绕 etcd 相关的运维知识就比较 ...

随机推荐

  1. SPOJ LCS2 - Longest Common Substring II 字符串 SAM

    原文链接http://www.cnblogs.com/zhouzhendong/p/8982484.html 题目传送门 - SPOJ LCS2 题意 求若干$(若干<10)$个字符串的最长公共 ...

  2. Python交互图表可视化Bokeh:2. 辅助参数

    图表辅助参数设置 辅助标注.注释.矢量箭头 参考官方文档:https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#col ...

  3. 空间分析工具:GIS

    1.数据空间 数据空间是指用来表示空间实体的的位置.几何特征及其属性特征的数据. 位置:经纬度.地址.相对位置: 几何特征:点.线.面.形状: 属性特征:面积.周长.人口.经济等属性. POI数据.O ...

  4. 使用git工具上传自己的程序到github上

    一:前期准备 可以运行的项目 github账号 git工具 二:开始操作 1.创建个人github仓库 写自己项目的名字,描述,权限,README 2.新建结束后会进入如下界面 3.复制仓库地址 4. ...

  5. day6 note 字典的增删改查(以及setdefault用法补充)

    今天的内容主要是join的用法和字典的用法,由于已经有前面的列表作为基础,所以还比较简单,不过因为昨天的作业比较难也比较多,所以作业的讲解占用的时间比较长.我需要好好消化一下作业的部分. 思维导图: ...

  6. dfs和bfs的区别

    详见转载博客:https://www.cnblogs.com/wzl19981116/p/9397203.html 1.dfs(深度优先搜索)是两个搜索中先理解并使用的,其实就是暴力把所有的路径都搜索 ...

  7. CSU 1592 石子合并 (经典题)【区间DP】

    <题目链接> 题目大意: 现在有n堆石子,第i堆有ai个石子.现在要把这些石子合并成一堆,每次只能合并相邻两个,每次合并的代价是两堆石子的总石子数.求合并所有石子的最小代价. Input ...

  8. BZOJ-5-4300: 绝世好题-位-DP

    思路 :题意描述我也很绝望 .先说一下题意 : 给定长度为n数组a [ ],求a[ ] 的一个最大子序列(可以不连续),使得b [ i ]& b [ i - 1 ] ! = 0.求最大的 b数 ...

  9. P2709 小B的询问-莫队

    思路 :依旧是 分块 块内按照 r 排序 不同块按照 L排序,处理好增加 删除对结果的影响即可. #include<bits/stdc++.h> using namespace std; ...

  10. 练习八 spool导出

    sqlplus -s username/password@sid set trimspool on; set linesize 120; set pagesize 2000; set newpage ...