1、介绍
本教程使用Compose、Machine、Swarm工具把WordPress部署在OpenStack上。
本节采用Consul作为Swarm的Discovery Service模块,要利用Consul实现服务的注册与发现,需要建立Consul Cluster。在Consul方案中,每个提供服务的节点上都要部署和运行Consul的agent,所有运行Consul agent节点的集合会构成Consul Cluster。
2、创建虚拟机
使用docker-machine create命令创建5个虚拟机,其中虚拟机1用作Swarm的Master,虚拟机2用作Consul的服务发现,虚拟机3~5用作Swarm的节点。
创建lfkdockermachine1虚拟机
#docker-machine create -d openstack --openstack-insecure --openstack-auth-url=Keystone_Auth_URL --openstack-username=UserName --openstack-password=PassWord --openstack-tenant-id=TenantID --openstack-tenant-name=TenantName --openstack-flavor-id=FlavorID --openstack-image-id=ImageID --openstack-region=az0.dcl --openstack-net-id=NetID --openstack-availability-zone=az1.dc1 --openstack-sec-groups=GroupsID --openstack-floatingip-pool=external_relay_network lfkdockermachine1
Creating machine...
更多参数详见:https://docs.docker.com/machine/drivers/openstack/#options
3、查看虚拟机
#docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
lfkdockermachine1 openstack running tcp://100.64.0.31:2376
lfkdockermachine2 openstack running tcp://100.64.0.32:2376
lfkdockermachine3 openstack running tcp://100.64.0.33:2376
lfkdockermachine4 openstack running tcp://100.64.0.34:2376
lfkdockermachine5 openstack running tcp://100.64.0.35:2376
通过OpenStack的nova list查看
#nova list --all_te | grep lfk | head -1
| 65ad59c7-39df-4cdc-8957-eb2e396ac8d6 | lfkdockermachine1 | ACTIVE | - | Running | docker-VM_network=192.168.10.91,100.64.0.31 |
4、搭建Swarm的Discovery Service模块
在lfkdockermachine2上通过consul命令搭建Consul Server节点
#consul agent -server -bootstrap-expect=1 -data-dir=data -bind=192.168.10.92 -client=192.168.10.92 &
在lfkdockermachine3、lfkdockermachine4、lfkdockermachine5上搭建Consul Client节点
#consul agent -data-dir=data -node=lfkdockermachine3 -join=192.168.10.92 -bind=192.168.10.93 -client=192.168.10.93 &
此时在日志lfkdockermachine2上可看到Consul Client节点加入了集群
consul:member 'lfkdockermachine3' joined, marking health alive
将lfkdockermachine4和lfkdockermachine5也加入集群
在Consul Server节点通过members命令列出整个集群的综合信息
#consul members -rpc-addr=192.168.10.92:8400
Node Address Status Type Build Protocol
lfkdockermachine2 192.168.10.92 alive server 0.5.0 2
lfkdockermachine3 192.168.10.93 alive client 0.5.0 2
lfkdockermachine4 192.168.10.94 alive client 0.5.0 2
lfkdockermachine5 192.168.10.95 alive client 0.5.0 2
5、搭建Swarm集群
在lfkdockermachine1上搭建Swarm Master,直接使用官方提供的Swarm可执行程序来创建Swarm Master
#swarm manage consul://192.168.10.92:8500/swarm --strategy "random" -H tcp://0.0.0.0:2375 &
[2] 3307
INFO[0000] Listening for HTTP addr=0.0.0.0:2375 proto=tcp
使用swarm join将3~5加入swarm集群
#swarm join consul://192.168.10.92:8500/swarm --addr=192.168.10.93:2375 &
在Swarm Master上查看Swarm节点信息
#swarm list consul://192.168.10.192:8500/swarm
192.168.10.93:2375
192.168.10.94:2375
192.168.10.95:2375
5、利用Compose部署WordPress
借鉴:http://www.cnblogs.com/XYJK1002/p/5386187.html
部署系统
# docker-compose up
查看是否启动
# docker -H tcp://192.168.10.92:2375 ps -a