SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)

1.新增elasticsearch检索服务

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第1张图片

2.登录虚拟机拉取elasticsearch镜像

Install Elasticsearch with Docker | Elasticsearch Guide [7.15] | Elastic

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.15.2

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第2张图片

3.创建目录

mkdir -p /data1/dockerMatchDirectory/elasticsearch/config

mkdir -p /data1/dockerMatchDirectory/elasticsearch/data

4. 设置可以被远程机器访问

echo "http.host: 0.0.0.0" >> /data1/dockerMatchDirectory/elasticsearch/config/elasticsearch.yml

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第3张图片

5.给文件夹授权 不然会出现AccessDeniedException

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第4张图片

chmod -R 777 /data1/dockerMatchDirectory/elasticsearch

6. 运行

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-v /data1/dockerMatchDirectory/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /data1/dockerMatchDirectory/elasticsearch/data:/usr/share/elasticsearch/data \
-v /data1/dockerMatchDirectory/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d docker.elastic.co/elasticsearch/elasticsearch:7.15.2

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第5张图片

7.浏览器访问是否安装成功

http://192.168.56.30:9200/

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第6张图片

8. 安装可视化kibana

Install Kibana with Docker | Kibana Guide [7.15] | Elastic

docker pull docker.elastic.co/kibana/kibana:7.15.2

docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.56.30:9200 -p 5601:5601 \
-d docker.elastic.co/kibana/kibana:7.15.2

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第7张图片

 9.浏览器访问http://192.168.56.30:5601

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第8张图片

 10.测试发起一条查询请求

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第9张图片

 11.设置elasticsearch kibana自动重启

docker update elasticsearch --restart=always

docker update kibana --restart=always

 12.添加配置文件

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第10张图片

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第11张图片

pom引入相关maven

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第12张图片

spring boot默认会引入7.12.1版本的elasticsearch 我们在主服务里统一成7.15.2版本

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第13张图片

 13.添加elasticsearch配置

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第14张图片

14.路由配置增加配置

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第15张图片

15. 先索引几条文档 put请求

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第16张图片

16.构建索引常量

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第17张图片

17.构建请求controller

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第18张图片

18.编写业务 注入自己的配置

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第19张图片

19.测试模糊查询 模糊匹配name包含John的

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第20张图片

可以看到确实有两条数据包含John

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第21张图片

 使用kibana查到的结果也是一样

SpringCloud+nacos+gateway+elasticsearch+kibana+seata+sentinel+zipkin+swagger2+rabbitmq集成docker部署(九)_第22张图片

你可能感兴趣的:(后端,linux服务器环境搭建,框架搭建,elasticsearch,docker,spring,cloud,kibana,swagger2)