• Elasticsearch系列-安装部署


    Elasticsearch系列-安装部署

    准备

    1.服务器创建es用户

    useradd es
    passwd es
    
    • 1
    • 2

    2.elasticsearch部署环境JDK

    3.安装包
    可以去elastic官网下载相应版本文件。我这里安装版本的是7.12.0。
    Linux版本:

    //centos下若没有安装curl 
    yum install curl
    //进入es用户目录执行下载
    curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz
    
    • 1
    • 2
    • 3
    • 4

    安装

    解压下载的压缩文件

    tar -xzvf elasticsearch-7.12.0-linux-x86_64.tar.gz 
    
    • 1

    启动elasticsearch

    cd elasticsearch-7.12.0/bin/
    ./elasticsearch &
    
    • 1
    • 2

    访问elasticsearch

    curl http://127.0.0.1:9200
    
    //返回信息
    {
      "name" : "izwz9ja3exxb7by25st5gbz",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "hD8cxBoIRvW6tZUEIFMTUQ",
      "version" : {
        "number" : "7.12.0",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "78722783c38caa25a70982b5b042074cde5d3b3a",
        "build_date" : "2021-03-18T06:17:15.410153305Z",
        "build_snapshot" : false,
        "lucene_version" : "8.8.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    集群启动:
    修改配置文件

    vim elasticsearch.yml
    
    //配置集群名称
    cluster.name: elasticsearch
    //配置节点名称
    node.name: node-1
    //配置数据存放路径
    path.data: /path/to/data
    //配置日志存放路径
    path.logs: /path/to/logs
    //配置访问地址 所有机器可访问 则配置为0.0.0.0 
    network.host: 0.0.0.0
    //配置访问端口
    http.port: 9200
    //配置集群扫描地址
    discovery.seed_hosts: ["172.18.88.96", "127.0.0.1"]
    //配置集群节点主节点竞选的节点
    cluster.initial_master_nodes: ["node-1", "node-2"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    启动集群节点

    ./elasticsearch -Epath.data=data1 -Epath.logs=log1 -Enode.name=node-1 -d
    ./elasticsearch -Epath.data=data2 -Epath.logs=log2 -Enode.name=node-2 -d
    ./elasticsearch -Epath.data=data3 -Epath.logs=log3 -Enode.name=node-3 -d
    
    • 1
    • 2
    • 3

    查看集群健康信息:
    curl http://localhost:9200/_cluster/health
    curl http://localhost:9200/_cat/healthv=true
    查看节点列表
    curl http://localhost:9200/_cat/nodes
    查看节点信息
    curl http://localhost:9200/_nodes/transportpretty

    错误

    1. 启动报错 error=‘Cannot allocate memory’

      warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
      warning: ignoring JAVA_OPTS= -Djava.security.egd=file:/dev/./urandom; pass JVM parameters via ES_JAVA_OPTS
      Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_171/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.
      warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
      warning: ignoring JAVA_OPTS= -Djava.security.egd=file:/dev/./urandom; pass JVM parameters via ES_JAVA_OPTS
      Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_171/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.
      Exception in thread “main” java.lang.RuntimeException: starting java failed with [1]
      output:

      There is insufficient memory for the Java Runtime Environment to continue.

      Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.

      An error report file with more information is saved as:

      logs/hs_err_pid27324.log

      error:
      Java HotSpot™ 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error=‘Cannot allocate memory’ (errno=12)
      at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
      at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
      at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
      at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
      at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)

    解决方法:
    修改config目录下的配置文件jvm.options

    ################################################################
    ## IMPORTANT: JVM heap size
    ################################################################
    ##
    ## The heap size is automatically configured by Elasticsearch
    ## based on the available memory in your system and the roles
    ## each node is configured to fulfill. If specifying heap is
    ## required, it should be done through a file in jvm.options.d,
    ## and the min and max should be set to the same value. For
    ## example, to set the heap to 4 GB, create a new file in the
    ## jvm.options.d directory containing these lines:
    ##
    ## -Xms4g
    ## -Xmx4g
    ##
    ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
    ## for more information
    ##
    ################################################################
    # 按自己机器内存情况配置
    -Xms128m
    -Xmx128m
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    1. 启动报错:can not run elasticsearch as root

      [2021-04-09T10:26:01,627][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [izwz9ja3exxb7by25st5gbz] uncaught exception in thread [main]
      org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.12.0.jar:7.12.0]
      at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.12.0.jar:7.12.0]
      Caused by: java.lang.RuntimeException: can not run elasticsearch as root
      at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397) ~[elasticsearch-7.12.0.jar:7.12.0]
      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.12.0.jar:7.12.0]
      … 6 more
      uncaught exception in thread [main]
      java.lang.RuntimeException: can not run elasticsearch as root
      at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:101)
      at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:168)
      at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397)
      at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
      at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
      at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
      at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
      at org.elasticsearch.cli.Command.main(Command.java:79)
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
      at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
      For complete error details, refer to the log at /root/elasticsearch-7.12.0/logs/elasticsearch.log

    解决方法:
    创建es用户

    创建es 用户
    useradd es
    创建es用户密码  changeme
    passwd es
    分配es用户 安装文件夹权限
    chown -R es elasticsearch-7.12.0
    切换到es 用户
    su es
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1. 启动报错“Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker”
      解决方法:因为elasticsearch目录在root下面,将elasticsearch安装文件拷贝到es用户目录下

    2. 启动报错“AccessDeniedException[/home/es/elasticsearch-7.12.0/config/elasticsearch.yml]”
      解决方法:因为elasticsearch目录没有权限,读取不到配置文件,授权操作一下

      chown -R es elasticsearch-7.12.0

    3. 启动报错 “ERROR: [2] bootstrap checks failed”
      [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
      [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    解决方法:

    修改配置文件
    vim /etc/sysctl.conf
    在文件最后加上
    vm.max_map_count=262144
    保存文件后 刷新文件生效
    sysctl -p
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    JavaScript基本数据类型
    Linux命令`ll`的结果解析
    Linux系统编程-进程等待
    Python也可以实现Excel中的“Vlookup”函数
    Android实验:Activity界面基础
    组件化开发之如何封装组件-react
    应对数据爆炸时代,揭秘向量数据库如何成为AI开发者的新宠,各数据库差异对比
    Codeforces Round #812 (Div. 2)
    ESP32S3的ESP_LOGx()控制台输出详细介绍
    【高并发】通过源码深度分析线程池中Worker线程的执行流程
  • 原文地址:https://blog.csdn.net/m0_67402564/article/details/126362693