springboot 2.7.18
<properties>
<!-- 显式指定 Elasticsearch 版本,确保与服务器一致 -->
<elasticsearch.version>7.17.18</elasticsearch.version>
</properties>
<dependencies>
<!-- Elasticsearch 核心依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</dependencies>
spring:
elasticsearch:
uris: http://localhost:9200 # ES 地址,如果是集群可写多个
username: elastic # 如果开启了安全认证需填写
password: your_password # 如果开启了安全认证需填写
connection-timeout: 5s # 连接超时
socket-timeout: 30s # 读取超时
安装
mkdir -p /vuser/app/elasticsearch/config
mkdir -p /vuser/app/elasticsearch/data
mkdir -p /vuser/app/elasticsearch/logs
chmod -R 777 /vuser/app/elasticsearch/
docker run --name es-temp -d elasticsearch:7.17.18
docker cp es-temp:/usr/share/elasticsearch/config/elasticsearch.yml /vuser/app/elasticsearch/config/
docker stop es-temp && docker rm es-temp
#直接在 /vuser/app/elasticsearch/config/elasticsearch.yml 填入以下内容
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 开启跨域访问,方便 Kibana 或 Head 插件连接
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
# 单节点模式
discovery.type: single-node
docker run -d \
--name es7 \
-p 9200:9200 \
-p 9300:9300 \
-e "ES_JAVA_OPTS=-Xms2g -Xmx2g" \
-v /vuser/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /vuser/app/elasticsearch/data:/usr/share/elasticsearch/data \
-v /vuser/app/elasticsearch/logs:/usr/share/elasticsearch/logs \
elasticsearch:7.17.18
安装 IK 分词器 (中文搜索必备)
docker exec -it es7 /bin/bash
# 进入 bin 目录
cd /usr/share/elasticsearch/bin
# 在线安装 IK 分词器 (版本对应 7.17.18)
./elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/7.17.18
docker restart es7
docker logs -f -n 1000 es7
查看
http://192.168.1.100:9200
http://192.168.1.100:9200/_cat/health?v
http://192.168.100.30:9200/_cat/plugins?v