基于NFS的分布式持久化

基于容器的微服务架构中,分布式持久化方案并没有一个默认的最好方案,这里使用NFS来作为容器持久化方案。

NFS服务需要在服务器及需要挂载的客户端上分别安装配置。


nfs-utils包含服务:

rpcbind : The rpcbind server converts RPC program numbers into universal addresses.

nfs-server :  It enables the clients to access NFS shares.

nfs-lock / rpc-statd : NFS file locking. Implement file lock recovery when an NFS server crashes and reboots.

nfs-idmap : It translates user and group ids into names, and to translate user and group names
into ids

 

nfs相关配置文件:

/etc/exports : It is a main configuration file, controls which file systems are exported to remote hosts and specifies options.

/etc/fstab : This file is used to control what file systems including NFS directories are mounted when the system boots.

/etc/sysconfig/nfs : This file is used to control which ports the required RPC services run on.

/etc/hosts.allow, and /etc/hosts.deny : These files are called TCP wrappers, controls the access to NFS server. It is used by NFS to decide whether or not to accept a connection coming in from another IP address


 

 

NFS服务器安装:

Step1:安装及启动

1 yum install nfs-utils libnfsidmap
2 systemctl enable rpcbind
3 systemctl enable nfs-server
4 systemctl start rpcbind
5 systemctl start nfs-server
6 systemctl start rpc-statd
7 systemctl start nfs-idmapd

 

Step2:创建共享路径,并开放访问

1 mkdir /data1/share
2 chmod 777 /data1/share
3 echo '/data1/share 10.200.xx.xx/24(rw,sync,no_root_squash)' >>/etc/exports

其中,IP地址参数指定了需要挂载的client的IP,用掩码模式则指定IP段;

rw表示挂载路径允许读写权限;

sync表示同步模式,默认情况下是异步模式,由于是共享路径所以采用同步模式;

no_root_squash表示客户端能够以root权限操作挂载点文件系统。

 

Step3:更新挂载文件信息

exportfs -r

exportfs指令的各个参数说明如下:

exportfs -v : Displays a list of shares files and export options on a server
exportfs -a : Exports all directories listed in /etc/exports
exportfs -u : Unexport one or more directories
exportfs -r : Reexport all directories after modifying /etc/exports

 

Step4:配置服务器防火墙

firewall-cmd --permanent --zone public --add-service mountd
firewall-cmd --permanent --zone public --add-service rpc-bind
firewall-cmd --permanent --zone public --add-service nfs
firewall-cmd --reload

 


 

NFS客户端安装:

Step1:安装及启动

yum -y install nfs-utils libnfsidmap
systemctl enable rpcbind
systemctl start rpcbind

 

Step2:确认NFS服务器挂载信息

showmount -e 10.200.xx.xx

如果返回信息如下:

Export list for 10.200.xx.xx:
/data1/share 10.200.xx.xx/24

其中,IP段包含了该客户端的IP地址,则该客户端可以挂载到远程NFS服务器。

 

Step3:创建挂载URL并挂载NFS服务器

1 mkdir /mnt/share
2 mount 10.200.xx.xx:/data1/share /mnt/share

挂载后,通过以下指令查看挂载信息:

mount | grep nfs

正常情况下能够看到挂载到的NFS服务器的挂载信息,也可以通过

df -hT

来查看挂载信息,类型为nfs4的挂载即是到NFS服务器的挂载点。

 


 

 

客户端挂载信息的持久化:

默认情况下,客户端的挂载信息将在服务器reboot后丢失,需要重新挂载。与硬盘挂载相同,可以通过在/etc/fstab中添加NFS挂载信息来持久化挂载:

echo '10.200.xx.xx:/data1/share/ /mnt/share nfs rw,sync,hard,intr 0 0' >>/etc/fstab

而解除挂载,可以直接在NFS客户端使用unmount进行:

unmount /mnt/share

 


 

转载于:https://www.cnblogs.com/you-you-111/p/5803734.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kubernetes (K8s) 支持使用 NFS(Network File System)作为持久化存储解决方案。NFS 是一种分布式文件系统协议,允许将远程文件系统挂载到本地服务器上。 要使用 NFS 进行持久化存储,你需要先设置一个 NFS 服务器,并在 Kubernetes 集群中配置一个 NFS 持久卷。以下是一些步骤: 1. 配置 NFS 服务器:你需要设置一个 NFS 服务器并将其配置为共享文件系统。确保你已经安装并配置好了 NFS 服务器软件。 2. 创建 NFS 持久卷:在 Kubernetes 中,你可以使用 PersistentVolume(PV)和 PersistentVolumeClaim(PVC)对象来定义持久卷和持久卷声明。创建一个 PV 来表示 NFS 服务器上的共享目录,并为该 PV 创建一个 PVC。 3. 部署应用程序:使用创建的 PVC,在你的应用程序中声明一个持久卷。你可以通过将 PVC 挂载到应用程序的 Pod 中来实现持久化存储。 以下是一个示例的 YAML 文件,演示了如何在 Kubernetes 中配置一个 NFS 持久卷: ``` apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv spec: capacity: storage: 5Gi accessModes: - ReadWriteMany nfs: server: <NFS_SERVER_IP> path: /path/to/shared/directory --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nfs-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi storageClassName: "" selector: matchLabels: name: nfs-pv ``` 替换 `<NFS_SERVER_IP>` 和 `/path/to/shared/directory` 为你 NFS 服务器的 IP 地址和共享目录的路径。然后,使用 kubectl apply 命令来部署这个 YAML 文件。 一旦 PVC 和 PV 创建成功,你可以在你的应用程序中使用该 PVC 来挂载 NFS 持久卷,并在 Pod 中进行持久化存储。 这就是使用 NFS 进行持久化存储的基本步骤。希望对你有所帮助!如果还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值