美文网首页
docker-compose搭建es集群

docker-compose搭建es集群

作者: 谜00016 | 来源:发表于2019-06-25 14:51 被阅读0次

    参考 使用 Docker 快速部署 Elasticsearch 集群(https://segmentfault.com/a/1190000018606414)
    。仅供自己记录查阅

    环境

    • 使用vagrant 搭建虚拟机
      vagrantfile
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    Vagrant.require_version ">= 1.6.0"
    
    boxes = [
        {
            :name => "docker-dev",
            :eth1 => "192.168.56.113",
            :mem => "6144",
            :cpu => "2"
        }
    ]
    
    Vagrant.configure(2) do |config|
    
      config.vm.box = "centos/7"
      boxes.each do |opts|
        config.vm.define opts[:name] do |config|
          config.vm.hostname = opts[:name]
          config.vm.provider "vmware_fusion" do |v|
            v.vmx["memsize"] = opts[:mem]
            v.vmx["numvcpus"] = opts[:cpu]
          end
          config.vm.provider "virtualbox" do |v|
            v.customize ["modifyvm", :id, "--memory", opts[:mem]]
            v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
          end
          config.vm.network :private_network, ip: opts[:eth1]
        end
      end
    #  config.vm.synced_folder "./labs", "/home/vagrant/labs"
    #  config.vm.provision "shell", privileged: true, path: "./setup.sh"
    end
    
    
    • docker-compose版本:1.23.2
    • es 版本 elasticsearch:6.6.2

    docker-compose安装

    #docker-compose
    sudo curl -L \
    https://get.daocloud.io/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` \
    > /usr/local/bin/docker-compose
    
    sudo chmod +x /usr/local/bin/docker-compose
    
    #查看安装结果
    docker-compose -v
    

    创建目录

    #创建数据/日志目录 这里我们部署3个节点
    mkdir /opt/myes/data/{node0,node1,node2} -p
    mkdir /opt/myes/logs/{node0,node1,node2} -p
    cd /opt/elasticsearch
    #权限我也很懵逼啦 给了 privileged 也不行 索性0777好了
    chmod 0777 data/* -R && chmod 0777 logs/* -R
    
    #防止JVM报错
    echo vm.max_map_count=262144 >> /etc/sysctl.conf
    sysctl -p
    

    docker-compose.yml

    version: '3'
    services:
      elasticsearch_n0:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n0
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node0
          - node.master=true
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/node0:/usr/share/elasticsearch/data
          - ./logs/node0:/usr/share/elasticsearch/logs
        ports:
          - 9200:9200
      elasticsearch_n1:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n1
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node1
          - node.master=true
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/node1:/usr/share/elasticsearch/data
          - ./logs/node1:/usr/share/elasticsearch/logs
        ports:
          - 9201:9200
      elasticsearch_n2:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n2
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node2
          - node.master=true
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - ./data/node2:/usr/share/elasticsearch/data
          - ./logs/node2:/usr/share/elasticsearch/logs
        ports:
          - 9202:9200
      kibana:
        image: docker.elastic.co/kibana/kibana:6.6.2
        container_name: kibana
        environment:
          - SERVER_NAME=kibana
          - ELASTICSEARCH_URL=http://elasticsearch_n0:9200
          - XPACK_MONITORING_ENABLED=true
        ports:
          - 5601:5601
        depends_on:
          - elasticsearch_n0
    
    

    启动服务

    #启动
    docker-compose up -d
    #查看
    docker-compose ps
    

    使用谷歌浏览器,安装Elasticsearch Head插件,可视化es

    ----ps 后续增加了需求,在其中一台服务器上添加主节点,另一台服务器添加两个从节点
    主服务器:

    version: '3'
    services:
      elasticsearch_n0:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n0
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node0
          - node.master=true
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - network.host=0.0.0.0
          - node.ingest=true
          - network.publish_host=x.x.x.63
          - http.port=9200
          - transport.tcp.port=9300
          - discovery.zen.ping.unicast.hosts=x.x.x.63:9300,x.x.x.59:9300,x.x.x.59:9301
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
          nofile:
            soft: 262144
            hard: 262144
        volumes:
          - ./data/node0:/usr/share/elasticsearch/data
          - ./logs/node0:/usr/share/elasticsearch/logs
        ports:
          - 9200:9200
          - 9300:9300
        restart: always
      kibana:
        image: docker.elastic.co/kibana/kibana:6.6.2
        container_name: kibana
        environment:
          - SERVER_NAME=kibana
          - ELASTICSEARCH_URL=http://x.x.x.63:9200
          - XPACK_MONITORING_ENABLED=true
        ports:
          - 5601:5601
        depends_on:
          - elasticsearch_n0
    
    

    从节点服务器

    version: '3'
    services:
      elasticsearch_n1:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n1
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node1
          - node.master=true
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - network.host=0.0.0.0
          - node.ingest=true
          - network.publish_host=x.x.x.59
          - http.port=9200
          - transport.tcp.port=9300
          - discovery.zen.ping.unicast.hosts=x.x.x.63:9300,x.x.x.59:9300
          - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
          nofile:
            soft: 262144
            hard: 262144
        volumes:
          - ./data/node1:/usr/share/elasticsearch/data
          - ./logs/node1:/usr/share/elasticsearch/logs
        ports:
          - 9200:9200
          - 9300:9300
        restart: always
      elasticsearch_n2:
        image: elasticsearch:6.6.2
        container_name: elasticsearch_n2
        privileged: true
        environment:
          - cluster.name=elasticsearch-cluster
          - node.name=node2
          - node.master=false
          - node.data=true
          - bootstrap.memory_lock=true
          - http.cors.enabled=true
          - http.cors.allow-origin=*
          - network.host=0.0.0.0
          - node.ingest=true
          - network.publish_host=x.x.x.59
          - http.port=9200
          - transport.tcp.port=9301
          - discovery.zen.ping.unicast.hosts=x.x.x.63:9300,x.x.x.59:9300,x.x.x.59:9301
          - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
          - "discovery.zen.minimum_master_nodes=2"
        ulimits:
          memlock:
            soft: -1
            hard: -1
          nofile:
            soft: 262144
            hard: 262144
        volumes:
          - ./data/node2:/usr/share/elasticsearch/data
          - ./logs/node2:/usr/share/elasticsearch/logs
        ports:
          - 9201:9201
          - 9301:9301
        restart: always
    

    相关文章

      网友评论

          本文标题:docker-compose搭建es集群

          本文链接:https://www.haomeiwen.com/subject/odctcctx.html