创建目录修改权限
加载镜像
docker load -i docker.elastic.co_elasticsearch_elasticsearch_8.15.0-arm64.tar.gz
docker load -i docker.elastic.co_kibana_kibana_8.15.0-arm64.tar.gz
创建网络
docker network create es-net
运行临时容器
docker run -d --rm -p 9200:9200 --name es docker.elastic.co/elasticsearch/elasticsearch:8.15.0
复制配置文件
docker cp es:/usr/share/elasticsearch/config/. /usr/local/docker/es/config/node1
docker cp es:/usr/share/elasticsearch/config/. /usr/local/docker/es/config/node2
创建docker-compose.yaml文件
version: '3' services:elasticsearch-node1:image: docker.elastic.co/elasticsearch/elasticsearch:8.15.0container_name: es-node1environment:- ELASTIC_PASSWORD=123456- "ES_JAVA_OPTS=-Xms8g -Xmx8g"ulimits: #启用内存锁定,防止 JVM 堆内存被交换到磁盘memlock:soft: -1hard: -1volumes:- ./data/node1:/usr/share/elasticsearch/data- ./logs/node1:/usr/share/elasticsearch/logs- ./plugins:/usr/share/elasticsearch/plugins- ./config/node1/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.ymlports:- 9200:9200networks:- es-netdeploy:resources:limits:memory: 10gelasticsearch-node2:image: docker.elastic.co/elasticsearch/elasticsearch:8.15.0container_name: es-node2environment:- ELASTIC_PASSWORD=123456- "ES_JAVA_OPTS=-Xms8g -Xmx8g"ulimits: #内存锁定避免es进程的内存被交换到磁盘Swapmemlock:soft: -1hard: -1volumes:- ./data/node2:/usr/share/elasticsearch/data- ./logs/node2:/usr/share/elasticsearch/logs- ./plugins:/usr/share/elasticsearch/plugins- ./config/node2/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.ymlports:- 9201:9200networks:- es-netdeploy:resources:limits:memory: 10gkibana:image: docker.elastic.co/kibana/kibana:8.15.0container_name: kibanaenvironment:- ELASTICSEARCH_HOSTS=https://es-node1:9200- ELASTICSEARCH_USERNAME=elastic- ELASTICSEARCH_PASSWORD=123456- ELASTICSEARCH_SSL_VERIFICATIONMODE=noneports:- 5601:5601networks:- es-netdepends_on:- elasticsearch-node1- elasticsearch-node2deploy:resources:limits:memory: 1.2gvolumes:# 使用绑定挂载,无需定义命名卷 networks:es-net:external: true
修改node1/node2下的配置文件elasticsearch.yml
cluster.name: es-cluster node.name: es-node1 network.host: 0.0.0.0 discovery.seed_hosts:- es-node2 cluster.initial_master_nodes:- es-node1- es-node2 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true path.data: /usr/share/elasticsearch/data path.logs: /usr/share/elasticsearch/logs bootstrap.memory_lock: true indices.query.bool.max_clause_count: 8192
cluster.name: es-cluster node.name: es-node2 network.host: 0.0.0.0 discovery.seed_hosts:- es-node1 cluster.initial_master_nodes:- es-node1- es-node2 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true path.data: /usr/share/elasticsearch/data path.logs: /usr/share/elasticsearch/logs bootstrap.memory_lock: true indices.query.bool.max_clause_count: 8192
停止临时容器启动集群
docker stop es
docker-compose up -d
临时容器中elasticsearch.yml文件
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 10-03-2025 13:22:59 # # --------------------------------------------------------------------------------# Enable security features xpack.security.enabled: truexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents xpack.security.http.ssl:enabled: truekeystore.path: certs/http.p12# Enable encryption and mutual authentication between cluster nodes xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/transport.p12truststore.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: ["dedd65e76d91"]#----------------------- END SECURITY AUTO CONFIGURATION -------------------------