• 【杂记】docker搭建ELK 集群6.4.0版本 + elasticsearch-head IK分词器与拼音分词器整合


    大佬博客地址:https://blog.csdn.net/supermao1013/article/category/8269552 

    docker elasticsearch 集群启动命令

    docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d  -p 9200:9200 -p 9300:9300 -p 5601:5601 -v /usr/local/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins1:/usr/share/elasticsearch/plugins    -v /usr/local/es/data1:/usr/share/elasticsearch/data --name ES01 1ac676545731
    
    docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d -p 9201:9201 -p 9301:9301 -v /usr/local/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins2:/usr/share/elasticsearch/plugins    -v /usr/local/es/data2:/usr/share/elasticsearch/data --name ES02 1ac676545731
    

      

    搭建集群遇到的错误:

    错误一:

    [2019-09-30T02:24:27,081][INFO ][o.e.n.Node               ] [es-node1] initializing ...
    [2019-09-30T02:24:27,106][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [es-node1] uncaught exception in thread [main]
    org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
            at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
            at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.0.jar:6.4.0]
    Caused by: java.lang.IllegalStateException: Failed to create node environment
            at org.elasticsearch.node.Node.<init>(Node.java:277) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.0.jar:6.4.0]
            ... 6 more
    Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
            at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
            at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
            at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
            at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:385) ~[?:?]
            at java.nio.file.Files.createDirectory(Files.java:682) ~[?:?]
            at java.nio.file.Files.createAndCheckIsDirectory(Files.java:789) ~[?:?]
            at java.nio.file.Files.createDirectories(Files.java:775) ~[?:?]
            at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:203) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.node.Node.<init>(Node.java:274) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.node.Node.<init>(Node.java:256) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.4.0.jar:6.4.0]
            at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.0.jar:6.4.0]
            ... 6 more
    

      这种解决方式就是软连接data1文件夹(/usr/local/es/data1和/usr/local/es/data2)权限不足,需要chmod 777 data1  和 chmod 777 data2

    错误额二:

    [master-node] failed to read local state, exiting...
    org.elasticsearch.ElasticsearchException: java.io.IOException: failed to read [id:0, file:/data/elasticsearch/nodes/0/_state/global-0.st]
        at org.elasticsearch.ExceptionsHelper.maybeThrowRuntimeAndSuppress(ExceptionsHelper.java:200) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:304) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.MetaStateService.loadGlobalState(MetaStateService.java:112) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.MetaStateService.loadFullState(MetaStateService.java:56) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.GatewayMetaState.<init>(GatewayMetaState.java:86) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.node.Node.<init>(Node.java:447) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.node.Node.<init>(Node.java:256) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) [elasticsearch-cli-6.4.2.jar:6.4.2]
        at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) [elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) [elasticsearch-6.4.2.jar:6.4.2]
    Caused by: java.io.IOException: failed to read [id:0, file:/data/elasticsearch/nodes/0/_state/global-0.st]
        at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:298) ~[elasticsearch-6.4.2.jar:6.4.2]
        ... 15 more
    Caused by: java.lang.IllegalArgumentException: Unexpected field [cluster_uuid_committed]
        at org.elasticsearch.cluster.metadata.MetaData$Builder.fromXContent(MetaData.java:1232) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.cluster.metadata.MetaData$1.fromXContent(MetaData.java:1262) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.cluster.metadata.MetaData$1.fromXContent(MetaData.java:1253) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.MetaDataStateFormat.read(MetaDataStateFormat.java:196) ~[elasticsearch-6.4.2.jar:6.4.2]
        at org.elasticsearch.gateway.MetaDataStateFormat.loadLatestState(MetaDataStateFormat.java:294) ~[elasticsearch-6.4.2.jar:6.4.2]
        ... 15 more
    

      这种问题出现是因为我之前安装过es 其他版本,现在安装这个版本需要删除data/nodes里的.st文件,有很多,我嫌麻烦直接把data1文件夹全部删除(注意,我说的路径是

    /usr/local/es/data1和/usr/local/es/data2) 删除之后重新建data1和data2,然后授权限,不然还是起不来,授权看上面问题一。

    http://ip:端口/_cat/nodes?pretty 测试集群效果
    
    http://ip:端口/_cat/indices?v 查看elaticsearch 索引状态
    
    http://ip:端口/_cluster/health?pretty #查看健康信息
    
    
    http://ip:端口/_cat/health?v #查看集群状态
    

    analysis-pinyin插件下载地址

    https://github.com/medcl/elasticsearch-analysis-pinyin/releases
    

      

    analysis-ik插件下载地址

    https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v6.4.0
    

      

    使用文档

    https://github.com/medcl/elasticsearch-analysis-pinyin/
    

      

    docker -p命令

    不写本地端口, docker 将帮你自动分配:docker run -d -p :80 -p :443 nginx:latest
    加上 ip 就绑本地指定的 ip: docker run -d -p 127.0.0.1:8088:80 -p :443 nginx:latest
    不写本地端口就随机分配:docker run -d -p 127.0.0.1::80 -p :443 nginx:latest
    

      

    参考链接:https://blog.csdn.net/belonghuang157405/article/details/83301937

    docker搭建elasticsearch-head

    1:拉取elasticsearch-head

    docker pull mobz/elasticsearch-head:5
    

      

    2:启动容器

    docker run -d -p 9100:9100 --name es-manager  mobz/elasticsearch-head:5
    

      

    3:访问es-head http://ip:9100/

    4:添加索引出现问题:PUT 406 Not Acceptable

    解决方式:参考地址:https://www.jianshu.com/p/fec0d22ddf8d

    我的解决方式就是  再docker容器中 修改 _site/vendor.js 中 6886行

    将原来:

    contentType: "application/x-www-form-urlencoded" 
    

     

    改成

    contentType: "application/json"
    

      

    过程有些曲折,因为docker里边未安装vim/vi命令,需要先安装命令

    进入es-head容器内部

    docker es -it [容器ID] /bin/bash
    

      

    安装vim命令

    参考链接:https://blog.csdn.net/weixin_43569697/article/details/90649130

    apt-get update
    
    apt-get install -y vim
    
    #出现bash: apt-get: command not found
    #可以把apt-get换成yum试一下
    

     

    编辑vendor.js 

    vim /usr/src/app/_site/vendor.js
    

      

    显示行号

    :set number
    

      

    跳转指定行

    :6886
    

      

    修改完成,隐藏行号

    :set nonumber
    

    :wq保存后重启es-head 

    docker restart [容器ID]
    

      

    vim命令参考链接:https://blog.csdn.net/u011848617/article/details/38434359

    之后就能正常添加索引了

    查看docker消耗内存

    docker stats $(docker ps --format={{.Names}})
    

      

    IK分词与拼音分词整合

    PUT /product
    {
      "settings":{
          "analysis":{
            "analyzer":{
               "ik_pinyin_analyzer":{
                "type":"custom",
                "tokenizer":"ik_smart",
                "filter":"pinyin_filter"
              }
            },
            "filter":{
              "pinyin_filter":{
                "type":"pinyin",
                "keep_first_letter": false
              }
            }
        }
      }
    }
    

      

     

    希望能帮助到你。

      

  • 相关阅读:
    JAVA中的浅拷贝与深拷贝
    Spring异步-@Async注解
    Spring 事务传播行为的使用
    DecimalFormat的使用
    Java编码问题原因以及解决
    Spring
    [TimLinux] docker CentOS7 入门——容器(1)
    [TimLinux] asciinema Linux终端录制工具嵌入私有web中
    [TimLinux] docker CentOS7安装docker-ce最新版
    [TimLinux] systemd 精通CentOS7系统启动systemd
  • 原文地址:https://www.cnblogs.com/wbl001/p/11610587.html
Copyright © 2020-2023  润新知