前文
& & NFS的概念可以参考该篇:https://blog.csdn.net/weixin_42681866/article/details/115342255;这里讲下快速搭建
& & 以服务端的/data目录,映射到客户端的/nfs_data目录为例,分别看下服务端(192.168.1.2)和客户端(192.168.1.10)的搭建
服务端搭建(centos为例)
& & 检查nfs服务
rpm -qa|grep nfs
rpm -qa|grep rpcbind
& & 安装NFS:
yum install -y nfs-utils rpcbind
& & 通过systemctl启动nfs:
# 启动rpc和nfs,并且设置为开机自动重启
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs-server
systemctl enable nfs-server
& & 防火墙放通nfs,如果关闭无影响的话,直接关闭也是ok:
# 配置放通
firewall-cmd --permanent --add-service=nfs #配置防火墙放行nfs服务
firewall-cmd --reload
# 或者直接关闭
systemctl stop firewalld;systemctl disable firewalld
& & 配置/etc/exports,这是服务与开机自动挂载:
vim /etc/exports
# 在最后一行加入:data标识挂载的目录,ip则是服务端允许的客户端访问的ip,多个ip用空格隔开
/data 192.168.1.10(rw,sync,no_subtree_check,no_root_squash)
& & 上面几个参数是最常用的,简单介绍下 ro/rw表示只读还是读写,sync/async前者表示同步写入到内存和磁盘,后者标识先写入到内存,然后异步写入磁盘,则有一定几率丢失数据;no_root_squash表示如果客户端是root权限,则访问服务端目录也是root权限
& & 配置完后重启nfs: systemctl reload nfs
客户端搭建(centos为例)
& & 安装NFS:
yum install -y nfs-utils rpcbind
& & 创建共享目录:
mkdir /nfs_data
& & 使用mount挂载目录:
mount 192.168.1.2:/data /nfs_data
& & 同服务端配置/etc/exports一致,客户端通过配置/etc/fstab实现开机自动挂载:
vim /etc/fstab
# 加入最后一行
192.168.1.2:/data /nfs_data nfs rw,vers=3,proto=tcp,hard 0,0
& & 执行mount -a就可以立刻生效
& & 执行df -Th,此时就能看到挂载的目录,则表示挂载成功