前置:
- 在docker-comepose.yml创建文件夹并赋予读取写入权限data plugins logs, 分别是存储数据,存放插件,存放日志
- docker network ls
查看是否已经有网络elastic,没有使用docker network create elastic 创建 - 下载分词器elasticsearch-analysis-ik-8.14.2,kibana和ik分词器都要和es版本一致
下载地址Index of: analysis-ik/stable/
解压文件到plugins目录中如/plugins/elasticsearch-analysis-ik-8.14.2
测试ik中文分词: 访问kibana 开发工具控制台
POST _analyze
{
"analyzer": "ik_smart",
"text": "Elasticsearch 是一个强大的搜索引擎。"
}
效果:
文件目录:
docker-compose.yml
version: '3'
services:
es8:
image: docker.elastic.co/elasticsearch/elasticsearch:8.14.2
container_name: es8
networks:
- elastic
ports:
- 9200:9200
- 9300:9300
mem_limit: 2GB
volumes:
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./data:/usr/share/elasticsearch/data
- ./logs:/usr/share/elasticsearch/logs
- ./plugins:/usr/share/elasticsearch/plugins
environment:
# - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
- "TZ=Asia/Shanghai"
- "discovery.type=single-node"
- "ELASTIC_PASSWORD=123456"
kibana8:
container_name: kibana8
image: docker.elastic.co/kibana/kibana:8.14.2
networks:
- elastic
# restart: always
ports:
- 5601:5601
environment:
- ELASTICSEARCH_HOSTS=http://192.168.48.129:9200
volumes:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml # kibana 其实是支持中文的,只要在 /usr/share/kibana/config/kibana.yml 加一行 i18n.locale: "zh-CN"
networks:
elastic:
# 引用已存在网络
external: true
elasticsearch.yml
cluster.name: "docker-cluster-elk8"
network.host: 0.0.0.0
# Enable security features
xpack.security.enabled: false
kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.48.129:9200"]
i18n.locale: "zh-CN"
在虚拟机挂起后再启动会导致es无法连接
可能网络原因,重启网络和docker未解决,需要机器重启