Docker安装ElasticSearch
上一篇我们介绍了Docker的一些入门,这篇我们来实战安装下ElasticSearch。一、Docker 部署 ElasticSearch1、从仓库中查找所有ElasticSearch的镜像[root@iZwz99dhxbd6xwly17tb3bZ app]# docker search elasticsearchINDEXNAME...
·
上一篇我们介绍了Docker的一些入门,这篇我们来实战安装下ElasticSearch。
一、Docker 部署 ElasticSearch
1、从仓库中查找所有ElasticSearch的镜像
[root@iZwz99dhxbd6xwly17tb3bZ app]# docker search elasticsearch
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/elasticsearch Elasticsearch is a powerful open source se... 3060 [OK]
docker.io docker.io/kibana Kibana gives shape to any kind of data — s... 1239 [OK]
docker.io docker.io/nshou/elasticsearch-kibana Elasticsearch-6.3.1 Kibana-6.3.1 81 [OK]
docker.io docker.io/itzg/elasticsearch Provides an easily configurable Elasticsea... 66 [OK]
docker.io docker.io/mobz/elasticsearch-head elasticsearch-head front-end and standalon... 34
docker.io docker.io/kubernetes/fluentd-elasticsearch An image that ingests Docker container log... 25
docker.io docker.io/lmenezes/elasticsearch-kopf elasticsearch kopf 17 [OK]
docker.io docker.io/tutum/elasticsearch Elasticsearch image - listens in port 9200. 16 [OK]
docker.io docker.io/monsantoco/elasticsearch ElasticSearch Docker image 11 [OK]
docker.io docker.io/bitnami/elasticsearch Bitnami Docker Image for Elasticsearch 10 [OK]
docker.io docker.io/mesoscloud/elasticsearch [UNMAINTAINED] Elasticsearch 9 [OK]
docker.io docker.io/justwatch/elasticsearch_exporter Elasticsearch stats exporter for Prometheus 7
docker.io docker.io/taskrabbit/elasticsearch-dump Import and export tools for elasticsearch 7 [OK]
docker.io docker.io/blacktop/elasticsearch Alpine Linux based Elasticsearch Docker Image 5 [OK]
docker.io docker.io/centerforopenscience/elasticsearch Elasticsearch 3 [OK]
docker.io docker.io/frodenas/elasticsearch A Docker Image for Elasticsearch 3 [OK]
docker.io docker.io/barchart/elasticsearch-aws Elasticsearch AWS node 2
docker.io docker.io/jetstack/elasticsearch-pet An elasticsearch image for kubernetes PetSets 1 [OK]
docker.io docker.io/phenompeople/elasticsearch Elasticsearch is a powerful open source se... 1 [OK]
docker.io docker.io/thingswise/elasticsearch Elasticsearch + etcd2 peer discovery 1 [OK]
docker.io docker.io/18fgsa/elasticsearch Built from https://github.com/docker-libra... 0
docker.io docker.io/backplane/elasticsearch-curator Elasticsearch Curator (https://github.com/... 0
docker.io docker.io/driveclutch/infra-elasticsearch-aws Elasticsearch Docker for use in AWS 0 [OK]
docker.io docker.io/forkdelta/fluentd-elasticsearch fluent/fluentd with fluent-plugin-elastics... 0 [OK]
docker.io docker.io/wreulicke/elasticsearch elasticsearch 0 [OK]
2、选择一个版本镜像进行拉取
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2
Trying to pull repository docker.elastic.co/elasticsearch/elasticsearch ...
6.3.2: Pulling from docker.elastic.co/elasticsearch/elasticsearch
7dc0dca2b151: Pull complete
72d60ff53590: Pull complete
ca55c9f7cc1f: Pull complete
822d6592a660: Pull complete
22eceb1ece84: Pull complete
30e73cf19e42: Pull complete
f05e800ca884: Pull complete
3e6ee2f75301: Pull complete
Digest: sha256:8f06aecf7227dbc67ee62d8d05db680f8a29d0296ecd74c60d21f1fe665e04b0
Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:6.3.2
3、 查看镜像
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/elasticsearch latest 5acf0e8da90b 3 days ago 486 MB
docker.io/hello-world latest 4ab4c602aa5e 2 weeks ago 1.84 kB
docker.elastic.co/elasticsearch/elasticsearch 6.3.2 96dd1575de0f 2 months ago 826 MB
4、通过镜像,启动一个容器,并将9200和9300端口映射到本机(ElasticSearch
的默认端口是9200,我们把宿主环境9200端口映射到Docker
容器中的9200端口)
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
c11ef1beb4f3e82d74b8709f9462e83636551b6307cd816563a4a5539f17ac6b
5、 配置跨域,进入容器内部,修改elasticsearch.yml
[root@c11ef1beb4f3 elasticsearch]# ls
LICENSE.txt NOTICE.txt README.textile bin config data lib logs modules plugins
[root@c11ef1beb4f3 elasticsearch]# cd config/
[root@c11ef1beb4f3 config]# ls
elasticsearch.keystore ingest-geoip log4j2.properties roles.yml users_roles
elasticsearch.yml jvm.options role_mapping.yml users
[root@c11ef1beb4f3 config]# vi elasticsearch.yml
新增跨域配置
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1
6、重启ElasticSearch容器
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker restart es
es
7、 浏览器访问ip:9200
二、Docker 部署 ElasticSearch-Head
ElasticSearch-Head是一个管理界面,可以查看ElasticSearch相关信息
1、拉取ElasticSearch-Head镜像
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker pull mobz/elasticsearch-head:5
Trying to pull repository docker.io/mobz/elasticsearch-head ...
5: Pulling from docker.io/mobz/elasticsearch-head
75a822cd7888: Pull complete
57de64c72267: Pull complete
4306be1e8943: Pull complete
871436ab7225: Pull complete
0110c26a367a: Pull complete
1f04fe713f1b: Pull complete
723bac39028e: Pull complete
7d8cb47f1c60: Pull complete
7328dcf65c42: Pull complete
b451f2ccfb9a: Pull complete
304d5c28a4cf: Pull complete
4cf804850db1: Pull complete
Digest: sha256:55a3c82dd4ba776e304b09308411edd85de0dc9719f9d97a2f33baa320223f34
Status: Downloaded newer image for docker.io/mobz/elasticsearch-head:5
2、 运行ElasticSearch-Head容器
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker run -d --name es_admin -p 9100:9100 mobz/elasticsearch-head:5
76b0903ac01bc642d4d3ad238134df7312473a44c5b9f603f97f6742a759e629
3、浏览器访问 ip:9100
三、Docker部署ik中文分词插件
1、进入es容器内部,/plugins下新建ik文件夹
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker exec -it es /bin/bash
[root@970f612c5cac elasticsearch]# ls
LICENSE.txt NOTICE.txt README.textile bin config data lib logs modules plugins
[root@970f612c5cac elasticsearch]# cd plugins/
[root@970f612c5cac plugins]# mkdir ik
[root@970f612c5cac plugins]# ls
ik ingest-geoip ingest-user-agent
2、下载与es对应版本的ik压缩包,并解压
[root@970f612c5cac plugins]# cd ik
[root@970f612c5cac ik]# wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.2/elasticsearch-analysis-ik-6.3.2.zip
[root@970f612c5cac ik]# unzip elasticsearch-analysis-ik-6.3.2.zip
[root@970f612c5cac ik]# ls
commons-codec-1.9.jar elasticsearch-analysis-ik-6.3.2.jar plugin-descriptor.properties
commons-logging-1.2.jar httpclient-4.5.2.jar plugin-security.policy
config httpcore-4.4.4.jar
3、退出容器,重启es容器
[root@970f612c5cac ik]# exit
exit
[root@iZwz99dhxbd6xwly17tb3bZ ~]# docker restart es
4、测试ik分词插件,postman请求以下参数
结果返回如下 ,说明安装成功
{
"tokens": [
{
"token": "看到",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "这里是",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 1
},
{
"token": "这里",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 2
},
{
"token": "是不是",
"start_offset": 4,
"end_offset": 7,
"type": "CN_WORD",
"position": 3
},
{
"token": "不是",
"start_offset": 5,
"end_offset": 7,
"type": "CN_WORD",
"position": 4
},
{
"token": "感觉",
"start_offset": 7,
"end_offset": 9,
"type": "CN_WORD",
"position": 5
},
{
"token": "很简单",
"start_offset": 9,
"end_offset": 12,
"type": "CN_WORD",
"position": 6
},
{
"token": "简单",
"start_offset": 10,
"end_offset": 12,
"type": "CN_WORD",
"position": 7
},
{
"token": "呢",
"start_offset": 12,
"end_offset": 13,
"type": "CN_CHAR",
"position": 8
}
]
}
至此Docker安装 Elasticsearch已基本完成,从中我们可以清晰感受到Docker的强大之处!
更多推荐
已为社区贡献15条内容
所有评论(0)