- transient 臨時:這些設置在集群重啟之前一直會生效。一旦整個集群重啟,這些設置就被清除。
- persistent 永久:這些設置永久保存,除非再次被手動修改。是將修改持久化到文件中,重啟之后也不影響。
1、查看集群配置
GET _cluster/settings
2、禁用與啟用自平衡
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.rebalance.enable": "none"
}
}
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.rebalance.enable": "all"
}
}
3、禁用與啟用自分片
all - (默認值)允許為所有類型的分片分配分片。
primaries - 僅允許分配主分片的分片。
new_primaries -僅允許為新索引的主分片分配分片。
none - 任何索引都不允許任何類型的分配分片。
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.enable": "none"
}
}
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.enable": "all"
}
}
4、配置分片遷移並發數
①節點級別
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.node_concurrent_recoveries": 2
}
}
②集群級別
PUT _cluster/settings
{
"persistent": {
"cluster.routing.allocation.cluster_concurrent_rebalance": 8}
}
5、退役節點
_ip:通過IP
_name:通過節點名
_host:通過主機名
①指定退役節點IP
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.exclude._ip" : "1.1.1.1,2.2.2.2"
}
}
②指定保留節點IP,至少符合一項
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.include._ip" : "1.1.1.1,2.2.2.2"
}
}
③指定保留節點IP,指定項全部符合
PUT _cluster/settings
{
"persistent" : {
"cluster.routing.allocation.require._ip" : "1.1.1.1,2.2.2.2"
}
}
6、清空配置為默認值
PUT _cluster/settings
{
"persistent": {
"indices.recovery.max_bytes_per_sec": null}
}
7、開啟慢查詢
PUT /_settings
{
"index.search.slowlog.level": "debug",
"index.search.slowlog.threshold.query.warn": "5s",
"index.search.slowlog.threshold.query.info": "3s",
"index.search.slowlog.threshold.query.debug": "1s",
"index.search.slowlog.threshold.query.trace": "500ms",
"index.search.slowlog.threshold.fetch.warn": "1s",
"index.search.slowlog.threshold.fetch.info": "800ms",
"index.search.slowlog.threshold.fetch.debug": "500ms",
"index.search.slowlog.threshold.fetch.trace": "200ms"
}
8、強制重新分配集群中的UNASSIGEMED Shards
POST _cluster/reroute?retry_failed=true
9、設置index恢復時每秒最大字節數限制,默認40mb
PUT _cluster/settings
{
"persistent": {
"indices.recovery.max_bytes_per_sec": "100mb"}
}
10、同步刷新
POST _flush/synced
11、設置ES集群允許使用_all或*通配符的方式刪除索引,默認不允許,會報“Wildcard expressions or all indices are not allowed”錯誤。
PUT /_cluster/settings
{
"persistent" : {
"action.destructive_requires_name" : false
}
}
12、 磁盤的三個默認警戒水位線
cluster.routing.allocation.disk.watermark.low 低警戒水位線——默認為磁盤容量的85%。
Elasticsearch不會將分片分配給使用磁盤超過85%的節點。它也可以設置為絕對字節值(如500mb),以防止Elasticsearch在小於指定的可用空間量時分配分片。此設置不會影響新創建的索引的主分片,或者特別是之前任何從未分配過的分片。
cluster.routing.allocation.disk.watermark.high 高警戒水位線——默認為磁盤容量的90%。
Elasticsearch將嘗試從磁盤使用率超過90%的節點重新分配分片。它也可以設置為絕對字節值,以便在節點小於指定的可用空間量時將其從節點重新分配。此設置會影響所有分片的分配,無論先前是否分配。
cluster.routing.allocation.disk.watermark.flood_stage 洪水警戒水位線——默認為磁盤容量的95%。
Elasticsearch對每個索引強制執行只讀索引塊(index.blocks.read_only_allow_delete)。這是防止節點耗盡磁盤空間的最后手段。一旦有足夠的可用磁盤空間允許索引操作繼續,就必須手動釋放索引塊。
cluster.info.update.interval Elasticsearch應該多久檢查一次群集中每個節點的磁盤使用情況。 默認為30秒。
磁盤的分片分配綜合樣例配置如下:
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.disk.watermark.low": "100gb",
"cluster.routing.allocation.disk.watermark.high": "50gb",
"cluster.routing.allocation.disk.watermark.flood_stage": "10gb",
"cluster.info.update.interval": "1m"
}
}
13、ES遷移數據
①先擴容,集群退役節點
②logstash等工具遷移
③reindex
從遠程ES進行reindex
需要在配置文件中設置白名單:
reindex.remote.whitelist: ["192.168.1.2:9200"]
14、查看ES異常狀態
GET _cluster/allocation/explain
