mkdir -p /usr/local/microservices/elasticSearch/{es_data01,es_data02,es_data03,es_conf/_data,es_plugins}
/usr/local/microservices/elasticSearch/es_conf/_data
目录下编写ES的yml文件vim es01.yml
文件内容:
注意:需要修改文件中 network.publish_host,discovery.seed_hosts 两个配置项的IP
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 192.168.31.89 #修改为docker的宿主机ip
http.port: 9200 #这个是容器内部的,所以不用改
transport.tcp.port: 9300 #这个是容器内部的,所以不用改
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["192.168.31.89:9300","192.168.31.89:9301","192.168.117.232:9302"] #修改为docker的宿主机ip
discovery.zen.minimum_master_nodes: 2
indices.query.bool.max_clause_count: 10240
cluster.initial_master_nodes: es-node1
vim es02.yml
文件内容:
注意:需要修改文件中 network.publish_host,discovery.seed_hosts 两个配置项的IP
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 192.168.31.89 #修改为docker的宿主机ip
http.port: 9200 #这个是容器内部的,所以不用改
transport.tcp.port: 9300 #这个是容器内部的,所以不用改
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["192.168.31.89:9300","192.168.31.89:9301","192.168.117.232:9302"] #修改为docker的宿主机ip
discovery.zen.minimum_master_nodes: 2
indices.query.bool.max_clause_count: 10240
cluster.initial_master_nodes: es-node1
vim es03.yml
文件内容:
注意:需要修改文件中 network.publish_host,discovery.seed_hosts 两个配置项的IP
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 192.168.31.89 #修改为docker的宿主机ip
http.port: 9200 #这个是容器内部的,所以不用改
transport.tcp.port: 9300 #这个是容器内部的,所以不用改
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["192.168.31.89:9300","192.168.31.89:9301","192.168.117.232:9302"] #修改为docker的宿主机ip
discovery.zen.minimum_master_nodes: 2
indices.query.bool.max_clause_count: 10240
cluster.initial_master_nodes: es-node1
/usr/local/microservices/elasticSearch
目录下编写docker-compose.yml文件vim docker-compose.yml
文件内容:
version: '2.2'
services:
es01:
image: elasticsearch:7.8.0
container_name: es01
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- TAKE_FILE_OWNERSHIP=true
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es_data01:/usr/share/elasticsearch/data
- ./es_conf/_data/es01.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./es_plugins:/usr/share/elasticsearch/plugins
ports:
- 9200:9200
- 9300:9300
networks:
- es-net
restart: always
es02:
image: elasticsearch:7.8.0
container_name: es02
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- TAKE_FILE_OWNERSHIP=true
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es_data02:/usr/share/elasticsearch/data
- ./es_conf/_data/es02.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./es_plugins:/usr/share/elasticsearch/plugins
ports:
- 9201:9200
- 9301:9300
networks:
- es-net
restart: always
es03:
image: elasticsearch:7.8.0
container_name: es03
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- TAKE_FILE_OWNERSHIP=true
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./es_data03:/usr/share/elasticsearch/data
- ./es_conf/_data/es03.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./es_plugins:/usr/share/elasticsearch/plugins
ports:
- 9202:9200
- 9302:9300
networks:
- es-net
restart: always
networks:
es-net:
docker-compose up -d
docker ps
注意,此处启动后需要大概等1分钟的样子才能执行测试语句,不然会出现如下错误,具体原因本人还不清楚,知道的小伙伴,可以下方评论告诉我,谢谢
错误如下:
curl: (56) Recv failure: Connection reset by peer
curl localhost:9200
出现如下内容则表示搭建成功:
常见问题:
1.执行curl localhost:9200
后不能出现上图内容,使用docker logs 容器ID
命令查看日志,出现如下错误:
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase
解决方案:
vi /etc/sysctl.conf
在文件末尾新增如下内容:
vm.max_map_count = 655360
刷新系统配置
sysctl -p
2.在docker宿主机上执行curl localhost:9200
后可以出现上图内容,但是外网不能连接
在浏览器通过外网进行访问
http://docker宿主机IP:9200/
http://docker宿主机IP:9201/
http://docker宿主机IP:9202/
正常情况会出现如下页面:
若访问不到,可尝试如下解决办法:
2.1.检查防火墙,9200
,9201
,9202
,这三个端口是否开放
2.2.重启docker,重启ES集群
3.出现503错误
{
"error": {
"root_cause": [
{
"type": "cluster_block_exception",
"reason": "blocked by: [SERVICE_UNAVAILABLE/1/state not recovered / initialized];"
}
],
"type": "cluster_block_exception",
"reason": "blocked by: [SERVICE_UNAVAILABLE/1/state not recovered / initialized];"
},
"status": 503
}
解决方案:
将/usr/local/microservices/elasticSearch/
下的es_data01
,es_data02
,es_data03
,文件夹中的内容删除再重启
安装IK分词器
1.下载文件
IK分词器7.8.0下载地址
2.将下载好的elasticsearch-analysis-ik-7.8.0.zip
文件上传至/usr/local/microservices/elasticSearch/es_plugins
目录下
3.将压缩包移动到容器
docker cp /usr/local/microservices/elasticSearch/es_plugins/elasticsearch-analysis-ik-7.8.0.zip es01:/usr/share/elasticsearch/plugins
4.进入es01
容器
docker exec -it es01 /bin/bash
5.创建目录
mkdir /usr/share/elasticsearch/plugins/ik
6.将文件压缩包移动到ik目录下
mv /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik-7.8.0.zip /usr/share/elasticsearch/plugins/ik
5.进入目录
cd /usr/share/elasticsearch/plugins/ik
6.解压
unzip elasticsearch-analysis-ik-7.8.0.zip
7.退容器
exit
8.重启es集群
在/usr/local/microservices/elasticSearch/
目录下执行
#停止
docker-compose stop
#启动
docker-compose up -d
2.使用分词器后
至此,搭建成功