Docker安装ElasticSearch 版本7.1.1
一、Docker 部署 ElasticSearch
1、从仓库中查找所有ElasticSearch的镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [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 |
2、选择一个版本镜像进行拉取
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@iZwz99dhxbd6xwly17tb3bZ ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:7.1.1 Trying to pull repository docker.elastic.co/elasticsearch/elasticsearch ... 7.1.1: 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:7.1.1 |
3、 查看镜像
1 2 3 4 5 | [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 7.1.1 96dd1575de0f 2 months ago |
4、通过镜像,启动一个容器,并将9200和9300端口映射到本机(ElasticSearch
的默认端口是9200,我们把宿主环境9200端口映射到Docker
容器中的9200端口)
1 2 | [root@iZwz99dhxbd6xwly17tb3bZ ~]# docker run -d --name es -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS= "-Xms512m -Xmx512m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.1.1 c11ef1beb4f3e82d74b8709f9462e83636551b6307cd816563a4a5539f17ac6b |
5、 配置跨域,进入容器内部,修改elasticsearch.yml
1 2 3 4 5 6 7 | [root@iZwz99dhxbd6xwly17tb3bZ ~]# docker exec -it es /bin/bash[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 |
新增跨域配置
1 2 3 4 5 6 7 8 9 | 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容器
1 2 | [root@iZwz99dhxbd6xwly17tb3bZ ~]# docker restart es es |
7、 浏览器访问ip:9200
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | { "name" : "bfc29f5a8f8c" , "cluster_name" : "docker-cluster" , "cluster_uuid" : "9dtJwBrNTwCHnbewPETxhw" , "version" : { "number" : "7.1.1" , "build_flavor" : "default" , "build_type" : "docker" , "build_hash" : "7a013de" , "build_date" : "2019-05-23T14:04:00.380842Z" , "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" } |
二、Docker 部署 ElasticSearch-Head
ElasticSearch-Head是一个管理界面,可以查看ElasticSearch相关信息
1、拉取ElasticSearch-Head镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [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容器
1 2 | [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文件夹
1 2 3 4 5 6 7 | [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压缩包,并解压
这一步有的人服务器不支持zip所以解压不了。我是从电脑上解压后弄成tar.gz文件上传到服务器然后cp到容器内部对应文件夹下,命令 docker cp /tmp/elasticsearch-analysis-ik-7.1.1.tar.gz 40aeef081297:/usr/share/elasticsearch/plugins/tk
下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
1 2 3 4 5 6 7 | [root@970f612c5cac plugins]# cd ik [root@970f612c5cac ik]# wget https: //github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip [root@970f612c5cac ik]# unzip elasticsearch-analysis-ik-7.1.1.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容器
1 2 3 | [root@970f612c5cac ik]# exit exit [root@iZwz99dhxbd6xwly17tb3bZ ~]# docker restart es |
4、测试ik分词插件,postman请求以下参数
ip:9200/_analyze?pretty=true
{
"analyzer": "ik_max_word",
"text": "这是我拷贝来的,我是不是很厉害"
}
注意analyzer这个单词上下是不一样的
至此Docker安装 Elasticsearch已基本完成,从中我们可以清晰感受到Docker的强大之处!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步