Elasticsearch简单入门--elasticsearch重要的配置项

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhen_6137/article/details/86071650

Important Elasticsearch configuration

虽然Elasticsearch只需要很少的配置,但是有许多设置项需要手动配置,并且应该明确地被设置在投入生产之前。

  • path.data , path.logs
  • cluster.name
  • node.name
  • bootstrap.memory_lock
  • network.host
  • discovery.zen.ping.unicast.hosts
  • discovery.zen.minimum_master_nodes

1. path.data 和 path.logs

如果你使用zip 和 tar.gz档案文件解压缩安装的,data和logs目录是$ES_HOME的子目录,如果这些重要的文件夹被保留在它们的默认位置,那么在将Elasticsearch升级到新版本时删除它们的风险很高(If these important folders are left in their default locations, there is a high risk of them being deleted while upgrading Elasticsearch to a new version)。

在生产中使用,您几乎肯定希望更改数据和日志文件夹的位置

path.logs: /var/log/elasticsearch
path.data: /var/log/elasticsearch

这个path.data配置项可以被设置为多个路径,在这种情况下,所有路径都将用于存储数据(尽管属于单个shard的文件都将存储在相同的数据路径上)

path:
  data:
    - /mnt/elasticsearch_1
    - /mnt/elasticsearch_2
    - /mnt/elasticsearch_3

2. cluster.name

当一个节点与集群中的所有其他节点共享它的cluster.name时,它才能加入到集群中(A node can only join a cluster when it shares its cluster.name with all the other nodes in the cluster),意思就是一个节点跟其他节点有相同的cluster.name时,才能成为一个集群, 节点配置中 集群默认的名称为elasticsearch,但是你应该将其更改为一个能描述该集群用途的适当的名称。

cluster.name: logging-prod

但是要确保不要在不同的环境中重复使用相同的集群名称,否则,你可能会导致节点加入到错误的集群中。(Make sure that you don’t reuse the same cluster names in different environments, otherwise you might end up with nodes joining the wrong cluster.)

3. node.name

默认,Elasticsearch将会使用随机生成的UUID的前7个字符作为其node id, 注意,这个node id会被持久化,并且当节点重新启动时不会被改变,因此这个默认的节点名称也将不会改变。

值得配置一个更有意义的名称,它还具有在重新启动节点后持久化的优点。(It is worth configuring a more meaningful name which will also have the advantage of persisting after restarting the node)

node.name: prod-data-2

# node.name同样可以被设置为服务器的主机名称
node.name: ${HOSTNAME}

4. bootstrap.memory_lock

没有一个JVM被交换到磁盘上,这对于节点的健康非常重要 (It is vitally important to the health of your node that none of the JVM is ever swapped out to disk),

实现这一点的一种方法是设置引导程序。memory_lock设置为true。要使此设置生效,需要首先配置其他系统设置,

看到启用引导。memory_lock获取关于如何正确设置内存锁定的详细信息 

参考:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/setup-configuration-memory.html#mlockall

5. network.host

默认情况下,Elasticsearch只绑定到环回地址。127.0.0.1(::1)。这足以在服务器上运行单个开发节点。(By default, Elasticsearch binds to loopback addresses only — e.g. 127.0.0.1 and [::1]. This is sufficient to run a single development node on a server.)

实际上,可以从单个节点上相同的$ES_HOME位置启动多个节点。这对于测试Elasticsearch形成集群的能力很有用,但是在生产环境中不推荐使用这种配置.

为了与其他服务器上的节点通信并形成集群,您的节点将需要绑定到非环回地址,虽然有许多网络设置,通常您需要配置的是network.host:(In order to communicate and to form a cluster with nodes on other servers, your node will need to bind to a non-loopback address. While there are many network settings, usually all you need to configure is network.host:)

network.host: 192.168.1.10

注意:一旦为网络提供了自定义设置。Elasticsearch假设您正在从开发模式转移到生产模式,并将许多系统启动检查从警告升级到异常。(As soon you provide a custom setting for network.host, Elasticsearch assumes that you are moving from development mode to production mode, and upgrades a number of system startup checks from warnings to exceptions.)

See Development mode vs production modeedit for more information. 

查看更多关系开发模式和生成模式的信息 

https://www.elastic.co/guide/en/elasticsearch/reference/5.6/system-config.html#dev-vs-prod

6. discovery.zen.ping.unicast.hosts

开箱即用,无需任何网络配置,Elasticsearch将绑定到可用的环回地址,并扫描端口9300到9305,尝试连接到同一服务器上运行的其他节点。这提供了一种无需进行任何配置的自动集群体验(This provides an auto- clustering experience without having to do any configuration),在使用其他服务器上的节点形成集群时,必须提供集群中可能是活动的和可接触的其他节点的种子列表(When the moment comes to form a cluster with nodes on other servers, you have to provide a seed list of other nodes in the cluster that are likely to be live and contactable)

例如:

discovery.zen.ping.unicast.hosts:
   - 192.168.1.10:9300
   - 192.168.1.11 # 1
   - seeds.mydomain.com # 2

# 或者
discovery.zen.ping.unicast.hosts: ["192.168.1.10", "192.168.1.11", "192.168.1.12"]

The port will default to transport.profiles.default.port and fallback to transport.tcp.port if not specified.

A hostname that resolves to multiple IP addresses will try all resolved addresses.

7.  discovery.zen.minimum_master_nodes

为了防止数据丢失,配置discovery.zen.minimum_master_nodes设置项是极其重要的,以便每个符合主条件的节点都知道为了形成集群必须可见的符合主条件的节点的最小数量,如果没有这个设置,遭受网络故障的集群就有可能分裂成两个独立的集群——一个分裂的大脑——从而导致数据丢失。(Without this setting, a cluster that suffers a network failure is at risk of having the cluster split into two independent clusters — a split brain — which will lead to data loss.)

使用minumum_master_nodes避免脑裂的更多详细解释 参考:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-node.html#split-brain

避免脑裂,该设置项应该被设置为 a quorum of master-eligible nodes(候选主节点的法定人数)

(master_eligible_nodes/2)+1

换句话说,如果有三个候选主节点,那么minumum master nodes应该被设置为 (3/2)+1 或者是2

discovery.zen.minumum_master_nodes: 2

猜你喜欢

转载自blog.csdn.net/zhen_6137/article/details/86071650
今日推荐