NFS搭建

离线环境,提前在有网络的服务器上下载好需要的软件包

yum -y install nfs-utils rpcbind --downloadonly --downloaddir /root/nfs

zip -r nfs.zip nfs/

registry.cn-beijing.aliyuncs.com/pylixm/nfs-subdir-external-provisioner:v4.0.0

#nfs 安装
unzip nfs.zip
cd nfs/

# 安装nfs
rpm -ivh *.rpm --force --nodeps 

# 创建共享文件夹
# 在主节点暴露一个nfs的目录
mkdir -p /data/nfs


# *表示目录下的所有文件,然后括号里的是可以让同步的目录也可以执行rw的操作
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" >> /etc/exports
echo "/data/project/ *(insecure,rw,sync,no_root_squash)" >> /etc/exports
echo "/data/k8s/ *(insecure,rw,sync,no_root_squash)" >> /etc/exports
echo "/data/paddleocr/ *(insecure,rw,sync,no_root_squash)" >> /etc/exports
systemctl enable rpcbind --now
systemctl enable nfs --now

# 使配置生效
exportfs -r

# 在从节点
# 安装nfs
rpm -ivh *.rpm --force --nodeps 

# 在从节点展示目标IP下可供同步的目录
showmount -e master
Export list for 192.76.116.110:
/data/nfs *

# 同样的,创建目录,然后将服务器上的目录共享到本机
mkdir -p /data/nfs
mount -t nfs 192.76.116.110:/data/nfs /data/nfs
mount -t nfs 10.0.2.130:/data/k8s /data/k8s
mount -t nfs master:/data/project /data/project

systemctl enable rpcbind --now
systemctl enable nfs --now

# 客户端查看挂载的状态
[root@k8s-node2 data]# mount | grep nfs
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
192.76.116.110:/nfs/data on /nfs/data type nfs4 

# 解释参数
192.76.116.110:/nfs/data # 表示服务器的目录
/nfs/data  # 代表在本机的目录
type nfs4  # 表示nfs的版本是4

你可能感兴趣的:(Linux,运维)