docker-compose部署es集群

通过docker-compose部署es集群。es最新版本:7.5.1

mkdir -p /home/elfk/elasticsearch/config

mkdir /home/elfk/elasticsearch/{data1,data2,data3}

cd /home/elfk

echo 'ELK_VERSION=7.5.1' > .env
tree .

.
├── docker-compose.yml
└── elasticsearch
    ├── config
    │   └── elasticsearch.yml
    ├── data1
    ├── data2
    ├── data3
    └── Dockerfile

5 directories, 3 files

elasticsearch

Dockerfile

vim /home/elfk/elasticsearch/Dockerfile
ARG ELK_VERSION=7.5.1

# https://github.com/elastic/elasticsearch-docker
# FROM docker.elastic.co/elasticsearch/elasticsearch:${ELK_VERSION}
FROM elasticsearch:${ELK_VERSION}
# Add your elasticsearch plugins setup here
# Example: RUN elasticsearch-plugin install analysis-icu

elasticsearch.yml

vim /home/elfk/elasticsearch/config/elasticsearch.yml
---
## Default Elasticsearch configuration from Elasticsearch base image.
## https://github.com/elastic/elasticsearch/blob/master/distribution/docker/src/docker/config/elasticsearch.yml
#
cluster.name: "es-docker-cluster"
network.host: 0.0.0.0

## X-Pack settings
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack.html
#
xpack.license.self_generated.type: trial                                #trial为试用版,一个月期限,可更改为basic版本
xpack.security.enabled: true
xpack.monitoring.collection.enabled: true

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

docker-compose.yml

vim /home/elfk/docker-compose.yml
version: '3.7'
services:
  es01:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: $ELK_VERSION
    container_name: es01
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - type: volume
        source: data01
        target: /usr/share/elasticsearch/data
    ports:
      - 9200:9200
    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
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - elastic
  es02:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: $ELK_VERSION
    container_name: es02
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - type: volume
        source: data02
        target: /usr/share/elasticsearch/data
    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
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - elastic
  es03:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: $ELK_VERSION
    container_name: es03
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - type: volume
        source: data03
        target: /usr/share/elasticsearch/data
    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
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - elastic

volumes:
  data01:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/elfk/elasticsearch/data1
      
  data02:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/elfk/elasticsearch/data2
      
  data03:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /home/elfk/elasticsearch/data3

networks:
  elastic:
    driver: bridge
if [ $(grep 'vm.max_map_count' /etc/sysctl.conf |wc -l) -eq 0 ] ; \
then echo 'vm.max_map_count=655360' >> /etc/sysctl.conf; \
fi

sysctl -p

docker-compose up --build -d
docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
5af70e32dbb8        elfk_es01           "/usr/local/bin/dock…"   14 seconds ago      Up 6 seconds        0.0.0.0:9200->9200/tcp, 9300/tcp   es01
793bab4160b7        elfk_es03           "/usr/local/bin/dock…"   14 seconds ago      Up 6 seconds        9200/tcp, 9300/tcp                 es03
93ffa61c639f        elfk_es02           "/usr/local/bin/dock…"   14 seconds ago      Up 6 seconds        9200/tcp, 9300/tcp                 es02

netstat -lntp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1303/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      936/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1303/master         
tcp6       0      0 :::9200                 :::*                    LISTEN      8724/docker-proxy   
tcp6       0      0 :::22                   :::*                    LISTEN      936/sshd

你可能感兴趣的:(ELFK,Docker)