Elasticsearch6.4安装

下载地址:https://www.elastic.co/cn/downloads 假设系统安装好了对应的jdk,且jdk的版本要高于8。下面是具体的安装步骤。

  • 解压下载的安装包,命令如下:
tar -xzvf elasticsearch-6.4.3.tar.gz
  • 增加一个新用户和用户组:因为elasticsearch有远程执行脚本的功能所以容易中木马病毒,不允许用root用户启动,赋权限,用一般的用户启动。命令如下:
groupadd elasticsearch
useradd elasticsearch -g elasticsearch
chown -R elasticsearch:elasticsearch /home/ivan/elasticsearch-6.4.3/
  • 修改config目录下的elasticsearch.yml文件,具体的配置如下:
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
#集群的名称
#
cluster.name: ivan_test
#
# ------------------------------------ Node ------------------------------------
#
# 节点的名称
#
node.name: package4
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
#配置你存数据的目录
#
path.data: /home/ivan/elasticsearch-6.4.3/data
#
# 配置你存日志的目录
#
path.logs: /home/ivan/elasticsearch-6.4.3/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup: 这两个配置用于解决下面的问题,否则会报错
#
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#需要配置成本面的ip,否则外部无法访问
#
network.host: 对应机器的ip
#
# Set a custom port for HTTP:
#
#http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
  • 通过bin目录下的elasticsearch启动应用

安装期间踩的坑

1: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

  • 解决办法: 切换回root用户并通过vim /etc/security/limits.conf 命令修改系统的配置文件
#增加如下两行
* hard nofile 65536
* soft nofile 65536

注:ubuntu下需要通过ulimit -n 65536 命令 2: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [4096]

  • 解决办法: 切换回root用户并通过vim /etc/security/limits.d/90-nproc.conf 修改文件,增加如下行:
*          soft    nproc     4096

3: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

  • 解决办法: 切换回root用户并通过vim /etc/sysctl.conf 修改文件,添加下面配置:
vm.max_map_count=655360

并执行命令:sysctl -p 4: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

  • 解决办法: 修改elasticsearch.yml文件里的配置,增加如下两个配置:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

5:the minimum required Java version is 8; your Java version from [/usr/local/java/jdk7/jre] does not meet this requirement。

  • 解决办法,当linux机器里安装了多个jdk时, 而启动报这人错,说明没应用path下的jdk,可以通过修改config目录下的elasticsearch-env文件,指定用那个jdk启动
export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export PATH=${JAVA_HOME}/bin:$PATH

6:正常启动后,通过远程机器无法访问,

  • 解决办法:首先通过curl确认本地是可以访问的,修改elasticsearch.yml文件里的配置,增加如下两个配置:
http.cors.enabled: true
http.cors.allow-origin: "*"

如果还没办法访问, 注意系统的防火墙,可能通过如下命令关闭:

service iptables stop

集群安装

ES是去中心化,字面上理解就是无中心节点,这是对于集群外部来说的,因为从外部来看ES集群,在逻辑上是个整体,你与任何一个节点的通信和与整个ES集群通信是等价的。但在ES集群内部有如下三种角色:

  • master node:主要用于元数据(metadata)的处理,管理集群状态,包括管理分片的状态和副本的状态,以及节点的发现和删除、分片分配等。
  • data node:节点上保存了数据分片。它负责数据相关操作,比如分片的 CRUD,以及搜索和整合操作。
  • client node: 节点起到路由请求的作用,实际上可以看做负载均衡器。 根据每台机器的角色,修改下面四个配置,其中node.master与node.data的值根据实际情况进行修改。discovery.zen.ping.unicast.hosts:用于配置集群里的ip.
node.master: true 
node.data: true
discovery.zen.ping.unicast.hosts: ["IP1", "IP2", "IP3"]
discovery.zen.minimum_master_nodes: 1 #用来配置主节点的最小值
遇到的问题

1:failed to send join request to master

  • 解决办法:集群安装过程难免会相互拷文件,在copy文件的时候, 需要把data目录下的文件删除了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章