四台服务器
客户端a:192.168.1.111
客户端b:192.168.1.112
客户端c:192.168.1.113
服务端:192.168.2.230
服务端
下载nfs和rpcbind
yum install -y nfs-utils
#现在的rpcbind会作为nfs的依赖一同被下载。如果nfs安装报告没有提示rpcbind已作为依赖被下载需要单独安装rpcbind 安装指令: yum install -y rpcbind
#启动rpcbind服务和nfs服务 ps:先启动rpc再启动nfs
PS: 出现rpcbind启动失败确认防火墙、seLinux是否关闭
systemctl start rpcbindsystemctl enable rpcbind #开机自启systemctl start nfssystemctl enable nfs #开机自启#查看服务状态systemctl status rpcbindsystemctl status nfs
创建共享路径文件夹
mkdir /sharedirchomd 777 /sharedir #权限设置
编辑nfs的配置文件
vi /etc/exprots/sharedir 192.168.1.*(rw,sync,root_squash) #ip和后面的括号不能有空格 .* 192.168.1的全部号段# 第一段来定义共享目录的绝对路径 第二段指定ip和一些选项# rw 读写# ro 只读# sync 同步模式,内存数据实时写入磁盘# async 非同步模式# no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大# root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户# all_squash 客户端上所有用户在使用NFS共享目录时都被限定为一个普通用户# anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid
重启nfs
systemctl restart nfs# 确认showmount -e localhostExport list for localhost:/sharedir 192.168.1.*
客户端
客户端a
# 下载nfs和rpcbind 同服务端yum install -y nfs-utils# 启动rpcbind 客户端不用启动nfs服务systemctl start rpcbindsystemctl enable rpcbind #开机自启# 查询共享的目录 (服务端ip)showmount -e 192.168.2.230Export list for 192.168.2.230:/sharedir 192.168.1.*# 挂载本地文件夹mnt到共享目录 mnt不用单独创建mount -t nfs 192.168.2.230:/sharedir /mnt# 此时mnt与共享目录同步,在mnt中创建文件夹或文件再去服务端确认是否成功
永久挂载
以上操作完成之后就可以共享硬盘了,但是客户端重启之后就会失效,需要修改 /etc/fstab 实现永久挂载
vi /etc/fstab
添加下面的内容
# 服务端目录 本地挂载点 方式 选项 dump fsckorder192.168.2.230:/sharedir /mnt nfs defaults 0 0
MAC客户端挂载
在nfs服务端添加名单
vi /etc/exports/sharedir 10.16.118.*(rw,sync,root_squash)# mac 客户端 ip insecure:允许从大于1024的tcp/ip端口连接服务器/sharedir 10.16.101.17(rw,sync,root_squash,insecure)
重启nfs服务
mac客户端
sudo mount -o resvport 192.168.2.230:/sharedir /User/mac/mnt
