网上的关于 ElasticSearch 8.x 的部署文章,多半都是用的官方镜像,但是官方镜像很多特性都已经弃用或者修改了,很多环境变量也用不了。导致部署起来很不顺手。官方文档又写得非常的简陋,对于单机部署的文档可以说基本没有。对于开发环境来说,部署集群显然没有必要。自己写 Dockerfile 来 build 又有点太麻烦。刚好看到 bitnami 的镜像文档很齐全,就正好拿来用了。试了下,跑起来很丝滑,很优雅。

# $kibana_password 和 $elastic_password 替换成自己的密码即可
services:
  elasticsearch:
    image: bitnami/elasticsearch:8.15.1  # 请根据需要选择合适的版本
    container_name: elasticsearch
    healthcheck:
      test: ["CMD-SHELL", "curl --silent --fail -u elastic:$elastic_password localhost:9200/_cluster/health || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
    environment:
      - "ELASTICSEARCH_VOLUME_DIR=/bitnami/elasticsearch"
      - "ELASTICSEARCH_NODE_NAME=misaka-es01"
      - "ELASTICSEARCH_CLUSTER_NAME=misaka-cluster"
      - "ELASTICSEARCH_BIND_ADDRESS=0.0.0.0"
      - "ELASTICSEARCH_HTTP_PORT_NUMBER=9200"
      - "ELASTICSEARCH_TRANSPORT_PORT_NUMBER=9300"
      - "ELASTICSEARCH_ENABLE_SECURITY=true"
      - "ELASTICSEARCH_HEAP_SIZE=1024m"
      - "ELASTICSEARCH_MAX_ALLOWED_MEMORY=1536"
      - "ELASTICSEARCH_IS_DEDICATED_NODE=false"
      - "ELASTICSEARCH_ENABLE_REST_TLS=false"
      - "ELASTICSEARCH_SKIP_TRANSPORT_TLS=true"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "ELASTICSEARCH_PASSWORD=$elastic_password"
    volumes:
      - ./es/data:/bitnami/elasticsearch/data
      - ./es/plugins:/bitnami/elasticsearch/plugins
      - ./es/logs:/opt/bitnami/elasticsearch/logs
    ports:
      - 9200:9200
      - 9300:9300

  kibana:
    image: bitnami/kibana:8.15.1  # 确保Kibana版本与Elasticsearch版本兼容
    container_name: kibana
    environment:
      - "KIBANA_ELASTICSEARCH_URL=elasticsearch"
      - "KIBANA_ELASTICSEARCH_PORT_NUMBER=9200"
      - "KIBANA_HOST=0.0.0.0"
      - "KIBANA_PORT_NUMBER=5601"
      - "KIBANA_CREATE_USER=true"
      - "KIBANA_PASSWORD=$kibana_password"
      - "KIBANA_ELASTICSEARCH_PASSWORD=$elastic_password"
      - "KIBANA_VOLUME_DIR=/bitnami/kibana"
    volumes:
      - ./es/kibana:/bitnami/kibana
    ports:
      - 5601:5601
    depends_on:
      elasticsearch:
        condition: service_healthy  

其中,插件的压缩包放在 ./es/plugins 中,每次启动时会自动安装。以 插件名-版本号.zip 的命名规则以命名,例如:analysis-ik-8.15.1.zip

也可以自己配置 kibana.yml 。放在 ./es/kibana/conf/kibana.yml 即可。