elasticsearch6.x集群安装部署

es 集群部署

操作系统为centos7.6
集群规模:3

软件包准备

说明:jdk版本不能低于1.8,推荐使用openjdk

软件包 版本 下载地址
elasticsearch 6.2.3 https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.rpm
openjdk 9.0.4 https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz

部署步骤

三个节分别安装jdk和es服务

在三个节点上分别安装jdk和elasticsearch服务,并以单节点的形式启动服务,验证服务是否正常安装

  1. 解压jdk:
    tar -zxvf openjdk-9.0.4_linux-x64_bin.tar.gz
  2. 安装elasticsearch
    rpm -ivh elasticsearch-6.2.3.rpm
  3. 给elasticsearch指定JAVA_HOME
    vi /etc/sysconfig/elasticsearch
# Elasticsearch Java path
JAVA_HOME=/opt/jdk-9.0.4
  1. 修改elasticsearch的服务为开机自启动
    systemctl enable elasticsearch.service
  2. 启动elasticsearch服务
    systemctl start elasticsearch
  3. 验证es服务是否可用
curl http://localhost:9200
{
  "name" : "node-3",
  "cluster_name" : "my-application",
  "cluster_uuid" : "_na_",
  "version" : {
    "number" : "6.2.3",
    "build_hash" : "c59ff00",
    "build_date" : "2018-03-13T10:06:29.741383Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
  1. 如果es服务启动失败,请到/var/log/elasticsearch/var/log/messages下查看错误信息
独立的3个es节点组成集群

到此3个节点的es只是单独存在的,还没有形成一个集群,需要调整配置使其形成集群

  1. 修改/etc/elasticsearch/elasticsearch.yml的相关参数
参数 说明
cluster.name 三个节点的cluster.name参数必须保持一致
node.name 每个节点的node.name必须唯一
network.host 本节点bind的ip
discovery.zen.ping.unicast.hosts 三个节点的ip数组,用于es集群节点的自动发现
discovery.zen.minimum_master_nodes To avoid a split brain, this setting should be set to a quorum of master-eligible nodes:
(master_eligible_nodes / 2) + 1

举例:

# Use a descriptive name for your cluster:
cluster.name: my-application
# Use a descriptive name for the node:
node.name: node-3
# Set the bind address to a specific IP (IPv4 or IPv6):
network.host: 10.0.44.47
# The default list of hosts is ["127.0.0.1", "[::1]"]
discovery.zen.ping.unicast.hosts: ["10.0.44.45", "10.0.44.46","10.0.44.47"]
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
discovery.zen.minimum_master_nodes: 2
  1. 修改jvm参数/etc/elasticsearch/jvm.options
    建议-Xms -Xmx修改值为物理内存的50%,比如虚机内存是4G,则-Xms -Xmx参数值设置成2G
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
  1. 其他重要参数修改
    • 数据目录配置path.data,rpm安装完默认值是/var/lib/elasticsearch,建议设置独立的数据盘,并把该参数改完数据盘的目录

操作系统参数设置

  • 关闭swap
    • 执行命令:swapoff -a
    • 释掉/etc/fstab包含swap相关的行
    • 执行命令sysctl vm.swappiness=1
    • /etc/sysctl.conf 文件里添加vm.swappiness=1

你可能感兴趣的:(elasticsearch,大数据,elasticsearch,java)