• ElasticSearch(2)---安装


    在这里插入图片描述

    上一篇:ElasticSearch(1)—基础概念

    1.下载ElasticSearch

    下载ElasticSearch链接

    2.安装ElasticSearch

    要求:ElasticSearch要求JDK必须是1.8以上

      这里我下载的是linux版本的elasticSearch的压缩包:
    在这里插入图片描述
    将此压缩包上传到Linux中:

    2.1 解压缩文件

    tar -zxvf elasticsearch-7.6.0-linux-x86_64.tar.gz
    

    2.2 移动解压缩之后的文件到/usr/local/目录下

    mv elasticsearch-7.6.0 /usr/local/
    

    2.3 新建一个普通用户
      ElasticSearch无法使用root用户启动,所以需要创建一个普通用户。
    在这里插入图片描述

    依次输入以下命令:

    useradd zhangsan
    
    passwd zhangsan
    输入密码:123456    (输入密码之后可能会显示BAD PASSWORD,这是友情提示不用管)
    再次输入密码:123456 (回车之后显示 all authentication tokens updated successfully,用户创建成功)
    

    2.4 给新建用户赋予权限

    chown -R zhangsan /usr/local/elasticsearch-7.6.0/
    

    在这里插入图片描述
    2.5 切换用户

    切换使用的用户账号:

    su -l zhangsan
    

    2.6 开启ElasticSearch

      ElasticSearch开启方式分为两种:

    1. 种是使用默认配置开启单机版,这种一般是我们自己玩玩儿。
    2. 自定义配置文件,工作中一般使用config自定义配置文件来启动。

    一、开启默认配置单机版

    /usr/local/elasticsearch-7.6.0/bin/elasticsearch
    

    在这里插入图片描述
    2.7 检查是否启动成功
    新开一个Linux窗口:
    在这里插入图片描述
    在新开启的窗口输入下面的命令:

    curl -XGET 'http://127.0.0.1:9200'
    

    如果显示如下,则表明ElasticSearch开启成功:
    在这里插入图片描述
    二、开启自定义配置版
      这种开启方式是我们实际工作中使用的比较多的,Ctrl+C退出刚才开启的ElasticSearch服务。并输入下面命令进入config目录:

    cd /usr/local/elasticsearch-7.6.0/config
    

    在这里插入图片描述
    config目录中,有一个配置文件elasticsearch.yml

    2.8 elasticsearch.yml配置文件详解

    输入下面命令开始编辑配置文件:

    vim elasticsearch.yml
    

    按照下面的配置文件中的内容进行相应的修改:

    # ======================== Elasticsearch Configuration =========================
    #
    # NOTE: Elasticsearch comes with reasonable defaults for most settings.
    #       Before you set out to tweak and tune the configuration, make sure you
    #       understand what are you trying to accomplish and the consequences.
    #
    # The primary way of configuring a node is via this file. This template lists
    # the most important settings you may want to configure for a production cluster.
    #
    # Please consult the documentation for further information on configuration options:
    # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
    #
    # ---------------------------------- Cluster -----------------------------------
    #
    # Use a descriptive name for your cluster:
    #
    cluster.name: test_cluster
    #
    # ------------------------------------ Node ------------------------------------
    #
    # Use a descriptive name for the node:
    #
    node.name: node-1
    #
    # Add custom attributes to the node:
    #
    #node.attr.rack: r1
    #
    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: /home/zhangsan/data/elastic
    #
    # Path to log files:
    #
    path.logs: /home/zhangsan/logs/elastic
    #
    # ----------------------------------- Memory -----------------------------------
    #
    # Lock the memory on startup:
    #
    #bootstrap.memory_lock: true
    #
    # Make sure that the heap size is set to about half the memory available
    # on the system and that the owner of the process is allowed to use this
    # limit.
    #
    # Elasticsearch performs poorly when the system is swapping the memory.
    #
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    # network.host: 192.168.0.1
    network.host: 0.0.0.0
    #
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    #
    # For more information, consult the network module documentation.
    #
    # --------------------------------- Discovery ----------------------------------
    #
    # Pass an initial list of hosts to perform discovery when new node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    
    #discovery.zen.ping.unicast.hosts: ["host1", "host2"]
    cluster.initial_master_nodes: ["node-1"]
    # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
    #
    #discovery.zen.minimum_master_nodes: 3
    #
    # For more information, consult the zen discovery module documentation.
    #
    # ---------------------------------- Gateway -----------------------------------
    #
    # Block initial recovery after a full cluster restart until N nodes are started:
    #
    #gateway.recover_after_nodes: 3
    #
    # For more information, consult the gateway module documentation.
    #
    # ---------------------------------- Various -----------------------------------
    #
    # Require explicit names when deleting indices:
    #
    #action.destructive_requires_name: true
    http.cors.enabled: true
    http.cors.allow-origin: "*"
     
    node.master: true
    node.data: true
    

    2.9 修改jvm参数
    使用root账户输入以下命令:

    1.在ESconfig目录下的jvm.options中修改:

    -Xms1g 改为-Xms128m
    -Xmx1g 改为-Xmx128m
    

    2.修改内存大小
    内存权限报错

    3.修改如下配置:

    vi /etc/security/limits.conf
    

    添加如下内容:

    • soft nofile 65536

    • hard nofile 131072

    • soft nproc 2048

    • hard nproc 4096

    以上第二步和第三步完成之后输入命令sysctl -p立即执行。

    3 重启服务

    注意:-d表示后台启动,不加则表示前台启动

    /usr/local/elasticsearch-7.6.0/bin/elasticsearch -d
    

    在这里插入图片描述
    输入命令jps,查看是否有ElasticSearch的进程
    在这里插入图片描述
    如果有则表示开启成功。

    下一篇:ElasticSearch(3)—CURL操作
  • 相关阅读:
    Haskell 差点儿无痛苦上手指南
    HighCharts 具体使用及API文档说明
    又一道软通动力7K月薪面试题——银行业务调度系统
    [AngularJS + Webpack] require directives
    [AngularJS + Webpack] Using Webpack for angularjs
    [Whole Web] [AngularJS] Localize your AngularJS Application with angular-localization
    [React] React Fundamentals: Mixins
    [React] React Fundamentals: Component Lifecycle
    [React ] React Fundamentals: Component Lifecycle
    [React] React Fundamentals: Component Lifecycle
  • 原文地址:https://www.cnblogs.com/wgty/p/12810413.html
Copyright © 2020-2023  润新知