一、Snapshot
1、从已备份的快照中恢复indices

POST _snapshot/oss_bucket_name/snapshot_name/_restore?wait_for_completion=false
{
  "indices":"indices_name",
  "ignore_unavailable":"true",
  "index_settings": {
    "index.number_of_replicas": 0,
    "index.routing.allocation.total_shards_per_node":"10"
  },
  "include_global_state":false
}

2、注册快照仓库(NAS)

# ES配置文件elasticsearch.yml
path.repo: ["/esbackup/repo"]
curl -H 'Content-Type: application/json' -u 'elastic:123456' -XPUT http://127.0.0.1:9200/_snapshot/backup_repository -d '{"type": "fs","settings": {"location": "/esbackup/repo","compress": true}}'

3、注册快照仓库(S3或OSS)

1.安装插件
sudo bin/elasticsearch-plugin install repository-s3
wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-s3/repository-s3-7.8.0.zip
sudo bin/elasticsearch-plugin install file:///path/to/repository-s3-7.8.0.zip
2.在每个ES节点执行命令,添加AK、SK到ES中
bin/elasticsearch-keystore add s3.client.default.access_key
bin/elasticsearch-keystore add s3.client.default.secret_key
3. 重启ES生效以上配置
4. 创建快照仓库
curl -H 'Content-Type: application/json' -u 'elastic:123456' -XPUT 'http://127.0.0.1:9200/_snapshot/es_backup_oss_test' -d '{"type": "s3", "settings": { "bucket": "es-backup", "endpoint": "abc.aliyuncs.com"}}'

4、创建索引快照

curl -H 'Content-Type: application/json' -u 'elastic:123456' -XPUT 'http://127.0.0.1:9200/_snapshot/es_backup/snapshot-test' -d '{"indices":"indices_test_backup","ignore_unavailable": true,"include_global_state": false}'

二、discover(7之前版本)
1、更改ES集群minimum_master_nodes节点数量

PUT _cluster/settings
{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 1
    }
}

三、调整集群最大bucket数量
ES 6版本时search.max_buckets参数默认无限制
ES 7.0-7.8,search.max_buckets参数默认是10000
ES 7.9 以后,search.max_buckets参数默认是65536

PUT _cluster/settings 
{ 
  "persistent": { 
    "search.max_buckets": "65536"
  } 
}

四、打开自动创建索引

PUT _cluster/settings
{
  "persistent": {
    "action.auto_create_index":"true"
  }
}

五、ES模板中索引别名设置

{
  "mldb": {}
}

image.png

六、索引别名设置API

POST /_aliases
{
  "actions": [
    {"remove": {"index": "l1", "alias": "a1"}},
    {"add": {"index": "l1", "alias": "a2"}}
  ]
}
POST /_aliases
{
  "actions": [
    {"add": {"index": "l1", "alias": "a1"}},
    {"add": {"index": "l2", "alias": "a1"}},
    {"add": {"index": "l3", "alias": "a1"}}
  ]
}
POST /_aliases
{
  "actions": [
    {"add": {"indices": ["l1", "l2", "l3"], "alias": "a2"}}
  ]
}
POST /_aliases
{
  "actions": [
    {"add": {"index": "l1", "aliases": ["a1", "a2", "a3"]}}
  ]
}
POST /_aliases
{
  "actions": [
    {"add": {"index": "l*", "alias": "f1"}}
  ]
}

七、设置聚合查询最大bucket数量

PUT _cluster/settings
{
  "transient": {
    "search.max_buckets": 20000
  }
}

curl -XPUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'{"persistent" : {"search.max_buckets": 20000}}'

八、设置集群专有协调节点

node.master: false 
node.data: false 
node.ingest: false 
search.remote.connect: false 

九、设置ES日志级别

# 设置根日志级别为DEBUG
PUT /_cluster/settings
{
  "transient":{
    "logger._root":"DEBUG"
  }
}
# 设置discover模块的日志级别是DEBUG
PUT _cluster/settings
{
  "transient": {
    "logger.discovery" : "DEBUG"  
  }
}
# 设置全局慢查询日志打印级别
PUT /_cluster/settings
{
    "transient" : {
        "logger.index.search.slowlog" : "DEBUG", 
        "logger.index.indexing.slowlog" : "WARN" 
    }
}
# 设置索引慢查询阈值
PUT /my_index/_settings
{
    "index.search.slowlog.threshold.query.warn" : "10s", 
    "index.search.slowlog.threshold.fetch.debug": "500ms", 
    "index.indexing.slowlog.threshold.index.info": "5s" 
}

尊宝雷
15 声望0 粉丝