码迷,mamicode.com
首页 > 其他好文 > 详细

Docker笔记四:Elasticsearch实例部署

时间:2017-12-21 00:17:09      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:digital   nap   art   cmd   master   提示   pass   问题   $path   

  • 在运行或启动elasticsearch容器前,先在宿主机上执行 sysctl -w vm.max_map_count=262144:
  1. 解决“ max virtual memory areas vm.maxmapcount [65530] is too low ”错误问题。
  2. 解决容器中/etc/sysctl.conf不可写,sysctl -w vm.max_map_count=262144无效问题。
  3. 本人也尝试过在docker run 时使用--sysctl vm.max_map_count=262144选项,但提示not whitelisted。
  • 关于JAVA的安装,本机采用default-jre 。参考 How To Install Java with Apt-Get on Debian 8,不要求设置环境变量CLASSPATH:
    export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

    也不要求设置环境变量PATH:

    export PATH=$JAVA_HOME/bin:$PATH

    只需要设置环境变量JAVA_HOME:红色字体部分根据具体版本进行替换

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
  • 聚合:参考 ElasticsearchDSL / Aggregation

安装Elasticsearch

1. 编写Dockerfile:

FROM ubuntu
MAINTAINER cenze <272666745@qq.com>

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ADD conf/sources.list /etc/apt/

RUN apt-get update && apt-get install -y apt-utils vim unzip default-jre

ENV ESEARCH /usr/local/elasticsearch-6.0.1

ADD packages/elasticsearch-6.0.1.zip /usr/local/
RUN  unzip /usr/local/elasticsearch-6.0.1 -d /usr/local && adduser --disabled-login --disabled-password --no-create-home es

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV PATH $ESEARCH/bin:$PATH
ADD conf/elasticsearch.yml /usr/local/elasticsearch-6.0.1/config/
RUN chown -R es:es /usr/local/elasticsearch-6.0.1

EXPOSE 9200 9300

CMD ["elasticsearch"]

 

2. build镜像:

sudo docker build -t cenze/esearch -f Dockerfile-ESearch .

3. 以非root用户run容器,否则elasticsearch无法启动:

sudo docker run -d -p 9200:9200 -p 9300:9300 --name esearch --user es cenze/esearch

4. curl http://localhost:9200:

{
  "name" : "D_5lS8A",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "wS2pUZ95TC2jCRJ5GMvNsA",
  "version" : {
    "number" : "6.0.1",
    "build_hash" : "601be4a",
    "build_date" : "2017-12-04T09:29:09.525Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

 

安装中文分词插件ik

也可以是smartcn。ik的版本要与Elasticsearch版本匹配,本人用的6.0.1:

 

es@053b32506e8d:/$ elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.0.1/elasticsearch-analysis-ik-6.0.1.zip
es@053b32506e8d:/$ elasticsearch-plugin list
analysis-ik

 

测试中文关键词搜索

下列操作参考 https://github.com/medcl/elasticsearch-analysis-ik/

1. 创建索引:curl -X PUT http://localhost:9200/test/group。

2. mapping:

curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/_mapping -d‘
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
    
}‘

3. 索引多个文档:

curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/1 -d‘
{"content":"美国留给伊拉克的是个烂摊子吗"}
‘
curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/2 -d‘
{"content":"公安部:各地校车将享最高路权"}
‘
curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/3 -d‘
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
‘
curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/4 -d‘
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
‘

4. 搜索测试:

curl -XPOST -H‘content-type: application/json‘ http://localhost:9200/index/fulltext/_search  -d‘
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
‘

 

Docker笔记四:Elasticsearch实例部署

标签:digital   nap   art   cmd   master   提示   pass   问题   $path   

原文地址:http://www.cnblogs.com/XiongMaoMengNan/p/8073852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!