美文网首页bugstac...
elasticsearch6.3.2 安装

elasticsearch6.3.2 安装

作者: 番薯IT | 来源:发表于2018-08-14 18:34 被阅读189次

    环境

    • CentOS7
    • 请确保已经安装了jdk1.8或更高的版本

    下载

    选择要下载的,我下载的是TAR。按需要下载。

    image.png

    解压

    我已经将安装包放在了usr/local/software目录下。

    [root@localhost software]# pwd
    /usr/local/software
    [root@localhost software]# ls
    elasticsearch-6.3.2.tar.gz
    

    解压安装包,得到 elasticsearch-6.3.2

    tar -zxvf elasticsearch-6.3.2.tar.gz 
    

    我将elasticsearch-6.3.2移动到了usr/local/dev-env目录下。

    [root@localhost dev-env]# pwd
    /usr/local/dev-env
    [root@localhost dev-env]# mv /usr/local/software/elasticsearch-6.3.2  elasticsearch-6.3.2
    [root@localhost dev-env]# ls
    elasticsearch-6.3.2  jdk1.8.0_181
    

    启动异常

    当我在elastic下执行./bin/elasticsearch,启动elastic的时候,报了一下错误:

    [2018-08-09T18:11:32,675][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:140) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
            at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
            at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
            at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
            ... 6 more
    

    创建用户

    从上面可以看出,我们不能用root来启动es,那么我们就新建一个用户

    # 添加用户 elastic
    adduser elastic
    
    # 给用户elastic设置密码,按照提示输入自己的密码
    passwd elastic
    
    # 设置权限
    chown -R elastic /usr/local/dev-env/elasticsearch-6.3.2
    
    # 切换用户
    su elastic
    
    # 查看权限
    ll
    

    启动elasticsearch

    ./bin/elasticsearch
    
    ## 以守护进程在后台运行
    ./bin/elasticsearch -d 
    

    测试启动结果

    执行以下操作,查看输出

    curl 'http://localhost:9200'
    

    当然在执行时,可能会碰到下面问题

    curl: (7) Failed connect to localhost:9200; Connection refused
    

    我们只需要关闭防火墙

    service firewalld stop
    

    然后再运行,我们可以看到输出如下内容:

    {
      "name" : "7KfHH2X",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "XihaCbM2Q9Sk3w6yJRhHEw",
      "version" : {
        "number" : "6.3.2",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "053779d",
        "build_date" : "2018-07-20T05:20:23.451332Z",
        "build_snapshot" : false,
        "lucene_version" : "7.3.1",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    外部访问

    上面的设置只能在本地上能访问。我的linux是按照在虚拟机上的,现在我要在电脑的浏览器上访问。我们发现是不行的。那么我们需要新的设置

    修改elasticsearch目录下的config/elasticsearch.yml文件

    # 设置所有ip都能访问
    network.host: 0.0.0.0
    
    http.port: 9200
    

    其他问题

    当我们设置好上面的配置是,又出现了其他的问题,下面一个个的处理

    ERROR: [2] bootstrap checks failed
    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    

    上面出现了两个问题,我们一个个的处理。我们先切回到root用户。

    • 问题 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

    修改文件/etc/security/limits.conf,在其后面追加如下内容:

    * soft nofile 65536
    * hard nofile 65536
    
    • 问题 [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
    

    使用命令 sysctl -p 使刚才的设置生效。

    最后,我们切换到elastic用户,并启动服务./bin/elasticsearch,我们发现启动成功,并且能在其他的机器上访问到es了。

    相关文章

      网友评论

        本文标题:elasticsearch6.3.2 安装

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