美文网首页程序员
Elasticsearch的安装部署

Elasticsearch的安装部署

作者: 南南宫问天 | 来源:发表于2020-06-17 21:49 被阅读0次

    Elasticsearch的特点

    1)可以作为一个大型分布式集群(数百台服务器)技术,处理PB级数据,服务大公司,也可以运行在在单击上,服务小公司
    2)elasticsearch不是什么新技术,主要是将全文检索,数据分析以及分布式技术,合并一起,才形成了独一无二的ES,lucene(全文检索)
    3)对用户而言,是开箱即用的,非常简单,作为中小型的应用,直接3分钟部署一下ES,就可以作为生产环境的系统来使用了,数据量不大,操作不是太复杂.
    4)数据库的功能面对很多领域是不够的,优势,事务,各种联机事物型的操作,特殊的功能,比如全文检索,同义词处理,相关度排名,复杂数据分析,海量数据的近实时处理,Elasticsearch作为传统数据库的一个补充,提供了数据库所不能提供的很多功能

    Elasticsearch安装部署

    安装方式:

    image.png

    开始部署:

    1.安装java环境

    [root@db01 ~]# yum install -y java-1.8.0-openjdk
    

    2.创建软件目录并拉取软件

    [root@db01 ~]# mkdir /data/soft -p
    https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.rpm
    [root@db01 soft]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.rpm ##如果拉取不到的话也可以用浏览器实现下载好再上传到服务器
    

    3.使用rpm安装elasticsearch

    [root@db01 soft]# rpm -ivh elasticsearch-6.6.0.rpm 
    警告:elasticsearch-6.6.0.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY
    准备中...                         ################################# [100%])
    Creating elasticsearch group... OK
    Creating elasticsearch user... OK
    正在升级/安装...
       1:elasticsearch-0:6.6.0-1                                            (  ################################# [100%]
    ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
     sudo systemctl daemon-reload
     sudo systemctl enable elasticsearch.service
    ### You can start elasticsearch service by executing
     sudo systemctl start elasticsearch.service
    Created elasticsearch keystore in /etc/elasticsearch
    

    4.启动elasticsearch

    [root@db01 soft]# sudo systemctl daemon-reload
    [root@db01 soft]# sudo systemctl enable elasticsearch.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
    [root@db01 soft]# sudo systemctl start elasticsearch.service
    

    5.检查服务是否启动成功

    [root@db01 soft]# netstat -lntup | grep 9200 ###只要9200端口打开,代表启动成功了
    tcp6       0      0 127.0.0.1:9200          :::*                    LISTEN      21699/java          
    tcp6       0      0 ::1:9200                :::*                    LISTEN      21699/java    
    [root@db01 soft]# curl 127.0.0.1:9200 ##也可以curl下页面查看情况
    {
      "name" : "NQSWGpj",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "fPKluz4TSAi7V3I0y2PhPQ",
      "version" : {
        "number" : "6.6.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "a9861f4",
        "build_date" : "2019-01-24T11:27:09.439740Z",
        "build_snapshot" : false,
        "lucene_version" : "7.6.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    相关配置文件

    [root@db01 ~]# rpm -qc elasticsearch 
    /etc/elasticsearch/elasticsearch.yml  ##ES主配置文件
    /etc/elasticsearch/jvm.options        ##jvm虚拟机配置
    /etc/init.d/elasticsearch             ##init的启动文件 
    /etc/sysconfig/elasticsearch          ##环境变量相关参数
    /usr/lib/sysctl.d/elasticsearch.conf  ##jvm相关配置
    /usr/lib/systemd/system/elasticsearch.service  ##system启动文件
    

    6.修改配置文件

    [root@db01 ~]# egrep -v "^$|^#" /etc/elasticsearch/elasticsearch.yml 
    ##节点名称
    node.name: node-1 
    ##数据路径
    path.data: /data/elasticsearch
    ##日志路径
    path.logs: /var/log/elasticsearch
    ##打开内存锁定
    bootstrap.memory_lock: true
    ##定义访问的主机
    network.host: 172.16.210.53
    ##定义web访问端口
    http.port: 9200
    [root@db01 ~]# mkdir /data/elasticsearch ##记得创建数据目录
    [root@db01 ~]# chown -R elasticsearch.elasticsearch /data/elasticsearch/  ##更改属主和属组
    [root@db01 ~]# vim /etc/elasticsearch/jvm.options ##修改jvm相关配置
    ##找到这两行设置jvm使用内存
    -Xms2g
    -Xmx2g 
    ##我系统是4G内存,jvm的推荐使用内存是主机的一半,所以我就给2G最大内存,2G最小内存,最大和最小内存一样,就能做到内存锁死
    [root@db01 ~]# systemctl restart elasticsearch.service  ##重启服务
    

    内存限制说明:

    1. 不要超过32G
    2. 最大最小内存设置为一样
    3. 配置文件设置锁定内存
    4. 至少给服务器本身空余50%的内存

    查看状态

    [root@db01 ~]# systemctl status  elasticsearch.service 
    ● elasticsearch.service - Elasticsearch
       Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since 二 2020-06-16 08:20:13 CST; 3min 13s ago
         Docs: http://www.elastic.co
      Process: 21991 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=78)
     Main PID: 21991 (code=exited, status=78)
    
    6月 16 08:18:03 db01 systemd[1]: Started Elasticsearch.
    6月 16 08:18:03 db01 systemd[1]: Starting Elasticsearch...
    6月 16 08:20:13 db01 systemd[1]: elasticsearch.service: main process .../a
    6月 16 08:20:13 db01 systemd[1]: Unit elasticsearch.service entered f...e.
    6月 16 08:20:13 db01 systemd[1]: elasticsearch.service failed.
    Hint: Some lines were ellipsized, use -l to show in full.
    

    可以看到服务是没启动起来的.
    查看日志:

    root@db01 ~]# tailf /var/log/elasticsearch/elasticsearch.log 
    [2020-06-16T08:20:12,375][INFO ][o.e.n.Node               ] [node-1] starting ...
    [2020-06-16T08:20:12,695][INFO ][o.e.t.TransportService   ] [node-1] publish_address {172.16.210.53:9300}, bound_addresses {172.16.210.53:9300}
    [2020-06-16T08:20:12,711][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
    [2020-06-16T08:20:12,860][ERROR][o.e.b.Bootstrap          ] [node-1] node validation exception
    [1] bootstrap checks failed
    [1]: memory locking requested for elasticsearch process but memory is not locked
    

    可以明显的看到memory locking requested for elasticsearch process but memory is not locked 这行报错

    解决报错

    [root@db01 ~]# systemctl edit elasticsearch #3添加两行参数
    [Service]
    LimitMEMLOCK=infinity
    

    重启服务并查看状态

    [root@db01 ~]# systemctl daemon-reload 
    [root@db01 ~]# systemctl restart  elasticsearch
    [root@db01 ~]# systemctl status elasticsearch
    ● elasticsearch.service - Elasticsearch
       Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/elasticsearch.service.d
               └─override.conf
       Active: active (running) since 二 2020-06-16 08:27:51 CST; 3s ago
         Docs: http://www.elastic.co
     Main PID: 22167 (java)
       CGroup: /system.slice/elasticsearch.service
               └─22167 /bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:C...
    
    6月 16 08:27:51 db01 systemd[1]: Started Elasticsearch.
    6月 16 08:27:51 db01 systemd[1]: Starting Elasticsearch...
    ###服务启动成功
    [root@db01 ~]# netstat -lntup | grep 9200 ##检查端口
    tcp6       0      0 172.16.210.53:9200      :::*                    LISTEN      22461/java        
    [root@db01 ~]# curl 172.16.210.53:9200 ##最后curl一下在配置文件定义的ip和端口,能返回信息就代表配置成功了
    {
      "name" : "node-1",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "7cO37iSlTZK9tFFkdXW7PA",
      "version" : {
        "number" : "6.6.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "a9861f4",
        "build_date" : "2019-01-24T11:27:09.439740Z",
        "build_snapshot" : false,
        "lucene_version" : "7.6.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    

    相关文章

      网友评论

        本文标题:Elasticsearch的安装部署

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