第1.10章 elasticsearch优化

1 跨es集群复制
elasticsearch.yml中增加配置,在两个集群都配置上白名单

reindex.remote.whitelist: ["10.101.10.58:9200","10.101.10.59:9200","10.101.10.60:9200"]

其余配置参考第1.8章 elasticsearch水平扩展
Elasticsearch跨集群搜索(Cross Cluster Search)Elasticsearch:跨集群数据迁移之离线迁移执行命令

POST _reindex
 {     "source": {         "remote": {             "host": "http://172.168.1.15:9200"
         },         "index": "test1",         "query": {             "match": {                 "your_cond": "xxx"
             }
         }
     },     "dest": {         "index": "test2"
     }
 }

更详细的可以参考elasticsearch 基础 —— ReIndex

POST _reindex
{
  "source": {
    "remote": {
      "host": "http://otherhost:9200", // 远程es的ip和port列表
      "socket_timeout": "1m",
      "connect_timeout": "10s"  // 超时时间设置
    },
    "index": "my_index_name", // 源索引名称
    "query": {         // 满足条件的数据
      "match": {
        "test": "data"
      }
    }
  },
  "dest": {
    "index": "dest_index_name"  // 目标索引名称
  }
}

2 es中swap配置
ElasticSearch:堆大小与swap设置,内存换成硬盘将毁掉服务器的性能,那么对于高性能的数据服务,es有一个优化点就是关闭掉swap

sudo swapoff -a

如果关闭掉了swap,那么vm.swappiness中设置为0,还是1呢?
再看看centos中设置swap交换空间的大小设置和swappiness的比例设置,从这篇文章了解到设置为vm.swappiness=0目前内存使用量还有剩余的话,建议直接将swappiness改成0,这样可以最大限度的使用物理内存,减少硬盘的负载,同时加快速度。也避免在使用Memcached的时候出现"memcached timeout error because of slow response"这样的错误
再看看Linux swappiness参数设置与内存交换 ,这篇文章

vm.swappiness = 0  
仅在内存不足的情况下--当剩余空闲内存低于vm.min_free_kbytes limit时,使用交换空间。
vm.swappiness = 1  
内核版本3.5及以上、Red Hat内核版本2.6.32-303及以上,进行最少量的交换,而不禁用交换。

这样就不难梳理出结论

1、在足够内存的机器,那么可以关闭掉swap,既然已经关闭了swap。那么就有几种策略
   1.1 设置vm.swappiness = 0,这样从操作系统级别给禁用了
   1.2 在elasticsearch.yml中配置bootstrap.mlockall: true,这样让锁定es所占用的内存,不影响其他程序是否使用swap
2、如果没有足够内存的机器,需要将vm.swappiness降低

3 堆内存的设置
jvm.options中配置,参考Elasticsearch Reference中说明,
Elasticsearch中设置JVM堆的大小这篇文章做了翻译
这里面的信息是最大堆内存不要超过32G,最好是物理内存的50%

Set Xmx and Xms to no more than 50% of your physical RAM
the exact threshold varies but is near 32 GB
You should always set the min and max JVM heap  size to the same value.
确保Xmx和Xms的大小是相同的,其目的是为了能够在java垃圾回收机制清理完堆区后不需要重新分隔计算堆区的大小而浪费资源,可以减轻伸缩堆大小带来的压力

Elasticsearch内存分配设置详解

## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
发布了317 篇原创文章 · 获赞 168 · 访问量 46万+

猜你喜欢

转载自blog.csdn.net/warrah/article/details/95203909