Docker Swarm集群 使用NFS共享儲存

2021-10-09 15:27:34 字數 4011 閱讀 6797

系統環境為centos,一共有7臺機子組成了docker swarm集群,每台機子都要安裝nfs

ipdocker角色

nfs角色

111.111.3.41

manager

server

111.111.3.42

manager

client

111.111.3.43

manager

client

111.111.3.44

worker

client

111.111.3.45

manager

client

111.111.3.46

manager

client

111.111.3.47

worker

client

yum -y install nfs-utils
使用111.111.3.41為nfs的服務端

先在/root目錄下建立share資料夾,並賦予chmod 755許可權

配置共享目錄

nano /etc/exports

/root/share 111.111.3.0/24(rw,async,insecure,anonuid=1000,anongid=1000,no_root_squash)

生效配置

exportfs -rv
systemctl enable rpcbind

systemctl start rpcbind

systemctl enable nfs-server

systemctl start nfs-server

檢視nfs服務狀態

[root@kd111111003041 ~]#  rpcinfo -p

program vers proto port service

100024 1 udp 45889 status

100024 1 tcp 42518 status

100005 1 udp 20048 mountd

100005 1 tcp 20048 mountd

100005 2 udp 20048 mountd

100005 2 tcp 20048 mountd

100005 3 udp 20048 mountd

100005 3 tcp 20048 mountd

100003 3 tcp 2049 nfs

100003 4 tcp 2049 nfs

100227 3 tcp 2049 nfs_acl

100003 3 udp 2049 nfs

100003 4 udp 2049 nfs

100227 3 udp 2049 nfs_acl

100021 1 udp 37813 nlockmgr

100021 3 udp 37813 nlockmgr

100021 4 udp 37813 nlockmgr

100021 1 tcp 40301 nlockmgr

100021 3 tcp 40301 nlockmgr

100021 4 tcp 40301 nlockmgr

[root@kd111111003041 ~]# cat /var/lib/nfs/etab

/root/share 111.111.3.0/24(rw,async,wdelay,hide,nocrossmnt,insecure,no_root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=1000,anongid=1000,sec=sys,rw,insecure,no_root_squash,no_all_squash)

每個docker節點都要手動建立相同名稱的docker volume

docker volume create --driver local \

--opt type=nfs \

--opt o=addr=111.111.3.41,rw \

--opt device=:/root/share \

foo33

檢視volume

[root@kd111111003041 ~]# docker volume ls

driver volume name

local foo33

local portainer_data

檢視foo33的詳細

[root@kd111111003041 ~]# docker volume inspect foo33

[ ,

"mountpoint": "/var/lib/docker/volumes/foo33/_data",

"name": "foo33",

"options": ,

"scope": "local"

}]

在manager節點下建立服務

docker service create \

--name test-nginx-nfs \

--publish 84:80 \

--replicas 3 \

nginx

version: '3.8'

services:

nginx-test5:

image: nginx:latest

deploy:

mode: replicated

replicas: 3

restart_policy:

condition: on-failure

ports:

- "88:80"

networks:

my-overlay-network:

aliases:

- nginx-test5

volumes:

volumes:

foo_new:

driver: local

driver_opts:

type: "nfs"

o: "addr=111.111.3.41,rw"

device: ":/root/share"

networks:

my-overlay-network:

driver: overlay

使用docker stack編排方式,無需手動建立docker volume

將編寫好的docker-compose.yml上傳到是manager的機子上的任意目錄下,然後在控制台轉到對應的目錄下輸入命令

[root@kd111111003041 ~]# docker stack ls

name services orchestrator

id name mode replicas image ports

id name image node desired state current state error ports

[root@kd111111003041 ~]#

docker swarm集群部署應用

參考 使用docker machine搭建docker swarm集群並部署nginx服務 docker machine ssh swarmmng docker service create replicas 3 name web nginx p 80 80 nginx 或者先登入管理節點機器,然後...

Docker Swarm的集群化實踐以及感想

接觸docker也有幾年,分為幾個階段 1 最早只會run,stop,start,打好war包丟容器內去跑,把容器當成虛擬機器使用。2 把jar包直接打成映象,服務隨映象啟動而生。3 使用gitlab jenkins和docker集群 以及阿里雲容器映象服務,jenkins持續構建,用指令碼打成映象...

docker swarm安裝與使用

1.swarm簡介 2.swarm使用命令 拉取映象 docker pull swarm 初始化docker swarm docker swarm init advertise addr 192.168.202.106 初始化時,會出現加入從節點的命令,不過如果沒有記下來,可以呼叫如下命令 dock...