docker swarm 搭建 elasticsearch 集群

本次使用镜像为官方6.x镜像

容器版本为

Docker version 18.09.4, build d14af54266


version: '3.3'
services:
  es:
    image: shihangyu/es
    networks:
      - es
    ports:
      - 6666:9200
      - 9300:9300
    environment:
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
      discovery.zen.ping.unicast.hosts: es1, es
      cluster.name: my-application
    volumes:
      -  /home/dockeres/db:/usr/share/elasticsearch/data
      - /home/dockeres/db/log:/usr/share/elasticsearch/logs
    deploy:
      restart_policy:
        condition: on-failure
      replicas: 1
      placement:
        constraints:
          - node.hostname==slaver-02
      resources:
        limits:
          cpus: '2'
          memory: 2200M
        reservations:
          cpus: '0.5'
          memory: 800M      
  es1:
    image: shihangyu/es
    networks:
      - es
    environment:
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
      discovery.zen.ping.unicast.hosts: es1, es    
      cluster.name: my-application
    volumes:
      -  /home/dockeres/db:/usr/share/elasticsearch/data 
      - /home/dockeres/db/log:/usr/share/elasticsearch/logs
    deploy:
      restart_policy:
        condition: on-failure   
      replicas: 1
      placement:
        constraints:
         - node.hostname==slaver-01
      endpoint_mode: dnsrr
      resources:
        limits:
          cpus: '2'
          memory: 2200M
        reservations:
          cpus: '0.5'
          memory: 800M 
                  
networks:
  es:
    external: true

 

创建目录作为数据存储地址

      -  /home/dockeres/db
      - /home/dockeres/db/log

 

#启动时可能报错

echo "vm.max_map_count=655300" > /etc/sysctl.conf

sysctl -p

2gvq4e9qgcew        es_es               replicated          1/1                 shihangyu/es:latest                     *:6666->9200/tcp, *:9300->9300/tcp
sisshra1a16j        es_es1              replicated          1/1                 shihangyu/es:latest                

 

swarm elasticsearch 启动成功 

公司用kibana 来做elasticsearch mapping 创建

接下来构建 kibana 

version: '3.3'
services:
  kiban:
    image: docker.elastic.co/kibana/kibana:6.4.2
    ports:
      - 5603:5601
    networks:
      - es
    environment:
      - ELASTICSEARCH_URL=http://es:9200
    configs:
      - source: kibana.yml
        target: /usr/share/kibana/config/kiban.yml                             
    deploy:
      restart_policy:
        condition: on-failure
      replicas: 1
      placement:
        constraints:
          - node.hostname==slaver-01
      endpoint_mode: vip
      resources:
        limits:
          cpus: '2'
          memory: 1500M
        reservations:
          cpus: '0.5'
          memory: 800M
networks:
   es:
    external: true
        
configs:
  kibana.yml:
    file: ./kibana.yml

kibana yml文件

[root@master docker]# cat kibana.yml 
server.name: kibana
server.host: "0.0.0.0"
elasticsearch.url: http://es:9200
#elasticsearch.username: elastic
#elasticsearch.password: acl123456
xpack.monitoring.ui.container.elasticsearch.enabled: true
xpack.security.enabled: false

注意kibana 版本一定要和es版本一致 

 

你可能感兴趣的:(运维,docker,swarm,集群搭建)