李明
|
创建3台虚拟机
# -*- 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个虚拟机
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集群
sudo docker swarm init --help sudo docker swarm init --advertise-addr=172.28.128.3
sudo service docker restart docker swarm join --token SWMTKN-1-1vafvfucsur6iqd6ba5i2njty6djvzxnhwefsmar4sivcg8isi-dgm1aigtcu1rtotfc8y43j17m 172.28.128.3:2377
docker node ls
PS:这样基本上通过docker-swarm完成集群管理。
|
2018-09-27 01:08:15