Files
blog-press/docs/DevOps/ElasticSearch.md
2025-12-15 19:53:21 +08:00

85 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<ArticleMetadata />
## 一、基础概念
## 二、Docker部署
```yml
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
container_name: elasticsearch
environment:
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- xpack.security.enabled=true
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
ports:
- "9200:9200"
volumes:
- ./elasticsearch-data:/usr/share/elasticsearch/data
networks:
- devops
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -sS -u elastic:${ELASTIC_PASSWORD} http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=5s || exit 1"]
interval: 10s
timeout: 10s
retries: 3
start_period: 60s
kibana:
image: docker.elastic.co/kibana/kibana:8.12.0
container_name: kibana
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
- ELASTICSEARCH_USERNAME=kibana_system
- ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
ports:
- "5601:5601"
networks:
- devops
restart: unless-stopped
depends_on:
elasticsearch:
condition: service_healthy
networks:
devops:
driver: bridge
volumes:
elasticsearch-data:
driver: local
```
&emsp;&emsp;elasticsearch和kibana版本要保持一致该镜像较大可以先使用docker pull拉取到本地。
&emsp;&emsp;ELASTIC_PASSWORD和KIBANA_PASSWORD可以通过.env配置文件设置。
&emsp;&emsp;启动时elasticsearch可能会提示elasticsearch-data文件夹权限问题目前解决方案为将其权限设置为777。
## 三、简单使用
### 3.1 安装插件
&emsp;&emsp;启动成功后需要安装elasticsearch的分词插件analysis-ik。
&emsp;&emsp;进入Docker容器输入指令
```cmd
bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.12.0
```
&emsp;&emsp;注意版本要匹配。https://github.com/infinilabs/analysis-ik/releases/tag/Latest
&emsp;&emsp;安装完成后,重启容器。
### 3.2 更改密码
&emsp;&emsp;启动成功后需要更改elasticsearch的账号密码不知道为啥docker-compose文件设置的密码不行可能是容器初始化后又重置了
&emsp;&emsp;进入Docker容器输入指令
```cmd
bin/elasticsearch-setup-passwords interactive
```
&emsp;&emsp;根据提示输入相应的账号密码。
### 3.3 新建索引
1. 打开Elastic控制台选择Management->Dev Tools输入语句新建索引。
2. 选择Management->Stack Management->Data Views选择Create data view新建数据视图。
3. 输入name、index pattern刚才新建的索引和Timestamp信息保存数据视图。
4. 选择Discover选择刚才的数据视图即可查看该视图下所有数据。