要使用 Docker Compose 搭建一个 Elasticsearch 集群,并配置为不使用验证,同时使用 HTTP 访问,你可以遵循以下步骤:
确保你的系统上已安装 Docker 和 Docker Compose。如果尚未安装,请访问 Docker 的官方网站进行安装。
创建一个名为 docker-compose.yml
的文件,其中包含 Elasticsearch 集群的配置。以下是一个示例配置:
version: '3'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /home/sunyuhua/dockercom/es/es01/data:/usr/share/elasticsearch/data
- /home/sunyuhua/dockercom/es/es01/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200
networks:
- esnet
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /home/sunyuhua/dockercom/es/es02/data:/usr/share/elasticsearch/data
- /home/sunyuhua/dockercom/es/es02/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ulimits:
memlock:
soft: -1
hard: -1
networks:
- esnet
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- /home/sunyuhua/dockercom/es/es03/data:/usr/share/elasticsearch/data
- /home/sunyuhua/dockercom/es/es03/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ulimits:
memlock:
soft: -1
hard: -1
networks:
- esnet
networks:
esnet:
driver: bridge
在这个配置中:
xpack.security.enabled=false
禁用了 X-Pack 安全性(去除验证)。并编辑elasticsearch.yml 将https验证去掉
cluster.name: "docker-cluster"
network.host: 0.0.0.0
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 02-01-2024 08:12:14
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
# keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: false
# verification_mode: certificate
# keystore.path: certs/transport.p12
# truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["aa8bd846968c"]
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
在包含 docker-compose.yml
文件的目录中,打开终端或命令提示符。运行以下命令来启动集群:
docker-compose up -d
一旦集群启动,你可以通过访问 http://localhost:9200
来检查其状态。你可以使用 curl 或浏览器来执行此操作。
例如,使用 curl:
curl http://localhost:9200
你应该会看到关于 Elasticsearch 集群的一些基本信息。
ES_JAVA_OPTS
)。按照以上步骤,你应该能够成功搭建一个 Elasticsearch 集群,且无需进行用户验证,使用 HTTP 进行访问。