本文通过Docker快速安装一个单节点的ElasticSearch集群用于开发和测试,生产环境下的Elasticsearch还最好要3个以上结点,并且服务器也需要作一些设置,请期待我的下一遍博文
安装elasticsearch
这里我的项目是springboot 2.3.x版本,所以我安装的是ES 7.6.2版本,具体需要哪个版本,请参考ES的官方文档。
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.2
docker volume create elastic_data
#启动容器,注意一定要加参数-e "discovery.type=single-node"
docker run --name elastic762 --network=network_172_19 --ip=172.19.0.101 -v elastic_data:/data -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.2
安装中文分词插件IK
#进入容器
docker exec -it elastic762 /bin/bash
#安装插件
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip
#安装结束后重启容器
docker restart elastic762
配置ES
docker exec -it elastic762 /bin/bash
进入config目录
vi /config/elasticsearch.yml
改成以下内容
http.host: 0.0.0.0
cluster.name: elasticsearchTEST
node.name: node0
#加入这行才能通过9300端口连接
network.host: 0.0.0.0
#要加入这两个配置,才能使用elasticsearch-head远程连接
http.cors.enabled: true
http.cors.allow-origin: "*"
修改后重启容器即可。
评论区