2019-04-10 18:19:57
李明
|
一起在说说docker swarm
docker swarm init
#加入到manager中
docker swarm join-token manager
#加入到worker中
docker swarm join-token worker
环境搭建
应用IP地址服务配置安装应用安装方式docker-swarm-manager1192.168.66.100docker-swarm-manager1单核 2g内存docker-swarm-manager1dockerdocker-swarm-manager2192.168.66.101docker-swarm-manager2单核 2g内存docker-swarm-manager2dockerdocker-swarm-node1192.168.66.102docker-swarm-node1单核 2g内存docker-swarm-node1dockerdocker-swarm-node2192.168.66.103docker-swarm-node2单核 2g内存docker-swarm-node2docker
docker swarm环境
su -
#密码vagrant
docker swarm init
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on different interfaces (10.0.2.15 on enp0s3 and 192.168.66.100 on enp0s8) - specify one with --advertise-addr
docker swarm init --advertise-addr 192.168.66.100 --listen-addr 192.168.66.100:2377docker swarm join-token manager
docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-9qutkvpzk87chtr4pv8770mcb 192.168.66.100:2377
docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-f2dlt8g3hg86gyc9x6esewtwl 192.168.66.100:2377
docker swarm join --token SWMTKN-1-4itumtscktomolcau8a8cte98erjn2420fy2oyj18ujuvxkkzx-f2dlt8g3hg86gyc9x6esewtwl 192.168.66.100:2377
查看swarm集群
docker node ls
查看swarm集群的网络
docker network ls
创建容器间的共享网络
docker network create -d overlay --attachable swarm_testdocker network ls
创建5个pxc容器
docker volume create v1docker volume create backup1
#增加域名解析
echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://b81aace9.m.daocloud.iosudo systemctl restart dockerdocker run -d -p 3306:3306 --net=swarm_test \ --name=node1 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v1:/var/lib/mysql \ --privileged \ -v backup1:/data \ percona/percona-xtradb-clusterdocker ps
docker volume create v2docker run -d -p 3307:3306 --net=swarm_test \ --name=node2 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v2:/var/lib/mysql \ --privileged \ -v backup1:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps
docker volume create v3docker volume create backup3docker run -d -p 3307:3306 --net=swarm_test \ --name=node3 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v3:/var/lib/mysql \ --privileged \ -v backup3:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps
docker volume create v4docker volume create backup4docker run -d -p 3307:3306 --net=swarm_test \ --name=node4 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v4:/var/lib/mysql \ --privileged \ -v backup4:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps
docker volume create v4docker volume create backup4docker run -d -p 3307:3306 --net=swarm_test \ --name=node4 \ -e CLUSTER_NAME=PXC \ -e MYSQL_ROOT_PASSWORD=a123456 \ -e XTRABACKUP_PASSWORD=a123456 \ -v v4:/var/lib/mysql \ --privileged \ -v backup4:/data \ -e CLUSTER_JOIN=node1 \ percona/percona-xtradb-clusterdocker ps
容器集群
容器集群适合的场景
image.png
退出Swarm集群
#Manager退出必须加--force
docker swarm leave --force
删除节点
service docker stop
#Manager节点需要先降级
docker node demoted <nodeID>docker node rm <nodeID>docker network
PS:这次主要说了3点比较重要的:通过docker-swarm的网络搭建容器化通信网络,创建集群的时候--net 加入docker-swarm创建的网络,方便通信。不哪些适合做容器化集群,数据库和缓存。如何操作docker-swarm中的节点。
|