美文网首页elasticsearchjs css html学习
Elasticsearch 在linux服务器安装

Elasticsearch 在linux服务器安装

作者: 桃子家的二哈 | 来源:发表于2023-03-06 10:39 被阅读0次

    我们在日常系统开发中,在做模糊搜索,数据量小的情况下会用到(DB)去处理数据,然而当数据量到一个量级的时候通常这种前后端响应不是那么快,此时我们就要考虑优化,通常会将数据存放在Elasticsearch内进行快速查询

    安装Elasticsearch

    • 环境准备
      (1)CentOS Linux release 7.9.2009 (Core)
      (2)elasticsearch-7.3.1
      (3)java 1.8.0_45
    • 下载
    wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-linux-x86_64.tar.gz
    
    • 版本对应


      esVersion.png

    如图所示为各个服务对应的版本信息!!

    • 新建linux用户
    # 新建用户
    [root@taozialiyun es]# useradd estz
    #创建密码
    [root@taozialiyun es]# passwd estz
    
    • 在root用户下解压下载文件
    [root@taozialiyun es]# tar -zxvf elasticsearch-7.3.1-linux-x86_64.tar.gz
    
    • 进入配置文件 config
    [root@taozialiyun config]# cd /home/es/elasticsearch-7.3.1/config
    [root@taozialiyun config]# ll
    total 36
    # es配置
    -rw-rw---- 1 root root  2831 Aug 20  2019 elasticsearch.yml
    # jvm配置
    -rw-rw---- 1 root root  3524 Aug 20  2019 jvm.options
    # 日志配置
    -rw-rw---- 1 root root 17222 Aug 20  2019 log4j2.properties
    -rw-rw---- 1 root root   473 Aug 20  2019 role_mapping.yml
    -rw-rw---- 1 root root   197 Aug 20  2019 roles.yml
    -rw-rw---- 1 root root     0 Aug 20  2019 users
    -rw-rw---- 1 root root     0 Aug 20  2019 users_roles
    [root@taozialiyun config]# 
    
    • 修改jvm配置
      vim jvm.options
    -Xms512M
    -Xmx512M
    

    注意:这个根据自己服务器大小做修改,因为我的服务器内存只有2G所有,修改jvm为512M

    • 修改 elasticsearch.yml配置
      vim elasticsearch.yml
    #当前的集群名(改成一个有意义的名字)
    cluster.name: es-aliyun-tz 
    #配置当前es节点名称(改成一个有意义的名字)
    node.name: es-tz-1 
    # 数据目录位置
    path.data: /home/es/data 
    # 日志目录位置
    path.logs: /home/es/logs 
    #绑定的ip:默认只允许本机访问,修改为0.0.0.0后则可以远程访问
    network.host: 0.0.0.0   
    #设置master节点列表 用逗号分隔
    cluster.initial_master_nodes: ["node-1"] 
    # http端口
    http.port: 9200
    
    • 在启动的时候可能会报错需修改一下配置
      cd /etc/security
      vim /limits.conf
    # End of file
    root soft nofile 65535
    root hard nofile 65535
    * soft nofile 65535
    * hard nofile 65535
    #加入最后一句 
    vm.max_map_count=655360
    #max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量
    

    sysctl -p 生效

    • 启动及分配权限
      因为es启动限制不能在root用户下进行所以我们需要给目录授权,并切换到刚才我们新建的用户下启动
    [root@taozialiyun security]# cd /home
    [root@taozialiyun home]# ll
    total 0
    drwxr-xr-x 3 root root  24 May 28  2021 adore
    drwxr-xr-x 5 root root 104 Mar  7 10:04 es
    drwx------ 2 estz estz  62 Mar  7 09:49 estz
    [root@taozialiyun home]# chgrp -R estz ./es
    [root@taozialiyun home]# chown -R estz ./es
    [root@taozialiyun home]# chmod 777 es
    [root@taozialiyun home]# ll
    total 0
    drwxr-xr-x 3 root root  24 May 28  2021 adore
    drwxrwxrwx 5 estz estz 104 Mar  7 10:04 es
    drwx------ 2 estz estz  62 Mar  7 09:49 estz
    [root@taozialiyun home]# 
    
    

    如图可见,我们es目录的所属用户已经变为estz
    切换用户 su estz
    启动: ./bin/elasticsearch
    启动不报错后,浏览器访问地址:服务器IP+9200

    {
        "name": "es-tz-1",
        "cluster_name": "es-aliyun-tz",
        "cluster_uuid": "9l6wUsXQRTSsGv_ocbrwuA",
        "version": {
            "number": "7.3.1",
            "build_flavor": "default",
            "build_type": "tar",
            "build_hash": "4749ba6",
            "build_date": "2019-08-19T20:19:25.651794Z",
            "build_snapshot": false,
            "lucene_version": "8.1.0",
            "minimum_wire_compatibility_version": "6.8.0",
            "minimum_index_compatibility_version": "6.0.0-beta1"
        },
        "tagline": "You Know, for Search"
    }
    
    • 启动可能会有的报错问题
      (1)java版本不一致问题
    [estz@taozialiyun elasticsearch-7.3.1]$ ./bin/elasticsearch
    future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_281/jre] does not meet this requirement
    Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
    

    这个问题主要是,es本身自带了jdk如果服务器安装了jdk,会默认读取服务器jdk版本导致版本不一致
    解决方案:
    vim ./bin/elasticsearch

    export JAVA_HOME=/home/es/elasticsearch-7.3.1/jdk
    export PATH=$JAVA_HOME/bin:$PATH
    
    if [ -x "$JAVA_HOME/bin/java" ]; then
            JAVA="/home/es/elasticsearch-7.3.1/jdk/bin/java"
    else 
            JAVA=`which java`
    fi
    

    加入上面shell 指定读取elasticsearch下的jdk版本
    (2)内存不足的问题

    [2023-03-07T10:52:10,953][INFO ][o.e.b.BootstrapChecks    ] [es-tz-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
    ERROR: [1] bootstrap checks failed
    [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    

    修改jvm.options

    -Xms256M
    -Xmx256M
    

    (3)解决vm.max_map_count [65530] is too low问题

    [root@taozialiyun etc]# vim sysctl.conf 
    [root@taozialiyun etc]# systcl -p
    -bash: systcl: command not found
    [root@taozialiyun etc]# sysctl -p
    vm.swappiness = 0
    kernel.sysrq = 1
    net.ipv4.neigh.default.gc_stale_time = 120
    net.ipv4.conf.all.rp_filter = 0
    net.ipv4.conf.default.rp_filter = 0
    net.ipv4.conf.default.arp_announce = 2
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_max_syn_backlog = 1024
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_slow_start_after_idle = 0
    

    vm.max_map_count = 262144添加这个配置
    (4)再次启动

    成功.png

    成功

    综上则是我们安装elasticsearch单节点完整过程!

    相关文章

      网友评论

        本文标题:Elasticsearch 在linux服务器安装

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