Elasticsearch common mistakes and Configuration Profile

 

A common mistake

1.1 root user to start elasticsearch error

         Elasticsearch For security reasons, not to be started as root, the solution is to create a new user, related operations by the user. If you start with a root, there will be " java.lang.RuntimeException: CAN not runelasticsearch AS root " error, as shown below:

 

 

1.2 JVM virtual machine memory shortage

        Error: " JavaHotSpot ((TM)) 64-Bit Server warning the VM: the INFO: error = 'Cannotallocate Memory' (errno = 12 is) " indicates insufficient memory, configured to jvm.options the config file directory defaults to 2g, can be modified to 1g.

 

1.3 max_map_count too small

        Error " max Virtual Memory Areas vm.max_map_count [65530] IS TOO Low, Increase to AT Least [262144] ", max_map_count file contains a number of restrictions process can have VMA (virtual memory area), the system default is 65530, modified to 262144. /Etc/sysctl.conf solution is to modify the configuration file, add vm.max_map_count = 262144, remember only works need to restart the machine, the modified configuration as shown below:

 

 

1.4 max file descriptors过小

        Error " max File descriptors [65535] for elasticsearchprocess IS TOO Low, Increase to AT Least [65536] ", maxfile descriptors for the maximum file descriptor, is set to greater than 65536. /Etc/security/limits.conf solution is to modify the file, adding "* - nofile65536 * - memlock unlimited ", "*" indicates to all users work, modified configuration as shown below:

 

 

1.5 external network access settings

         Observant students may find the first chapter of verification is "localhost: 9200", if changed to "IP: 9200", the browser can not be accessed with curl, then how to make external network access it? Online search a bit, we need to modify elasticsearch.yml file config directory, modify network.host as "0.0.0.0", and then start success outside the network can access it. But unfortunately, on my machine also appeared in other errors, as shown below:

 

 

By the above error message, you need to modify elasticsearch.yml think config file directory, modify discovery.zen.ping.unicast.hosts as "[" 0.0.0.0 "]", then start again, we found no error message (note for firewall restriction port), while the remote browser access is normal, as shown below:

 

 

 

Two, elasticsearch Configuration Introduction

         Configuration file in the config directory: jvm.options, elasticsearch.yml and log4j2.properties. Which jvm.options virtual machine configuration, log4j2.properties to log configuration are relatively simple. The following highlights some of the important elasticsearch.yml configuration items and their meanings.

(1)cluster.name: elasticsearch

         配置elasticsearch的集群名称,默认是elasticsearch。elasticsearch会自动发现在同一网段下的集群名为elasticsearch的主机,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。生成环境时建议更改。

(2)node.name: “node-1”

       节点名,默认随机指定一个name列表中名字,该列表在elasticsearch的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字,大部分是漫威动漫里面的人物名字。生成环境中建议更改以能方便的指定集群中的节点对应的机器

(3)node.master: true

         指定该节点是否有资格被选举成为node,默认是true,elasticsearch默认集群中的第一台启动的机器为master,如果这台机挂了就会重新选举master。

(4)node.data: true

        指定该节点是否存储索引数据,默认为true。如果节点配置node.master:false并且node.data: false,则该节点将起到负载均衡的作用

(5)index.number_of_shards: 5

        设置默认索引分片个数,默认为5片。经本人测试,索引分片对ES的查询性能有很大的影响,在应用环境,应该选择适合的分片大小。

(6)index.number_of_replicas:

         设置默认索引副本个数,默认为1个副本。此处的1个副本是指index.number_of_shards的一个完全拷贝;默认5个分片1个拷贝;即总分片数为10。

(7)path.conf: /path/to/conf

        设置配置文件的存储路径,默认是es根目录下的config文件夹。

(8)path.data:/path/to/data1,/path/to/data2

        设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开。

(9)path.logs: /path/to/logs

        设置日志文件的存储路径,默认是es根目录下的logs文件夹

(10)path.plugins: /path/to/plugins

       设置插件的存放路径,默认是es根目录下的plugins文件夹

(11)bootstrap.memory_lock: true

          设置为true来锁住内存。因为当jvm开始swapping时es的效率会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过ulimit -l unlimited命令。

(12)network.host: 192.168.0.1

       这个参数是用来同时设置bind_host和publish_host上面两个参数。

(13)http.port: 9200

        设置对外服务的http端口,默认为9200。

(14)gateway.recover_after_nodes: 1

        设置集群中N个节点启动时进行数据恢复,默认为1。

(15)discovery.zen.minimum_master_nodes: 1

       设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)

(16)discovery.zen.ping.timeout: 3s

        设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。

(17)discovery.zen.ping.multicast.enabled:false

        设置是否打开多播发现节点,默认是true。

(18)discovery.zen.ping.unicast.hosts: [“host1”, “host2:port”]

         设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。

 

参考:

  https://blog.csdn.net/qq_21387171/article/details/53577115

Guess you like

Origin www.cnblogs.com/caoweixiong/p/11078548.html