环境

主机名 IP 操作系统 ES 版本
es227 192.168.1.227 CentOS7.5 6.5.4
es228 192.168.1.228 CentOS7.5 6.5.4
es229 192.168.1.229 CentOS7.5 6.5.4

各节点初始配置

  • 关闭 selinux、防火墙
  • 部署 java 运行环境
  • 创建 elastic 用户

    1
    
    useradd -m elastic
  • 创建数据目录

    1
    2
    3
    
    cd /var/lib
    mkdir elasticsearch
    chown elastic.elastic elasticsearch
  • 创建日志目录

    1
    2
    3
    
    cd /var/log
    mkdir -p elasticsearch
    chown elastic.elastic elasticsearch
  • 增加 sysctl.conf 配置,执行 sysctl -p 生效

    1
    
    vm.max_map_count = 262144
  • 增加 /etc/security/limits.conf 配置

    1
    2
    3
    4
    
    elastic soft nofile 65536
    elastic hard nofile 65536
    elastic soft memlock unlimited
    elastic hard memlock unlimited

部署 ELASTICSEARCH

  • 登陆 es227,下载 elasticsearch,解压至 /opt/ 下
  • 修改 elasticsearch 目录的权限

    1
    
    chown -R elastic.elastic /opt/elasticsearch
  • 修改 jvm 参数文件 /opt/elasticsearch/config/jvm.options

  • 修改 /opt/elsaticsearch/config/elasticsearch.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    cluster.name: TEST_ES_CLUSTER
    node.name: es227
    network.host: 192.168.1.227
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    bootstrap.memory_lock: true
    discovery.zen.ping.unicast.hosts: ["192.168.1.227:9300", "192.168.1.228:9300", "192.168.1.229:9300"]
    discovery.zen.minimum_master_nodes: 2
    gateway.recover_after_nodes: 2
  • 打包 elasticsearch 目录,复制到 es228 和 es229 上,并修改 elasticsearch.yml

    1
    2
    3
    4
    5
    6
    
    # es228
    node.name: es228
    network.host: 192.168.1.228
    # es229
    node.name: es229
    network.host: 192.168.1.229

启动集群(两种启动方式)

  • 直接启动二进制
    • 在每个节点上启动 elasticsearch 服务

      1
      
      su - elastic -c '/opt/elasticsearch/bin/elasticsearch -d'
  • systemd 启动
    • 创建文件 /usr/lib/systemd/system/elasticsearch.service,内容如下

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      
      [Unit]
      Description=ElasticSearch
      Requires=network.service
      After=network.service
      [Service]
      User=elastic
      Group=elastic
      LimitNOFILE=65536
      LimitMEMLOCK=infinity
      Environment=JAVA_HOME=/opt/jre
      ExecStart=/opt/elasticsearch/bin/elasticsearch
      SuccessExitStatus=143
      [Install]
      WantedBy=multi-user.target
    • 启动 elasticsearch 服务

      1
      2
      
      systemctl daemon-reload
      systemctl start elasticsearch

查看集群状态

  • 查看集群节点状态

    1
    2
    3
    4
    
    # 查看节点状态
    curl http://192.168.1.228:9200/_cat/nodes?pretty
    # 查看集群状态
    curl http://192.168.1.228:9200/_cluster/state?pretty

安装分词插件

  • 登陆 es227,下载插件 elasticsearch-analysis-ik-6.5.4.zip 至根目录下
  • 复制该文件至 es228 和 es229 的根目录下
  • 每个节点上安装

    1
    2
    
    su - elastic
    /opt/elasticsearch/bin/elasticsearch-plugin install file:///elasticsearch-analysis-ik-6.5.4.zip
  • 配置远程扩展字典时,出现 java.net.SocketPermission 拒绝连接,此时需配置 jre 策略

    1
    2
    
    # vim /opt/jre/lib/security/java.policy,在最后一个 "}" 前追加下面一行
    permission java.net.SocketPermission "*:*","accept,connect,resolve";