docker-compose + macvlan + Elasticsearch - 9.1.4 + Kibana - 9.1.4

操作过程

  1. 创建工作目录
mkdir -p /opt/porsCloud/24-elastic
  1. 进入工作目录
cd /opt/porsCloud/24-elastic
  1. 创建必要的目录
mkdir es_conf es_data es_logs es_plugins kibana_conf kibana_data
  1. 赋予权限
chown -R 1000:0 es_conf/ es_data/ es_logs/ es_plugins/ kibana_conf/ kibana_data/

或者

chmod -R 777 es_conf/ es_data/ es_logs/ es_plugins/ kibana_conf/ kibana_data/
  1. 添加 es_conf/elasticsearch.yml 文件
vim es_conf/elasticsearch.yml

内容如下

# 基础配置
cluster.name: "docker-cluster"
node.name: "elasticsearch-node"
network.host: 0.0.0.0
http.port: 9200
transport.port: 9300

# 发现和集群配置
discovery.type: single-node

# 禁用安全功能
xpack.security.enabled: false
xpack.security.enrollment.enabled: false

# 内存和性能配置
bootstrap.memory_lock: false

# 日志级别(可选)
logger.level: info

# 跨域配置(如果需要)
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: X-Requested-With,Content-Type,Content-Length,Authorization
  1. 添加 kibana_conf/kibana.yml 文件
vim es_conf/elasticsearch.yml

内容如下

server.host: "0.0.0.0"
server.port: 5601

i18n.locale: "zh-CN"

# Elasticsearch 连接配置(无安全认证)
elasticsearch.hosts: ["http://192.168.18.124:9200"]

# 最小化的加密密钥配置
xpack.encryptedSavedObjects.encryptionKey: "IAmSittingHereInTheBoringRoomItIsJustAnotherRainySundayAfternoon"
xpack.reporting.encryptionKey: "IAmSittingHereInTheBoringRoomItIsJustAnotherRainySundayAfternoon"
  1. 添加 docker-compose.yml 文件
vim docker-compose.yml

内容如下

services:
  elasticsearch:
    # 镜像名称
    image: elasticsearch:9.1.4
    # 容器名称
    container_name: elasticsearch
    networks:
      macvlan18:
       ipv4_address: 192.168.18.124
    # 端口映射
    ports:
      - "9200:9200"
      - "9300:9300"
    # 文件映射
    volumes:
      - /opt/porsCloud/24-elastic/es_data:/usr/share/elasticsearch/data # 数据
      - /opt/porsCloud/24-elastic/es_logs:/usr/share/elasticsearch/logs # 日志
      - /opt/porsCloud/24-elastic/es_plugins:/usr/share/elasticsearch/plugins # 插件
      - /opt/porsCloud/24-elastic/es_conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml # 配置文件
    # 环境配置
    environment:
      - "TZ=Asia/Shanghai"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m" # 内存限制(按需配置)
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9200/"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 120s
  kibana:
    depends_on:
      elasticsearch:
        condition: service_healthy
    image: kibana:9.1.4
    container_name: kibana
    networks:
      macvlan18:
       ipv4_address: 192.168.18.125
    ports:
      - "5601:5601"
    volumes:
      - /opt/porsCloud/24-elastic/kibana_data:/usr/share/kibana/data
      - /opt/porsCloud/24-elastic/kibana_conf/kibana.yml:/usr/share/kibana/config/kibana.yml
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5601/status"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 60s
networks:
  macvlan18:
    external: true
    name: macvlan18
  1. 新增 macvlan
docker network create -d macvlan --subnet=192.168.18.0/24 --ip-range=192.168.18.0/24 --gateway=192.168.18.254 -o parent=ens18 macvlan18
  1. 启动
docker-compose up -d
  1. 访问
  • http://192.168.18.124:9200/
  • http://192.168.18.125:5601/
  1. 访问 kibana 控制台 -> Management -> 堆栈监控 ,效果如下

docker-compose-es-kibana-1

posted @ 2025-09-25 18:35  chan_炽烽  阅读(34)  评论(0)    收藏  举报