1、Docker安装Elasticsearch
1.1、拉取elasticsearch镜像
docker pull elasticsearch:7.12.1
[root@VM-8-3-centos ~]# docker pull elasticsearch:7.12.1
7.12.1: Pulling from library/elasticsearch
7a0437f04f83: Pull complete
ed4a47ec20b2: Pull complete
74e4f4b7e738: Pull complete
ef2a2418a5f4: Pull complete
646dbf47f747: Pull complete
3ffbf21442fc: Pull complete
e04f00c0d464: Pull complete
Digest: sha256:622f854572780281bc85b5fde33be27e99670941ed8b7eea5ba4aaf533fa64ec
Status: Downloaded newer image for elasticsearch:7.12.1
docker.io/library/elasticsearch:7.12.1
[root@VM-8-3-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 3edbb69f9a49 2 weeks ago 117MB
nginx latest f6987c8d6ed5 7 months ago 141MB
mysql latest 3218b38490ce 7 months ago 516MB
elasticsearch 7.12.1 41dc8ea0f139 15 months ago 851MB
java 8 d23bdf5b1b1b 5 years ago 643MB
1.2、启动镜像
docker run -d -p 9200:9200 -p 9300:9300 --name myElasticsearch -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -e "discovery.type=single-node" elasticsearch:7.12.1
docker run -d # 后台运行
-p 9200:9200 -p 9300:9300 #端口映射
--name myElasticsearch # 镜像名称
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" #es默认使用内存较大,设置es所使用的的内存,否则es大概率无法启动
-e "discovery.type=single-node" #设置为单节点模式
elasticsearch:7.12.1 # 镜像名称
这样elasticsearch就成功启动了!
[root@VM-8-3-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91ea03d8b573 elasticsearch:7.12.1 "/bin/tini -- /usr/l…" 2 minutes ago Up 2 minutes 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp myElasticsearch
1.3、访问Elasticsearch服务
服务器放通安全组
访问elasticsearch服务
2、整合Elasticsearch
2.1、SpringBoot项目引入依赖
此处使用SpringBoot项目,SpringBoot版本为2.5.5
<!-- ElasticSearch -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
Maven插件查看依赖信息,发现elasticsearch已经成功导入
2.2、配制elasticsearch
spring:
# Elasticsearch
elasticsearch:
rest:
uris: http://119.***.***.208:9200