**1.规划网络的拓扑图
2.准备机器,安装软件,并开启服务
1.准备6台linux centos7.9的服务器
2.安装nfs并开启服务
下载nfs服务
[root@localhost ~] yum install nfs-utils -y
开启nfs服务
[root@localhost ~] service nfs-server start
Redirecting to /bin/systemctl start nfs-server.service
建立需要挂载的目录并授权
[root@localhost ~] mkdir /web
[root@localhost ~] chmod 777 /web
使用exportfs导出目录,无需重启nfs服务
[root@localhost ~b] exportfs -v
/web 192.168.133.0/24(rw,all_squash,sync)
3.3台使用yum安装docker 1.13的版本,设置并开启swarm集群
选择manager节点,配置host文件,添加ip和域名的对应记录
[root@localhost ~] cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.133.136 manager1
192.168.133.137 node2
192.168.133.138 node3
使用scp传输到另外两台节点
[root@localhost ~] scp /etc/hosts root@192.168.133.137:/etc/hosts
[root@localhost ~] scp /etc/hosts root@192.168.133.138:/etc/hosts
所有机器上关闭防火墙和selinux
[root@localhost ~] service firewalld stop
[root@localhost ~] sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
创建swarm集群
[root@localhost ~] docker swarm init --advertise-addr 192.168.133.136
Swarm initialized: current node (g8hyq7b24dsfy93s6l9mx3c6g) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5y27v1oaiwrb9jvedcv9hssfxnqjw4mubjkd8vwwmyqdsaumbl-2gy1wvaraly12bko6hhe4qcy1 192.168.174.128:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
复制docker swarm join…到其他节点上运行,加入manager节点
创建一个overlay类型的网络
[root@localhost] docker network create -d overlay ng_net
使用swarm创建容器并将数据卷挂载到nfs服务器的/web目录下
[root@localhost]docker service create -d \
--name nfs-service \
--mount 'type=volume,source=nfsvolume,target=/usr/share/nginx/html,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/web,"volume-opt=o=addr=192.168.133.136,rw,nfsvers=4,async"' \
--replicas 5 \
-p 80:80 \
nginx:latest
3.配置前端的nginx负载均衡
1.下载nginx服务
2.修改/etc/nginx./nginx.conf 里面的配置(添加在server代码的上面)
upstream mydownload {
server 192.168.133.136 weight=1;
server 192.168.133.137 weight=1;
server 192.168.133.138 weight=1;
}