『中级篇』docker-swarm创建一个多节点集群(43)

docker Swarm是Docker官方提供的一款集群管理工具,其主要作用是把若干台Docker主机抽象为一个整体,并且通过一个入口统一管理这些Docker主机上的各种Docker资源。源码地址:https://github.com/limingios/docker中的No.5

创建3台虚拟机

还是通过vagrant + virtualbox的方式来创建

  • 源码文件夹

  • 查看创建虚拟机的源码
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"

boxes = [
    {
        :name => "swarm-manager",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "swarm-worker1",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "swarm-worker2",
        :mem => "1024",
        :cpu => "1"
    }
]

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, type: "dhcp"
      end
  end

  config.vm.synced_folder "./labs", "/home/vagrant/labs"
  config.vm.provision "shell", privileged: true, path: "./setup.sh"

end

用SecureCRT连接着3个虚拟机
  • 查看每个虚拟机的ip地址
vagrant ssh swarm-manager
#swarm-manager的ip是172.28.128.3
ip a

vagrant ssh swarm-worker1
#swarm-worker1的ip是172.28.128.4
ip a

vagrant ssh swarm-worker2
#swarm-worker2的ip是172.28.128.5
ip a

创建docker-swarm集群
  1. swarm-manager 建立manager
 sudo docker swarm init --help
 sudo docker swarm init --advertise-addr=172.28.128.3

  1. swarm-worker1 和 swam-worker2 连接manager
sudo service docker restart
docker swarm join --token SWMTKN-1-1vafvfucsur6iqd6ba5i2njty6djvzxnhwefsmar4sivcg8isi-dgm1aigtcu1rtotfc8y43j17m 172.28.128.3:2377

image.png

  1. swarm-manager 查看连接状态
docker node ls

PS:这样基本上通过docker-swarm完成集群管理。

>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
>>原文链接地址:『中级篇』docker-swarm创建一个多节点集群(43)
上一篇: 下一篇:

发表评论

电子邮件地址不会被公开。 必填项已用*标注