美文网首页
Anolis8部署Elasticsearch单节点

Anolis8部署Elasticsearch单节点

作者: 前浪浪奔浪流 | 来源:发表于2023-02-09 17:21 被阅读0次

    涉及版本声明:

    Linux: Anolis8.4 64位, 且已经安装好epel源。
    Jdk: 1.8.0_11
    ElasticSearch: elasticsearch-7.16.2
    下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.2-x86_64.rpm
    Ik-Analysis: elasticsearch-analysis-ik-7.16.2
    下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
    analysis-pinyin: elasticsearch-analysis-pinyin-7.16.2
    下载地址:https://github.com/medcl/elasticsearch-analysis-pinyin/releases
    elasticsearch-head: elasticsearch-head5.0.0
    下载地址:https://codeload.github.com/mobz/elasticsearch-head/tar.gz/refs/tags/v5.0.0
    Elasticsearch与jdk版本对应关系

    image.png

    一、 安装环境准备

    主机规划:192.168.100.86 anolis8
    系统配置:
    4 VCPU、4G内存、50G硬盘
    修改服务器名称:

    hostnamectl set-hostname anolis8
    

    需要修改几个参数,不然启动会报错

    vim /etc/security/limits.conf
    在末尾追加以下内容
    * soft nofile 65536
    * hard nofile 65536
    * soft nproc 2048
    * hard nproc 2048
    * soft memlock unlimited
    * hard memlock unlimited
    

    对于systemd service的资源限制,现在放在 /etc/systemd/system.conf

    vim /etc/systemd/system.conf
    在末尾追加以下内容
    DefaultLimitNOFILE=65536
    DefaultLimitNPROC=32000
    DefaultLimitMEMLOCK=infinity
    

    否则elasticsearch启动时会报错:
    memory locking requested for elasticsearch process but memory is not locked

    这个问题的解决办法是修改

    vim /usr/lib/systemd/system/elasticsearch.service
    在文件中添加
    LimitMEMLOCK=infinity
    保存后退出
    systemctl daemon-reload
    

    二、安装配置

    1、安装JDK

    使用脚本安装jdk1.8版本 
    chmod +x jdkinstall.sh
    sh jdkinstall.sh
    source /etc/profile
    
    [root@anolis8 ~]# java -version
    java version "1.8.0_11"
    Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
    

    2,安装elasticsearch

    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.2-x86_64.rpm
    
    [root@anolis8 ~]# rpm -ivh elasticsearch-7.16.2-x86_64.rpm
    
    [root@anolis8 ~]# ll /etc/elasticsearch/
    总用量 44
    -rw-rw---- 1 root elasticsearch   199 2月  10 11:04 elasticsearch.keystore
    -rw-rw---- 1 root elasticsearch  1042 12月 19 2021 elasticsearch-plugins.example.yml
    -rw-rw---- 1 root elasticsearch  3712 2月  10 11:37 elasticsearch.yml
    -rw-rw---- 1 root elasticsearch  3344 2月  10 11:40 jvm.options
    drwxr-s--- 2 root elasticsearch     6 12月 19 2021 jvm.options.d
    -rw-rw---- 1 root elasticsearch 19150 12月 19 2021 log4j2.properties
    -rw-rw---- 1 root elasticsearch   473 12月 19 2021 role_mapping.yml
    -rw-rw---- 1 root elasticsearch   197 12月 19 2021 roles.yml
    -rw-rw---- 1 root elasticsearch     0 12月 19 2021 users
    -rw-rw---- 1 root elasticsearch     0 12月 19 2021 users_roles
    
    2.1配置elasticsearch
    创建elasticsearch data的存放目录,并修改该目录的属主属组
    # mkdir -p /data/es-data   (自定义用于存放data数据的目录)
    # chown -R elasticsearch:elasticsearch /data/es-data
    修改elasticsearch的日志属主属组
    # chown -R elasticsearch:elasticsearch /var/log/elasticsearch
    修改elasticsearch的配置文件
    # vim /etc/elasticsearch/elasticsearch.yml
    找到配置文件中的cluster.name,打开该配置并设置集群名称
    17行
    cluster.name: my-els
    找到配置文件中的node.name,打开该配置并设置节点名称
    node.name: anolis8      //192.168.100.86
    
    修改data存放的路径
    path.data: /data/es-data
    
    修改logs日志的路径
    path.logs: /var/log/elasticsearch
    
    锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高;
    bootstrap.memory_lock: true
    
    监听的网络地址
    network.host: 0.0.0.0
    
    开启监听的端口
    http.port: 9200
    
    增加新的参数,这样head插件可以访问es
    http.cors.enabled: true    
    http.cors.allow-origin: "*"
    bootstrap.system_call_filter: false
    
    集群发现
    在启动此节点时,传递要执行发现的主机的初始列表:
    discovery.seed_hosts: ["192.168.100.86"]
    初始用来引导集群的符合主节点条件的节点列表:
    cluster.initial_master_nodes: ["192.168.100.86"]
    保存退出
    
    ps -ef|grep java
    [root@anolis8 ~]# ps -ef|grep java
    elastic+    4234       1  1 11:40 ?        00:03:46 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j2.formatMsgNoLookups=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=ALL-UNNAMED -Xms512m -Xmx512m -XX:+UseG1GC -Djava.io.tmpdir=/tmp/elasticsearch-18154957694075136409 -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=/var/lib/elasticsearch -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=268435456 -XX:G1HeapRegionSize=4m -XX:InitiatingHeapOccupancyPercent=30 -XX:G1ReservePercent=15 -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=rpm -Des.bundled_jdk=true -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -p /var/run/elasticsearch/elasticsearch.pid --quiet
    
    
    可以看到elasticsearch启动所使用的java路径:/usr/share/elasticsearch/jdk/bin/java
    查看java版本
    [root@es01 home]# /usr/share/elasticsearch/jdk/bin/java -version
    openjdk version "17.0.1" 2021-10-19
    OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
    OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
    
    elasticsearch使用的内存大小为2G,我们把它改小点:
    修改参数:
    vim /etc/elasticsearch/jvm.options
    -Xms512m
    -Xmx512m
    启动
    systemctl start elasticsearch.service
    
    **查看状态**
    [root@anolis8 ~]# systemctl status elasticsearch.service
    ● elasticsearch.service - Elasticsearch
       Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)
       Active: active (running) since Fri 2023-02-10 11:41:10 CST; 4h 51min ago
         Docs: https://www.elastic.co
     Main PID: 4234 (java)
        Tasks: 69 (limit: 24888)
       Memory: 934.4M
       CGroup: /system.slice/elasticsearch.service
               ├─4234 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m >
               └─4439 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
    
    2月 10 11:40:33 anolis8 systemd[1]: Starting Elasticsearch...
    2月 10 11:41:10 anolis8 systemd[1]: Started Elasticsearch.
    lines 1-13/13 (END)
    

    日志位置(日志的名称是以集群名称命名的):

    [root@anolis8 ~]# ll /var/log/elasticsearch/
    总用量 252
    -rw-r--r-- 1 elasticsearch elasticsearch 163044 2月  10 16:32 gc.log
    -rw-r--r-- 1 elasticsearch elasticsearch   2012 2月  10 11:40 gc.log.00
    -rw-r--r-- 1 elasticsearch elasticsearch      0 2月  10 11:40 my-els_audit.json
    -rw-r--r-- 1 elasticsearch elasticsearch   1278 2月  10 11:41 my-els_deprecation.json
    -rw-r--r-- 1 elasticsearch elasticsearch    806 2月  10 11:41 my-els_deprecation.log
    -rw-r--r-- 1 elasticsearch elasticsearch      0 2月  10 11:40 my-els_index_indexing_slowlog.json
    -rw-r--r-- 1 elasticsearch elasticsearch      0 2月  10 11:40 my-els_index_indexing_slowlog.log
    -rw-r--r-- 1 elasticsearch elasticsearch      0 2月  10 11:40 my-els_index_search_slowlog.json
    -rw-r--r-- 1 elasticsearch elasticsearch      0 2月  10 11:40 my-els_index_search_slowlog.log
    -rw-r--r-- 1 elasticsearch elasticsearch  28043 2月  10 11:41 my-els.log
    -rw-r--r-- 1 elasticsearch elasticsearch  52811 2月  10 11:41 my-els_server.json
    

    创建开机自启动服务

    systemctl enable elasticsearch.service
    chkconfig elasticsearch on
    

    如果报错:

    [2022-04-14T17:13:04,076][WARN ][o.e.b.JNANatives         ] [es02] Unable to lock JVM Memory: error=12, reason=无法分配内存
    [2022-04-14T17:13:04,078][WARN ][o.e.b.JNANatives         ] [es02] This can result in part of the JVM being swapped out.
    [2022-04-14T17:13:04,078][WARN ][o.e.b.JNANatives         ] [es02] Increase RLIMIT_MEMLOCK, soft limit: 65536, hard limit: 65536
    [2022-04-14T17:13:04,079][WARN ][o.e.b.JNANatives         ] [es02] These can be adjusted by modifying /etc/security/limits.conf, for example: 
        # allow user 'elasticsearch' mlockall
        elasticsearch soft memlock unlimited
        elasticsearch hard memlock unlimited
    [2022-04-14T17:13:04,079][WARN ][o.e.b.JNANatives         ] [es02] If you are logged in interactively, you will have to re-login for the new limits to take effect.
    

    请修改/usr/lib/systemd/system/elasticsearch.service

    vim /usr/lib/systemd/system/elasticsearch.service
    [service]增加 LimitMEMLOCK=infinity
    systemctl daemon-reload
    systemctl restart elasticsearch.service
    
    # netstat -antp |grep 9200
    tcp6       0      0 :::9200                 :::*                    LISTEN      25475/java
    

    通过浏览器请求下9200的端口,看下是否成功, 以下为正常:

    [root@anolis8 ~]# curl http://127.0.0.1:9200/
    {
      "name" : "anolis8      //192.168.100.86",
      "cluster_name" : "my-els",
      "cluster_uuid" : "g4amx5QxSq6-Wdf9y81iiQ",
      "version" : {
        "number" : "7.16.2",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "2b937c44140b6559905130a8650c64dbd0879cfb",
        "build_date" : "2021-12-18T19:42:46.604893745Z",
        "build_snapshot" : false,
        "lucene_version" : "8.10.1",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }
    

    如何和elasticsearch交互

    curl -i -XGET 'localhost:9200/_count?pretty'
    HTTP/1.1 200 OK
    X-elastic-product: Elasticsearch
    Warning: 299 Elasticsearch-7.16.2-2b937c44140b6559905130a8650c64dbd0879cfb "Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.16/security-minimal-setup.html to enable security."
    content-type: application/json; charset=UTF-8
    content-length: 115
    
    {
      "count" : 10,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      }
    }
    

    3、安装elasticsearch-head插件

    通过github下载elasticsearch-head项目
    npm安装 下载源码,编译安装,在nodejs环境下运行插件

    # yum install git bzip2 -y
    
    下载地址:
    https://github.com/mobz/elasticsearch-head
    https://codeload.github.com/mobz/elasticsearch-head/tar.gz/refs/tags/v5.0.0
    通过浏览器下载elasticsearch-head-5.0.0.tar.gz然后上传后解压
    tar -zxvf elasticsearch-head-5.0.0.tar.gz
    ll 
    -rw-r--r--  1 root root 343758474 4月   9 17:31 elasticsearch-7.16.2-x86_64.rpm
    drwxrwxr-x  7 root root      4096 4月  14 18:10 elasticsearch-head-5.0.0
    -rw-r--r--  1 root root    863489 4月  14 17:41 elasticsearch-head-5.0.0.tar.gz
    
    dnf安装nodejs
    查看可用流的列表
    
    [root@anolis8 elasticsearch-head-5.0.0]# dnf module list nodejs
    Repository epel is listed more than once in the configuration
    上次元数据过期检查:3:22:28 前,执行于 2023年02月10日 星期五 11时46分36秒。
    AnolisOS-8 - AppStream
    Name                            Stream                             Profiles                                                       Summary                                   
    nodejs                          10 [d][e]                          common [d], development, minimal, s2i                          Javascript runtime                        
    nodejs                          12                                 common [d], development, minimal, s2i                          Javascript runtime                        
    nodejs                          14                                 common [d], development, minimal, s2i                          Javascript runtime                        
    nodejs                          16                                 common [d], development, minimal, s2i                          Javascript runtime                        
    
    Extra Packages for Enterprise Linux Modular 8 - x86_64
    Name                            Stream                             Profiles                                                       Summary                                   
    nodejs                          13                                 default, development, minimal                                  Javascript runtime                        
    nodejs                          16-epel                            default, development, minimal                                  Javascript runtime                        
    
    提示:[d]默认,[e]已启用,[x]已禁用,[i]已安装
    
    需要nodejs的版本在14以上才行。因此需要使用nodejs:16的流。
    
    [root@anolis8 elasticsearch-head-5.0.0]# dnf module install nodejs:16
    Repository epel is listed more than once in the configuration
    上次元数据过期检查:3:23:16 前,执行于 2023年02月10日 星期五 11时46分36秒。
    依赖关系解决。
    这个操作会把模块 'nodejs' 从流 '10' 切换到流 '16'
    错误:无法切换已启用模块的流,除非显式的通过配置选项 module_stream_switch 启用。
    推荐直接移除来自模块的所有已安装内容,然后通过 'dnf module reset <module_name>' 命令重置模块。在您重置模块之后,就可以安装其他的流。
    
    [root@anolis8 elasticsearch-head-5.0.0]# dnf module reset nodejs:16
    Repository epel is listed more than once in the configuration
    上次元数据过期检查:3:25:23 前,执行于 2023年02月10日 星期五 11时46分36秒。
    只需要模块名。正在忽略'nodejs:16'中的无用信息
    依赖关系解决。
    ============================================================================================================================================================================
     软件包                                   架构                                    版本                                       仓库                                      大小
    ============================================================================================================================================================================
    重置模块:
     nodejs                                                                                                                                                                    
    
    事务概要
    ============================================================================================================================================================================
    
    确定吗?[y/N]: y
    完毕!
    
    查看结果
    [root@anolis8 elasticsearch-head-5.0.0]# dnf module list nodejs
    Repository epel is listed more than once in the configuration
    上次元数据过期检查:3:25:55 前,执行于 2023年02月10日 星期五 11时46分36秒。
    AnolisOS-8 - AppStream
    Name                             Stream                           Profiles                                                       Summary                                    
    nodejs                           10 [d]                           common [d], development, minimal, s2i                          Javascript runtime                         
    nodejs                           12                               common [d], development, minimal, s2i                          Javascript runtime                         
    nodejs                           14                               common [d], development, minimal, s2i                          Javascript runtime                         
    nodejs                           16                               common [d], development, minimal, s2i                          Javascript runtime                         
    
    Extra Packages for Enterprise Linux Modular 8 - x86_64
    Name                             Stream                           Profiles                                                       Summary                                    
    nodejs                           13                               default, development, minimal                                  Javascript runtime                         
    nodejs                           16-epel                          default, development, minimal                                  Javascript runtime                         
    
    提示:[d]默认,[e]已启用,[x]已禁用,[i]已安装
    
    安装nodejs16
    [root@anolis8 elasticsearch-head-5.0.0]# dnf module install nodejs:16
    Repository epel is listed more than once in the configuration
    上次元数据过期检查:3:26:24 前,执行于 2023年02月10日 星期五 11时46分36秒。
    依赖关系解决。
    ============================================================================================================================================================================
     软件包                               架构                       版本                                                                   仓库                           大小
    ============================================================================================================================================================================
    安装组/模块包:
     nodejs                               x86_64                     1:16.17.1-1.module+an8.6.0+10852+70f84ff5                              AppStream                      12 M
     npm                                  x86_64                     1:8.15.0-1.16.17.1.1.module+an8.6.0+10852+70f84ff5                     AppStream                     1.9 M
    安装弱的依赖:
     nodejs-docs                          noarch                     1:16.17.1-1.module+an8.6.0+10852+70f84ff5                              AppStream                     9.3 M
     nodejs-full-i18n                     x86_64                     1:16.17.1-1.module+an8.6.0+10852+70f84ff5                              AppStream                     8.0 M
    安装模块配置档案:
     nodejs/common                                                                                                                                                             
    启用模块流:
     nodejs                                                          16                                                                                                        
    
    事务概要
    ============================================================================================================================================================================
    安装  4 软件包
    
    总下载:31 M
    安装大小:153 M
    确定吗?[y/N]: 
    
    检查结果
    [root@anolis8 elasticsearch-head-5.0.0]# node -v
    v16.17.1
    [root@anolis8 elasticsearch-head-5.0.0]# npm -v
    8.15.0
    
    cd elasticsearch-head-5.0.0/
    ll
    总用量 96
    -rw-rw-r--   1 root root   248 9月  15 2017 Dockerfile
    -rw-rw-r--   1 root root   221 9月  15 2017 Dockerfile-alpine
    -rw-rw-r--   1 root root   104 9月  15 2017 elasticsearch-head.sublime-project
    -rw-rw-r--   1 root root  2171 9月  15 2017 Gruntfile.js
    -rw-rw-r--   1 root root  3482 9月  15 2017 grunt_fileSets.js
    -rw-rw-r--   1 root root  1088 9月  15 2017 index.html
    -rw-rw-r--   1 root root   559 9月  15 2017 LICENCE
    drwxr-xr-x 461 root root 32768 4月  14 18:03 node_modules
    -rw-------   1 root root   192 4月  14 18:10 nohup.out
    -rw-rw-r--   1 root root   886 9月  15 2017 package.json
    -rw-rw-r--   1 root root   100 9月  15 2017 plugin-descriptor.properties
    drwxrwxr-x   4 root root    53 9月  15 2017 proxy
    -rw-rw-r--   1 root root  6944 9月  15 2017 README.textile
    drwxrwxr-x   5 root root   140 9月  15 2017 _site
    drwxrwxr-x   4 root root    31 9月  15 2017 src
    drwxrwxr-x   4 root root    70 9月  15 2017 test
    通过阿里巴巴源安装cnpm
    [root@anolis8 elasticsearch-head-5.0.0]# npm install -g cnpm --registry=https://registry.npm.taobao.org
    npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
    
    added 38 packages, removed 76 packages, and changed 380 packages in 19s
    
    11 packages are looking for funding
      run `npm fund` for details
    npm notice 
    npm notice New major version of npm available! 8.15.0 -> 9.4.2
    npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.2
    npm notice Run npm install -g npm@9.4.2 to update!
    npm notice 
    
    ---------------------------
    
    [root@anolis8 elasticsearch-head-5.0.0]# cnpm install
    ⠼ [2/10] Installing qs@~5.1.0
    WARN node unsupported "node@v16.17.1" is incompatible with karma@1.3.0, expected node@0.10 || 0.12 || 4 || 5 || 6
    ⠧ [2/10] Installing path-is-absolute@^1.0.0
    WARN node unsupported "node@v16.17.1" is incompatible with grunt-contrib-connect@1.0.2 › http2@^3.3.4, expected node@>=0.12.0 <9.0.0
    ✔ Installed 10 packages on /root/elasticsearch-head-5.0.0
    ✔ Linked 383 latest versions fallback to /root/elasticsearch-head-5.0.0/node_modules/.store/node_modules
    [1/2] scripts.install grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@^2.1.3 run "node install.js", root: "/root/elasticsearch-head-5.0.0/node_modules/.store/phantomjs-prebuilt@2.1.16/node_modules/phantomjs-prebuilt"
    PhantomJS not found on PATH
    Downloading https://cdn.npmmirror.com/binaries/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
    Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
    Receiving...
      [=================================-------] 82%
    Received 22866K total.
    Extracting tar contents (via spawned process)
    Removing /root/elasticsearch-head-5.0.0/node_modules/.store/phantomjs-prebuilt@2.1.16/node_modules/phantomjs-prebuilt/lib/phantom
    Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1676013537803/phantomjs-2.1.1-linux-x86_64 -> /root/elasticsearch-head-5.0.0/node_modules/.store/phantomjs-prebuilt@2.1.16/node_modules/phantomjs-prebuilt/lib/phantom
    Writing location.js file
    Done. Phantomjs binary available at /root/elasticsearch-head-5.0.0/node_modules/.store/phantomjs-prebuilt@2.1.16/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
    [1/2] scripts.install grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@^2.1.3 finished in 10s
    [2/2] scripts.postinstall karma@1.3.0 › core-js@^2.2.0 run "node -e \"try{require('./postinstall')}catch(e){}\"", root: "/root/elasticsearch-head-5.0.0/node_modules/.store/core-js@2.6.12/node_modules/core-js"
    Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
    
    The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
    > https://opencollective.com/core-js 
    > https://www.patreon.com/zloirock 
    
    Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
    
    [2/2] scripts.postinstall karma@1.3.0 › core-js@^2.2.0 finished in 123ms
    ✔ Run 2 scripts
    deprecate grunt-contrib-connect@1.0.2 › http2@^3.3.4 Use the built-in module in node 9.0.0 or newer, instead
    deprecate grunt@1.0.1 › coffee-script@~1.10.0 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
    deprecate grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@^2.1.3 this package is now deprecated
    deprecate karma@1.3.0 › chokidar@^1.4.1 Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
    anti semver karma@1.3.0 › useragent@2.3.0 › tmp@0.0.x delcares tmp@0.0.x(resolved as 0.0.33) but using ancestor(karma)'s dependency tmp@0.0.28(resolved as 0.0.28)
    deprecate grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@2.1.16 › request@^2.81.0 request has been deprecated, see https://github.com/request/request/issues/3142
    deprecate karma@1.3.0 › log4js@^0.6.31 0.x is no longer supported. Please upgrade to 6.x or higher.
    deprecate grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@2.1.16 › request@2.88.2 › har-validator@~5.1.3 this library is no longer supported
    deprecate karma@1.3.0 › socket.io@1.4.7 › socket.io-parser@2.2.6 › json3@3.3.2 Please use the native JSON object instead of JSON 3
    deprecate grunt-contrib-jasmine@1.0.3 › grunt-lib-phantomjs@1.1.0 › phantomjs-prebuilt@2.1.16 › request@2.88.2 › uuid@^3.3.2 Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
    deprecate karma@1.3.0 › socket.io@1.4.7 › socket.io-adapter@0.4.0 › socket.io-parser@2.2.2 › json3@3.2.6 Please use the native JSON object instead of JSON 3
    deprecate karma@1.3.0 › chokidar@1.7.0 › readdirp@2.2.1 › micromatch@3.1.10 › snapdragon@0.8.2 › source-map-resolve@^0.5.0 See https://github.com/lydell/source-map-resolve#deprecated
    deprecate karma@1.3.0 › chokidar@1.7.0 › readdirp@2.2.1 › micromatch@3.1.10 › snapdragon@0.8.2 › source-map-resolve@0.5.3 › source-map-url@^0.4.0 See https://github.com/lydell/source-map-url#deprecated
    deprecate karma@1.3.0 › chokidar@1.7.0 › readdirp@2.2.1 › micromatch@3.1.10 › snapdragon@0.8.2 › source-map-resolve@0.5.3 › urix@^0.1.0 Please see https://github.com/lydell/urix#deprecated
    deprecate karma@1.3.0 › chokidar@1.7.0 › readdirp@2.2.1 › micromatch@3.1.10 › snapdragon@0.8.2 › source-map-resolve@0.5.3 › resolve-url@^0.2.1 https://github.com/lydell/resolve-url#deprecated
    deprecate karma@1.3.0 › core-js@^2.2.0 core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
    Recently updated (since 2023-02-03): 2 packages (detail see file /root/elasticsearch-head-5.0.0/node_modules/.recently_updates.txt)
      Today:
        → grunt@1.0.1 › dateformat@1.0.12 › meow@3.7.0 › minimist@^1.1.3(1.2.8) (04:59:49)
    ✔ All packages installed (458 packages installed from npm registry, used 21s(network 11s), speed 769.13KB/s, json 384(1.78MB), tarball 6.41MB, manifests cache hit 0, etag hit 0 / miss 0)
    
    启动es-head插件,必须进入es-head插件目录运行启动命令
    cd elasticsearch-head-5.0.0/
    
    [root@anolis8 elasticsearch-head-5.0.0]# nohup npm run start &
    
    

    使用浏览器访问http://192.168.100.86:9100/即可访问到es-head插件,再使用es-head插件访问es数据库,效果如下


    image.png

    http://192.168.100.86:9200/
    注意
    9100端口是插件端口,9200是es端口
    通过插件访问http://192.168.100.86:9200点击连接还是失败,是因为es有安全机制只允许服务器本地访问,这时需要设置

    设置跨域:
    设置跨域同时也适用于安装的es-head插件跟es数据不在同一台服务器上时的情况

    #编辑es主配置文件,在文本末尾添加如下两行配置
    vim /etc/elasticsearch/elasticsearch.yml
    # 是否支持跨域
    http.cors.enabled: true
    # *表示支持所有域名
    http.cors.allow-origin: "*"
    
    systemctl restart elasticsearch
    cd elasticsearch-head-5.0.0/
    nohup npm run start &
    

    注意 :别把es-head插件后放到 Elasticsearch的plugins目录下,否则会报错!!!

    三、安装本地Elasticsearch的IK分词插件和拼音分词插件

    1、 安装本地Elasticsearch的IK分词插件

    Ik-Analysis: elasticsearch-analysis-ik-7.16.2
    下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
    解压下载文件elasticsearch-analysis-ik-7.16.2.zip

    ll elasticsearch-analysis-ik-7.16.2
    总用量 1428
    -rw-r--r-- 1 root root 263965 4月  15 16:59 commons-codec-1.9.jar
    -rw-r--r-- 1 root root  61829 4月  15 16:59 commons-logging-1.2.jar
    drwxr-xr-x 2 root root    299 4月  15 16:59 config
    -rw-r--r-- 1 root root  54595 4月  15 16:59 elasticsearch-analysis-ik-7.16.2.jar
    -rw-r--r-- 1 root root 736658 4月  15 16:59 httpclient-4.5.2.jar
    -rw-r--r-- 1 root root 326724 4月  15 16:59 httpcore-4.4.4.jar
    -rw-r--r-- 1 root root   1807 4月  15 16:59 plugin-descriptor.properties
    -rw-r--r-- 1 root root    125 4月  15 16:59 plugin-security.policy
    
    将解压后的elasticsearch-analysis-ik-7.16.2 文件夹上传至elasticsearch安装目录下的plugins下
    
    /usr/share/elasticsearch/plugins/
    

    重启Elasticsearch,可以看到控制台打印日志

    loaded plugin [analysis-ik]
    

    2、 安装本地Elasticsearch的拼音分词插件

    analysis-pinyin: elasticsearch-analysis-pinyin-7.16.2
    下载地址:https://github.com/medcl/elasticsearch-analysis-pinyin/releases
    上传下载文件elasticsearch-analysis-pinyin-7.16.2.zip

    ll elasticsearch-analysis-pinyin-7.16.2
    总用量 7936
    -rw-r--r-- 1 root root   27445 4月  15 16:59 elasticsearch-analysis-pinyin-7.16.2.jar
    -rw-r--r-- 1 root root 8091448 4月  15 16:59 nlp-lang-1.7.jar
    -rw-r--r-- 1 root root    1824 4月  15 16:59 plugin-descriptor.properties
    
    将解压后的elasticsearch-analysis-pinyin-7.16.2 文件夹上传至elasticsearch安装目录下的plugins下
    
    /usr/share/elasticsearch/plugins/
    

    重启Elasticsearch,可以看到控制台打印日志

    loaded plugin [analysis-pinyin]
    

    nodejs下载地址
    https://nodejs.org/zh-cn/download/

    es官网的安装方式
    https://www.elastic.co/guide/en/elasticsearch/reference/8.6/rpm.html#rpm-repo

    相关文章

      网友评论

          本文标题:Anolis8部署Elasticsearch单节点

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