Elasticsearch学习之配置小记

基于 elasticsearch 1.4.4 版本.安装方式为RPM安装.所有涉及路径需根据实际情况来设置判断.

0x01 内存调整

调整ES内存分配有多种方式,建议调整 /etc/sysconfig/elasticsearch 中的设置(还可以直接修改bin下的启动脚本).

# Directory where the Elasticsearch binary distribution resides
ES_HOME=/usr/share/elasticsearch
# Heap Size (defaults to 256m min, 1g max)
# 修改此处即可,ES_HEAP_SIZE表示JVM参数的-Xms and -Xmx设置
ES_HEAP_SIZE=32g # Heap new generation # 表示JVM参数的-Xmn设置 #ES_HEAP_NEWSIZE= # max direct memory # 表示JVM的-XX:MaxDirectMemorySize设置 #ES_DIRECT_SIZE= # Additional Java OPTS #ES_JAVA_OPTS= # Maximum number of open files MAX_OPEN_FILES=65535 # Maximum amount of locked memory #MAX_LOCKED_MEMORY= # Maximum number of VMA (Virtual Memory Areas) a process can own MAX_MAP_COUNT=262144 # Elasticsearch log directory LOG_DIR=/var/log/elasticsearch # Elasticsearch data directory DATA_DIR=/var/lib/elasticsearch # Elasticsearch work directory WORK_DIR=/tmp/elasticsearch # Elasticsearch conf directory CONF_DIR=/etc/elasticsearch # Elasticsearch configuration file (elasticsearch.yml) CONF_FILE=/etc/elasticsearch/elasticsearch.yml # User to run as, change this to a specific elasticsearch user if possible # Also make sure, this user can write into the log directories in case you change them # This setting only works for the init script, but has to be configured separately for systemd startup ES_USER=elasticsearch # Configure restart on package upgrade (true, every other setting will lead to not restarting) #RESTART_ON_UPGRADE=true

注:只需要修改 ES_HEAP_SIZE 设置即可,其他保持默认.除非你精通JVM的调优. 关于 ES的JVM调优 ,可以查看下.

0x02 集群设置

修改配置 /etc/elasticsearch/elasticsearch.yml 以下对相关字段以注释方式进行解析.

##################### Elasticsearch Configuration Example ##################### # 我只是挑些重要的配置选项进行注释,其实自带的已经有非常细致的英文注释了.有理解偏差的地方请以英文原版解释为准. ################################### Cluster ################################### # 代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的. # es的一个概念就是去中心化,字面上理解就是无中心节点,这是对于集群外部来说的,因为从外部来看es集群,在逻辑上是个整体,你与任何一个节点的通信和与整个es集群通信是等价的。 # cluster.name可以确定你的集群名称,当你的elasticsearch集群在同一个网段中elasticsearch会自动的找到具有相同cluster.name的elasticsearch服务. # 所以当同一个网段具有多个elasticsearch集群时cluster.name就成为同一个集群的标识. #cluster.name: elasticsearch #################################### Node ##################################### # 节点名称同理,可自动生成也可手动配置. #node.name: "Franz Kafka" # 允许一个节点是否可以成为一个master节点,es是默认集群中的第一台机器为master,如果这台机器停止就会重新选举master. #node.master: true # 允许该节点存储数据(默认开启) #node.data: true # 配置文件中给出了三种配置高性能集群拓扑结构的模式,如下: # 1. 如果你想让节点从不选举为主节点,只用来存储数据,可作为负载器 # node.master: false # node.data: true # # 2. 如果想让节点成为主节点,且不存储任何数据,并保有空闲资源,可作为协调器 # node.master: true # node.data: false # # 3. 如果想让节点既不称为主节点,又不成为数据节点,那么可将他作为搜索器,从节点中获取数据,生成搜索结果等 # node.master: false # node.data: false # 监控集群状态有一下插件和API可以使用: # Use the Cluster Health API [http://localhost:9200/_cluster/health], the # Node Info API [http://localhost:9200/_nodes] or GUI tools # such as <http://www.elasticsearch.org/overview/marvel/>, # <http://github.com/karmi/elasticsearch-paramedic>, # <http://github.com/lukas-vlcek/bigdesk> and # <http://mobz.github.com/elasticsearch-head> to inspect the cluster state. # A node can have generic attributes associated with it, which can later be used # for customized shard allocation filtering, or allocation awareness. An attribute # is a simple key value pair, similar to node.key: value, here is an example: # #node.rack: rack314 # By default, multiple nodes are allowed to start from the same installation location # to disable it, set the following: #node.max_local_storage_nodes: 1 #################################### Index #################################### # 设置索引的分片数,默认为5 #index.number_of_shards: 5 # 设置索引的副本数,默认为1: #index.number_of_replicas: 1 # 配置文件中提到的最佳实践是,如果服务器够多,可以将分片提高,尽量将数据平均分布到大集群中去 # 同时,如果增加副本数量可以有效的提高搜索性能 # 需要注意的是,"number_of_shards" 是索引创建后一次生成的,后续不可更改设置 # "number_of_replicas" 是可以通过API去实时修改设置的 #################################### Paths #################################### # 配置文件存储位置 #path.conf: /path/to/conf # 数据存储位置(单个目录设置) #path.data: /path/to/data # 多个数据存储位置,有利于性能提升 #path.data: /path/to/data1,/path/to/data2 # 临时文件的路径 #path.work: /path/to/work # 日志文件的路径 #path.logs: /path/to/logs # 插件安装路径 #path.plugins: /path/to/plugins #################################### Plugin ################################### # 设置插件作为启动条件,如果一下插件没有安装,则该节点服务不会启动 #plugin.mandatory: mapper-attachments,lang-groovy ################################### Memory #################################### # 当JVM开始写入交换空间时(swapping)ElasticSearch性能会低下,你应该保证它不会写入交换空间 # 设置这个属性为true来锁定内存,同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过 `ulimit -l unlimited` 命令 #bootstrap.mlockall: true # 确保 ES_MIN_MEM 和 ES_MAX_MEM 环境变量设置为相同的值,以及机器有足够的内存分配给Elasticsearch # 注意:内存也不是越大越好,一般64位机器,最大分配内存别才超过32G ############################## Network And HTTP ############################### # 设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0 #network.bind_host: 192.168.0.1 # 设置其它节点和该节点交互的ip地址,如果不设置它会自动设置,值必须是个真实的ip地址 #network.publish_host: 192.168.0.1 # 同时设置bind_host和publish_host上面两个参数 #network.host: 192.168.0.1 # 设置节点间交互的tcp端口,默认是9300 #transport.tcp.port: 9300 # 设置是否压缩tcp传输时的数据,默认为false,不压缩 #transport.tcp.compress: true # 设置对外服务的http端口,默认为9200 #http.port: 9200 # 设置请求内容的最大容量,默认100mb #http.max_content_length: 100mb # 使用http协议对外提供服务,默认为true,开启 #http.enabled: false ################################### Gateway ################################### # gateway的类型,默认为local即为本地文件系统,可以设置为本地文件系统 #gateway.type: local # 下面的配置控制怎样以及何时启动一整个集群重启的初始化恢复过程 # (当使用shard gateway时,是为了尽可能的重用local data(本地数据)) # 一个集群中的N个节点启动后,才允许进行恢复处理 #gateway.recover_after_nodes: 1 # 设置初始化恢复过程的超时时间,超时时间从上一个配置中配置的N个节点启动后算起 #gateway.recover_after_time: 5m # 设置这个集群中期望有多少个节点.一旦这N个节点启动(并且recover_after_nodes也符合), # 立即开始恢复过程(不等待recover_after_time超时) #gateway.expected_nodes: 2 ############################# Recovery Throttling ############################# # 下面这些配置允许在初始化恢复,副本分配,再平衡,或者添加和删除节点时控制节点间的分片分配 # 设置一个节点的并行恢复数 # 1.初始化数据恢复时,并发恢复线程的个数,默认为4 #cluster.routing.allocation.node_initial_primaries_recoveries: 4 # # 2.添加删除节点或负载均衡时并发恢复线程的个数,默认为2 #cluster.routing.allocation.node_concurrent_recoveries: 2 # 设置恢复时的吞吐量(例如:100mb,默认为0无限制.如果机器还有其他业务在跑的话还是限制一下的好) #indices.recovery.max_bytes_per_sec: 20mb # 设置来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5 #indices.recovery.concurrent_streams: 5 # 注意: 合理的设置以上参数能有效的提高集群节点的数据恢复以及初始化速度 ################################## Discovery ################################## # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点.默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 1 # 探查的超时时间,默认3秒,提高一点以应对网络不好的时候,防止脑裂 #discovery.zen.ping.timeout: 3s # For more information, see # <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html> # 设置是否打开多播发现节点.默认是true. # 当多播不可用或者集群跨网段的时候集群通信还是用单播吧 #discovery.zen.ping.multicast.enabled: false # 这是一个集群中的主节点的初始列表,当节点(主节点或者数据节点)启动时使用这个列表进行探测 #discovery.zen.ping.unicast.hosts: ["host1", "host2:port"] # Slow Log部分与GC log部分略,不过可以通过相关日志优化搜索查询速度 ############## Memory(重点需要调优的部分) ################ # Cache部分: # es有很多种方式来缓存其内部与索引有关的数据.其中包括filter cache # filter cache部分: # filter cache是用来缓存filters的结果的.默认的cache type是node type.node type的机制是所有的索引内部的分片共享filter cache.node type采用的方式是LRU方式.即:当缓存达到了某个临界值之后,es会将最近没有使用的数据清除出filter cache.使让新的数据进入es. # 这个临界值的设置方法如下:indices.cache.filter.size 值类型:eg.:512mb 20%。默认的值是10%。 # out of memory错误避免过于频繁的查询时集群假死 # 1.设置es的缓存类型为Soft Reference,它的主要特点是据有较强的引用功能.只有当内存不够的时候,才进行回收这类内存,因此在内存足够的时候,它们通常不被回收.另外,这些引用对象还能保证在Java抛出OutOfMemory异常之前,被设置为null.它可以用于实现一些常用图片的缓存,实现Cache的功能,保证最大限度的使用内存而不引起OutOfMemory.在es的配置文件加上index.cache.field.type: soft即可. # 2.设置es最大缓存数据条数和缓存失效时间,通过设置index.cache.field.max_size: 50000来把缓存field的最大值设置为50000,设置index.cache.field.expire: 10m把过期时间设置成10分钟. 

转载于:https://www.cnblogs.com/sunfie/p/9683557.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值