这里,只列举大概的步骤:

  1. 安装Docker
  2. 从Docker上获取ElasticSearch的容器
  3. 从Docker上获取Kibana的容器
  4. 运行ElasticSearch
  5. 运行Kibana
  6. 修改ES的配置,然后通过Docker重启ES容器,以应用配置:ES跨域访问 / 中文分词
  7. 在Kibana中,验证中文分词

以上这些步骤的代码如下:

1. yum install docker

2. 修改Docker的源为中国大陆
[root@linux ~]# cat /etc/docker/daemon.json
{
"registry-mirrors" : [
    "http://registry.docker-cn.com",
    "http://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
  ],
  "insecure-registries" : [
    "registry.docker-cn.com",
    "docker.mirrors.ustc.edu.cn"
  ],
  "debug" : true,
  "experimental" : true
}
[root@linux ~]# 

3. 从Docker Hub获取容器:ElasticSearch与Kibana
docker pull elasticsearch:7.2.0
docker pull kibana:7.2.0

4. 运行容器:ElasticSearch与Kibana
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -d elasticsearch:7.2.0
docker run --name kibana --link=elasticsearch:test  -p 5601:5601 -d kibana:7.2.0

ElasticSearch运行起来后,就可以看到状态了:
[root@linux ~]# curl http://localhost:9200
{
  "name" : "740b3001626e",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "FOxORSDrRhCyQRb4XCUSfw",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root@linux ~]# 

5. 修改ES的配置文件,以解决跨域访问的问题
进入Docker的ES容器的命令行:
docker exec -it elasticsearch /bin/bash

进入目标目录:
cd /usr/share/elasticsearch/config/

修改配置文件:
[root@740b3001626e config]# cat elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
[root@740b3001626e config]# 

从容器的命令行退出:exit

6. 为ES安装IK分词器,因为默认的ES分词器对中文的支持不是很好:

先下载IK:
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.2.0/elasticsearch-analysis-ik-7.2.0.zip

然后安装HTTPD服务:
yum install -y httpd

启动HTTPD服务:
service httpd start

创建目录:
mkdir /var/www/html/software

将下载好的IK的安装介质上传到上面创建的目录【/var/www/html/software】中

然后,通过URL的方式访问:
[root@linux ~]# curl http://192.168.27.128/software/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /software</title>
 </head>
 <body>
<h1>Index of /software</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="/">Parent Directory</a>       </td><td>&nbsp;</td><td align="right">  - </td><td>&nbsp;</td></tr>
<tr><td valign="top"><img src="/icons/compressed.gif" alt="[   ]"></td><td><a href="elasticsearch-analysis-ik-7.2.0.zip">elasticsearch-analys..&gt;</a></td><td align="right">2020-07-06 10:14  </td><td align="right">4.3M</td><td>&nbsp;</td></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
[root@linux ~]# 

进入Docker的ES容器的命令行:
docker exec -it elasticsearch /bin/bash

安装IK:
进入插件目录:
cd /usr/share/elasticsearch/plugins/

执行安装:
[root@740b3001626e plugins]# elasticsearch-plugin install http://192.168.27.128/software/elasticsearch-analysis-ik-7.2.0.zip        -> Downloading http://192.168.27.128/software/elasticsearch-analysis-ik-7.2.0.zip
[=================================================] 100% 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y
-> Installed analysis-ik
[root@740b3001626e plugins]# 

如上所示,这样IK就安装好了。

7. 重启Docker的ES容器,以生效刚刚的配置修改:
docker restart elasticsearch 

最后,在Kibana中验证中文分词:

这一段的具体的内容如下:

Console / 命令:

GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "与其互为宇宙,不如自称人间。"
}

Console / 结果:

{
  "tokens" : [
    {
      "token" : "与其",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "互为",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "宇宙",
      "start_offset" : 4,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "不如",
      "start_offset" : 7,
      "end_offset" : 9,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "自称",
      "start_offset" : 9,
      "end_offset" : 11,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "人间",
      "start_offset" : 11,
      "end_offset" : 13,
      "type" : "CN_WORD",
      "position" : 5
    }
  ]
}

这样,通过Docker在Linux上部署【ES+Kibana】,就完成了。


说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒
隐藏
变装