集群规划:

node01
node02
node03
node04
node05

前置准备请参考(主要是jdk 和 免密登录):

https://www.cnblogs.com/ronnieyuan/p/11518913.html

https://www.cnblogs.com/ronnieyuan/p/11461377.html

Elasticsearch 的安装

  1. 上传tar包并解压:

    tar -zxvf elasticsearch-7.3.2-no-jdk-linux-x86_64.tar.gz  -C /opt/ronnie/
  2. 修改配置文件

    cd /opt/ronnie/elasticsearch-7.3.2/config/
    
    vim elasticsearch.yml

    需要修改的配置:

    # 集群名
    cluster.name: ronnie-es
    
    # 节点名 我这是5台虚拟机, 所以分别是node-1 到 node-5
    node.name: node-1
    
    # 主机名
    network.host: 192.168.180.130
    
    # http连接端口, ps: 9300为集群内部通信端口
    http.port: 9200
    # 比较新的版本不需要配置多波和防脑裂
    discovery.zen.ping_timeout: 120s
    client.transport.ping_timeout: 60s
    discovery.zen.ping.unicast.hosts: ["192.168.180.130","192.168.180.131","192.168.180.132","192.168.180.133","192.168.180.134"]
    # 初始主节点
    cluster.initial_master_nodes: ["node-1"]
    
  3. 将elasticsearch目录发送给其他4台虚拟机

    scp -r /opt/ronnie/elasticsearch-7.3.2/ [email protected]:/opt/ronnie/
    scp -r /opt/ronnie/elasticsearch-7.3.2/ [email protected]:/opt/ronnie/
    scp -r /opt/ronnie/elasticsearch-7.3.2/ [email protected]:/opt/ronnie/
    scp -r /opt/ronnie/elasticsearch-7.3.2/ [email protected]:/opt/ronnie/

    修改elasticsearch.yml文件中对应的节点名和主机名

  4. 修改系统配置文件

    vim ~/.bashrc, 添加ES_HOME路径

    # elasticsearch
    export ES_HOME=/opt/ronnie/elasticsearch-7.3.2
    export PATH=$ES_HOME/bin:$PATH

    使修改后的配置生效: source ~/.bashrc, 在命令行下可以tab出elasticsearch即配置成功

  5. 这时候启动会报一个错: org.elasticsearch.bootstrap.StartupException:java.lang.RuntimeException: can not run elasticsearch as root

    • 原因是es 不允许使用root权限运行, 以前发生过生产事故。
  • 所以我们需要创建一个非root用户来运行es

    groupadd es
    useradd es -g es -p 123456
    
    cd /opt/ronnie
    chown -R es:es elasticsearch-7.3.2/
    # 切换为es用户
    su es
  1. 启动报错

    # 说明可控的虚拟内存太小了, 需要调整虚拟内存
    max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    • su root 切换到root用户

    • 执行命令:

      sysctl -w vm.max_map_count=262144
    • 再切换回非root用户启动

    • 可以看到一个个节点信息被注册到主节点

      [2019-12-19T13:21:33,355][INFO ][o.e.l.LicenseService     ] [node-1] license [f1827ea0-c747-4151-98ec-e5db1b56ee14] mode [basic] - valid
      [2019-12-19T13:21:33,357][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1] Active license is now [BASIC]; Security is disabled
      [2019-12-19T13:21:35,056][INFO ][o.e.c.s.MasterService    ] [node-1] node-join[{node-2}{fccTE81jSGyFi6UAqI3pJA}{Ei_BMkwPR1S3P577Oy85yA}{192.168.180.131}{192.168.180.131:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true} join existing leader], term: 1, version: 16, reason: added {{node-2}{fccTE81jSGyFi6UAqI3pJA}{Ei_BMkwPR1S3P577Oy85yA}{192.168.180.131}{192.168.180.131:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}
      [2019-12-19T13:21:35,781][INFO ][o.e.c.s.ClusterApplierService] [node-1] added {{node-2}{fccTE81jSGyFi6UAqI3pJA}{Ei_BMkwPR1S3P577Oy85yA}{192.168.180.131}{192.168.180.131:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}, term: 1, version: 16, reason: Publication{term=1, version=16}
      [2019-12-19T13:21:36,120][INFO ][o.e.c.s.MasterService    ] [node-1] node-join[{node-3}{iYSKZYruQziDaukE38R9Hg}{731BcyNzTfmLsxoLUkVcsA}{192.168.180.132}{192.168.180.132:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true} join existing leader], term: 1, version: 17, reason: added {{node-3}{iYSKZYruQziDaukE38R9Hg}{731BcyNzTfmLsxoLUkVcsA}{192.168.180.132}{192.168.180.132:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}
      [2019-12-19T13:21:36,645][INFO ][o.e.c.s.ClusterApplierService] [node-1] added {{node-3}{iYSKZYruQziDaukE38R9Hg}{731BcyNzTfmLsxoLUkVcsA}{192.168.180.132}{192.168.180.132:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}, term: 1, version: 17, reason: Publication{term=1, version=17}
      [2019-12-19T13:21:37,385][INFO ][o.e.c.s.MasterService    ] [node-1] node-join[{node-4}{qgdThjgcS02z55uB6RAXJg}{TVdEG16wSA-8r9HNfjMrjg}{192.168.180.133}{192.168.180.133:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true} join existing leader], term: 1, version: 19, reason: added {{node-4}{qgdThjgcS02z55uB6RAXJg}{TVdEG16wSA-8r9HNfjMrjg}{192.168.180.133}{192.168.180.133:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}
      [2019-12-19T13:21:37,844][INFO ][o.e.c.s.ClusterApplierService] [node-1] added {{node-4}{qgdThjgcS02z55uB6RAXJg}{TVdEG16wSA-8r9HNfjMrjg}{192.168.180.133}{192.168.180.133:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}, term: 1, version: 19, reason: Publication{term=1, version=19}
      [2019-12-19T13:21:37,848][INFO ][o.e.c.s.MasterService    ] [node-1] node-join[{node-5}{3LkyJBolQAK-MQ9msg60ow}{AB15qo9QQJCi3smFB4WhnQ}{192.168.180.134}{192.168.180.134:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true} join existing leader], term: 1, version: 20, reason: added {{node-5}{3LkyJBolQAK-MQ9msg60ow}{AB15qo9QQJCi3smFB4WhnQ}{192.168.180.134}{192.168.180.134:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}
      [2019-12-19T13:21:38,257][INFO ][o.e.c.s.ClusterApplierService] [node-1] added {{node-5}{3LkyJBolQAK-MQ9msg60ow}{AB15qo9QQJCi3smFB4WhnQ}{192.168.180.134}{192.168.180.134:9300}{dim}{ml.machine_memory=3781853184, ml.max_open_jobs=20, xpack.installed=true},}, term: 1, version: 20, reason: Publication{term=1, version=20}
    • 通过浏览器访问9200端口:

12-17 05:03