美文网首页
centos7 安装elasticsearch5.6.8

centos7 安装elasticsearch5.6.8

作者: 狗子家的铲屎官 | 来源:发表于2018-12-06 15:14 被阅读0次

    一、下载安装

    • 下载
      到官网找到对应版本的下载链接,用wget命令下载 下载地址
    [root@localhost es]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
    --2018-12-05 16:29:27--  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.8.tar.gz
    正在解析主机 artifacts.elastic.co (artifacts.elastic.co)... 54.225.221.128, 107.21.127.184, 107.21.202.15, ...
    正在连接 artifacts.elastic.co (artifacts.elastic.co)|54.225.221.128|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:33781024 (32M) [binary/octet-stream]
    正在保存至: “elasticsearch-5.6.8.tar.gz”
    
    100%[=================================================================>] 33,781,024  1.14MB/s 用时 30s    
    
    2018-12-05 16:29:59 (1.06 MB/s) - 已保存 “elasticsearch-5.6.8.tar.gz” [33781024/33781024])
    
    • 解压
    [root@localhost es]# tar -zxf elasticsearch-5.6.8.tar.gz
    
    • 建立软链接
      习惯建一个目录管理所有应用的软件界(为了个人方便而已)
    [root@localhost /]# ln -s /develop/es/elasticsearch-5.6.8/ /shortcut/es
    [root@localhost /]# cd shortcut/
    [root@localhost shortcut]# ll
    总用量 0
    lrwxrwxrwx. 1 root root 32 12月  5 16:56 es -> /develop/es/elasticsearch-5.6.8/
    
    • 新建用户
      es 5以上都不允许用root用户启动,如果用root启动会出现以下错误:can not run elasticsearch as root
    [root@localhost elasticsearch-5.6.8]# bin/elasticsearch
    [2018-12-05T16:40:00,801][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:136) ~[elasticsearch-5.6.8.jar:5.6.8]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.8.jar:5.6.8]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.8.jar:5.6.8]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.8.jar:5.6.8]
    ...
    

    新建一个叫es用户,并为es设置密码

    [root@localhost es]# useradd es
    [root@localhost es]# passwd es
    

    给es账号赋权

    [root@localhost es]# chown -R es /develop/es/elasticsearch-5.6.8
    
    • 启动es
    [es@localhost es]$bin/elasticsearch
    [2018-12-06T11:29:07,535][INFO ][o.e.n.Node               ] [] initializing ...
    [2018-12-06T11:29:17,825][INFO ][o.e.h.n.Netty4HttpServerTransport] [5nNJgP4] 
    publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
    [2018-12-06T11:29:17,825][INFO ][o.e.n.Node               ] [5nNJgP4] started
    

    这样子变启动成功了。 可以访问对应的127.0.0.1:9200 看到以下结果:

    [root@localhost ~]# curl 127.0.0.1:9200
    {
      "name" : "5nNJgP4",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "aek3sfxyRjeMfvgrK-jB0Q",
      "version" : {
        "number" : "5.6.8",
        "build_hash" : "688ecce",
        "build_date" : "2018-02-16T16:46:30.010Z",
        "build_snapshot" : false,
        "lucene_version" : "6.6.1"
      },
      "tagline" : "You Know, for Search"
    }
    

    这时候es就算安装成功了。

    • 设置为可被外部访问的ip
      这时候并不能用ip访问es,如下图
    [root@localhost es]# curl 192.168.24.152::9200
    curl: (6) Could not resolve host: 192.168.24.152:; 未知的名称或服务
    

    所以需要修改对应配置文件信息

    1. 修改elasticsearch.yml,设置host 跟port
    [root@localhost ~]# vim /develop/es/elasticsearch-5.6.8/config/elasticsearch.yml 
    
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 0.0.0.0
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    #
    # For more information, consult the network module documentation.
    #
    
    
    1. 这时候启动会遇到下面问题
    [2018-12-06T14:01:48,138][INFO ][o.e.b.BootstrapChecks    ] [5nNJgP4] bound or publishing to a 
    non-loopback address, enforcing bootstrap checks
    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]
    

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

    原因:无法创建本地文件问题,用户最大可创建文件数太小
    解决方案:
    切换到root用户,编辑limits.conf配置文件, 添加类似如下内容:
    vim /etc/security/limits.conf
    添加如下内容:

    * hard nofile 65536
    * soft nofile 65536
    

    备注: * 代表Linux所有用户名称(比如 es)保存、退出、重新登录才可生效

    [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    原因:最大虚拟内存太小
    解决方案:切换到root用户下,修改配置文件sysctl.conf
    vim /etc/sysctl.conf
    添加下面配置

    vm.max_map_count=655360
    

    并执行

    [root@localhost ~]# sysctl -p
    vm.max_map_count = 655360
    

    注意:这时候还不能访问需要关闭防火墙或者开放9200端口
    centos7防火墙设置

    • 问题解决
    [root@localhost es]# curl 192.168.24.152:9200
    {
      "name" : "5nNJgP4",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "aek3sfxyRjeMfvgrK-jB0Q",
      "version" : {
        "number" : "5.6.8",
        "build_hash" : "688ecce",
        "build_date" : "2018-02-16T16:46:30.010Z",
        "build_snapshot" : false,
        "lucene_version" : "6.6.1"
      },
      "tagline" : "You Know, for Search"
    }
    
    

    相关文章

      网友评论

          本文标题:centos7 安装elasticsearch5.6.8

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