美文网首页BigData
Linux 环境下 ElasticSearch 6.0.1 集群

Linux 环境下 ElasticSearch 6.0.1 集群

作者: FireflyWang | 来源:发表于2017-12-14 21:58 被阅读84次

    1.下载

    下载地址于 https://www.elastic.co/downloads/elasticsearch , 当时下载是 6.0.1 版本, 目前 (2017.12.14) 为 6.1.0 版本,以下是否适用,不予验证。

    此版本为编译好的版本,因此无需重新编译。

    2. 安装

    安装比较简单,因为上面下载的.zip版本为编译好的版本,因此无需重新编译,需要注意的是安装环境。

    安装完毕后,进入es目录,即

    cd $ES_HOME (即elasticsearch安装目录)
    bin/elasticsearch
    

    即可启动,启动后可能有各种问题,见 3. 注意事项

    下面附属笔者的环境:

    1. Linux 2.6 (CentOS rebuild)
    2. JDK 1.8.0_144

    3. 注意事项

    • 请修改 config/elasticsearch.yml 中的 cluster.name, 此key是用来标识集群名的,比如 cluster.name:index_search_for_dev
    • 请修改 config/elasticsearch.yml 中的 network.host, 此key标识机器的网络地址,默认是回环地址需要修改,比如
      network.host:${外网IP}
    • JDK的版本需在1.8版本及以上
    • 如果启动的时候出现 java.lang.UnsupportedOperationException: seccomp unavailable 异常,有几个选择 (1) 忽略它,因为es尝试使用seccomp来加速启动,但是因为linux内核版本过低 ( < Linux3.2) 不支持,不会影响es的启动和功能。 (2) 升级linux内核 (3) 通过配置文件关闭它,修改config/elasticsearch.yml配置中的bootstrap.system_call_filter: false来关闭启动的seccomp功能
    • 如果启动时出现 max file decriptors [4096] for elasticsearch process is too low, increase to at least [65536] 错误, 那么就需要ulimit -n查看一下文件描述符,默认是1024 切换到root账户,编辑 /etc/security/limits.conf 文件,添加两行
    * soft    nofile    65536
    * hard    nofile    65536
    

    直接重新登陆用ulimit -n就能看到效果(笔者这边需要一次切换用户才起效力)

    • 如果启动出现 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 错误, 需要使用root用户修改 /etc/sysctl.conf 文件, 添加:
    vm.max_map_count=655360
    

    然后执行命令:

    sysctl -p
    

    4. 集群部署

    如果是单机部署,以上就可以使用了, 但是集群部署需要重新配置一下

    配置文件(建议, 参考 https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html):

    node.name: ${HOSTNAME}
    network.host: 设置为当前主机的IP(Non-loopback)
    discovery.zen.ping.unicast.hosts:[ip1,ip2,domain3,hostname4](提供几个集群内主机IP,按官方说法,只是 seeds, 无需全部)
    master_eligible_nodes=有资格被设置为主节点的节点数/2 + 1 (有资格被设置为主节点的配置为node.master=true,也是默认设置为均可,这是为了防止集群脑裂的)
    

    使用 SCP SSH复制命令进行集群部署

    scp -r $LOCAL_DIR $REMOTE_IP:$REMOTE_DIR 
    

    启动节点,会有 with same id 错误,因为node-id使用了data目录下的文件进行了Hash,因此只需要将data目录下的文件全部删除,启动即可,具体原因参考 https://github.com/elastic/elasticsearch/issues/21405

    具体的SSH免密登录方式,请查看
    http://www.cnblogs.com/lzxlfly/p/7221890.html

    5. 验证

    ElasticSearch 提供了RestAPI (9200端口, 默认), 因此使用curl命令可进行连接

    curl -XGET -H 'Content-type:application/json' 'http://IP:PORT/_cluster/health'
    

    参考资料

    1. https://github.com/elastic/elasticsearch/issues/21405 关于node-id的讨论
    2. https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html ES官方配置指南
    3. https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html 其他环境的安装参考
    4. https://www.cnblogs.com/sloveling/p/elasticsearch.html 前人路过的坑

    相关文章

      网友评论

        本文标题:Linux 环境下 ElasticSearch 6.0.1 集群

        本文链接:https://www.haomeiwen.com/subject/ykpocttx.html