Linux操作Elasticsearch7.16.2

Linux上操作Elasticsearch

Elasticsearch的安装

  • 安装环境
    JDK1.8
    Elasticsearch7.16.2

  • 下载es安装包
    Elasticsearch7.16.2下载地址

  • 上传到linux并解压

    tar -zxvf elasticsearch-7.16.2-linux-x86_64.tar.gz mv ../elasticsearch-7.16.2
    
    • 删除源码包
    rm -f elasticsearch-7.16.2-linux-x86_64.tar.gz 
    
  • 启动es
    es安装目录下执行

    ./bin/elasticsearch
    
  • 启动报错
    Exception in thread “main” java.nio.file.AccessDeniedException:
    因为es不能使用root用户启动,因此新建用户并赋权,切换到新建用户,然后启动

    adduser elastic
    chown -R elastic /usr/local/opt/elasticsearch-7.16.2/
    su elastic
    ./bin/elasticsearch
    
  • 原因是因为当前环境使用的是jdk8,es7以上自带jdk,对应的是jdk11,环境变量冲突,所以出现这个警告

    warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
    Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/opt/jdk1.8/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
    
  • 需要修改elasticsearch-env配置文件
    修改以下代码片段:

    # now set the path to java
    if [ ! -z "$ES_JAVA_HOME" ]; then
      JAVA="$ES_JAVA_HOME/bin/java"
      JAVA_TYPE="ES_JAVA_HOME"
    elif [ ! -z "$JAVA_HOME" ]; then
       fallback to JAVA_HOME
      echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
      JAVA="$JAVA_HOME/bin/java"
      JAVA_TYPE="JAVA_HOME"
    else
       # use the bundled JDK (default)
      if [ "$(uname -s)" = "Darwin" ]; then
        # macOS has a different structure
        JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
     else
        JAVA="$ES_HOME/jdk/bin/java"
      fi
      JAVA_TYPE="bundled JDK"
    fi
    

    将以上代码修改为

    if [ "$(uname -s)" = "Darwin" ]; then
    	    # macOS has a different structure
    	    JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
    	  else
    	    JAVA="$ES_HOME/jdk/bin/java"
    	  fi
    	  JAVA_TYPE="bundled jdk"
    
  • 修改esjvm大小
    -Xms256m
    -Xmx256m

    vim config/jvm.options
    
  • 启动报错

    ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
    bootstrap check failure [1] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    

    编辑 /etc/sysctl.conf
    最后添加vm.max_map_count=655360

    vim /etc/sysctl.conf
    

    保存后,执行:
    sysctl -p

  • 普通用户下启动
    执行命令启动后,执行命令查看是否启动成功

    curl 127.0.0.1:9200
    

    启动成功在这里插入图片描述

  • 设置外网访问

    vim /config/elasticsearch.yml
    

    添加以下内容,并且开放远程防火墙端口,如果是云服务器,需要设置安全组开放9200端口

    cluster.name: elasticsearch
    node.name: node-1
    path.data: /usr/local/opt/elasticsearch-7.16.2/data
    path.logs: /usr/local/opt/elasticsearch-7.16.2/logs
    network.host: 0.0.0.0
    http.port: 9200
    cluster.initial_master_nodes: ["node-1"]
    
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值