标签:ted msi shel json creat node reg yun add
1.使用 vagrant 部署 三台 centos/7 的 环境
###Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name=>"docker-host",
:eth1=>"192.168.205.10",
:mem=>"1024",
:cpu=>"1",
:port=>"8888"
},
{
:name=>"docker-node1",
:eth1=>"192.168.205.11",
:mem=>"1024",
:cpu=>"1",
:port=>"8889"
},
{
:name=>"docker-node2",
:eth1=>"192.168.205.12",
:mem=>"1024",
:cpu=>"1",
:port=>"8890"
}
]
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.network "forwarded_port", guest: 80, host: opts[:port]
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
2.编写 setup.sh
###setup.sh
#/bin/sh
# install some tools
sudo yum install -y wget
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo yum makecache
sudo yum -y update
sudo yum install -y git vim gcc glibc-static telnet bridge-utils
# install docker
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
# start docker service
sudo groupadd docker
sudo usermod -aG docker vagrant
sudo systemctl start docker
rm -rf get-docker.sh
sudo tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://v2ltjwbg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker version
3.创建labs 文件夹 并启动容器
mkdir lables
vagrant up
4. 进去 host 节点
vagrant ssh docker-host
声明节点
docker swarm init --advertise-addr=192.168.205.10
只需要 在其他节点运行这段代码 即可 进入这个节点
5. 进入node1节点 并 加入 swarm 集群
进入docker-node1 节点
vagrant ssh docker-node1
运行刚刚生成的代码即可加入 swarm 集群
在 host 节点查看集群节点情况
docker-host 下
docker node ls
docker-node2 节点同理
6. 在 docker-machine 上进行 swarm 安装
docker-machine create swarm-manager
docker-machine create swarm-node1
docker-machine create swarm-node2
同理 加入
7. 在 labs.play-with-docker.com
常见三个虚拟主机即可运行上面的命令即可
29. docker swarm 创建 三个节点 swarm 的集群
标签:ted msi shel json creat node reg yun add
原文地址:https://www.cnblogs.com/zonehoo/p/11378863.html