Centos7 安装配置NFS v4

1 搭建、配置NFS服务器

1.1 安装

[root@uat-w2 home]# yum -y install nfs-utils rpcbind
Loaded plugins: fastestmirror
······
Installed:
  nfs-utils.x86_64 1:1.3.0-0.68.el7                                             rpcbind.x86_64 0:0.2.0-49.el7                                            

Dependency Installed:
  gssproxy.x86_64 0:0.7.0-29.el7      keyutils.x86_64 0:1.5.8-3.el7           libbasicobjects.x86_64 0:0.1.1-32.el7  libcollection.x86_64 0:0.7.0-32.el7 
  libevent.x86_64 0:2.0.21-4.el7      libini_config.x86_64 0:1.3.1-32.el7     libnfsidmap.x86_64 0:0.25-19.el7       libpath_utils.x86_64 0:0.2.1-32.el7 
  libref_array.x86_64 0:0.1.5-32.el7  libverto-libevent.x86_64 0:0.2.5-4.el7  quota.x86_64 1:4.01-19.el7             quota-nls.noarch 1:4.01-19.el7      
  tcp_wrappers.x86_64 0:7.6-77.el7   

Complete!
[root@uat-w2 home]# 

1.2 启动服务并配置开机自动启动

[root@uat-w2 home]# systemctl start nfs && systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@uat-w2 home]# systemctl start rpcbind && systemctl enable rpcbind
[root@uat-w2 home]# 

1.3 创建并配置共享目录

创建文件夹/date/nfs并设置权限

[root@uat-w2 home]# mkdir -p /data/nfs
[root@uat-w2 home]# chmod -R 777 /data/nfs

1.4 配置/etc/exports

[root@uat-w2 home]# echo "/data/nfs   172.18.30.*(rw,sync,no_root_squash)" >> /etc/exports
[root@uat-w2 home]# cat /etc/exports
/data/nfs   172.18.30.*(rw,sync,no_root_squash)
[root@uat-w2 home]# 

或者配置为

[root@uat-w2 home]# echo "/data/nfs   172.18.30.0/24(rw,sync,no_root_squash)" >> /etc/exports

或者

[root@uat-w2 home]# echo "/data/nfs   *(rw,sync,no_root_squash)" >> /etc/exports

使配置生效

[root@uat-w2 home]# exportfs -r
[root@uat-w2 home]# 

参数配置说明

参数值内容说明
rw读写
ro只读,但最终能不能读写,还是与文件系统的 rwx 及身份有关
参数值内容说明
sync代表数据会同步写入到内存与硬盘中
async则代表数据会先暂存于内存当中,而非直接写入硬盘
参数值内容说明
root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户
no_root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
all_squash不论登入 NFS 的使用者身份为何, 均被映射为匿名用户,通常就是 nobody(nfsnobody)

1.5 检查共享目录是否设置成功

[root@uat-w2 home]# showmount -e
Export list for uat-w2:
/data/nfs 172.18.30.*
[root@uat-w2 home]# 

2 NFS客户端

2.1 安装客户端

[root@uat-w1 ~]# yum -y install nfs-utils
Loaded plugins: fastestmirror
······
Installed:
  nfs-utils.x86_64 1:1.3.0-0.68.el7                                                                                                                       

Dependency Installed:
  gssproxy.x86_64 0:0.7.0-29.el7      keyutils.x86_64 0:1.5.8-3.el7           libbasicobjects.x86_64 0:0.1.1-32.el7  libcollection.x86_64 0:0.7.0-32.el7 
  libevent.x86_64 0:2.0.21-4.el7      libini_config.x86_64 0:1.3.1-32.el7     libnfsidmap.x86_64 0:0.25-19.el7       libpath_utils.x86_64 0:0.2.1-32.el7 
  libref_array.x86_64 0:0.1.5-32.el7  libverto-libevent.x86_64 0:0.2.5-4.el7  quota.x86_64 1:4.01-19.el7             quota-nls.noarch 1:4.01-19.el7      
  rpcbind.x86_64 0:0.2.0-49.el7       tcp_wrappers.x86_64 0:7.6-77.el7       

Complete!
[root@uat-w1 ~]# 

2.2 检查共享目录是否设置成功

[root@uat-w1 ~]# showmount -e 172.18.30.x
Export list for 172.18.30.214:
/data/nfs 172.18.30.*
[root@uat-w1 ~]# 

2.3 挂载远程服务器NFS分区到本地挂载点

[root@uat-w1 ~]# mkdir -p /data/nfs-client
[root@uat-w1 ~]# mount -t nfs 172.18.30.x:/data/nfs /data/nfs-client
[root@uat-w1 ~]# 

在客户端目录创建文件

[root@uat-w1 ~]# echo "my nfs" >> /data/nfs-client/hello.txt
[root@uat-w1 ~]# 

在服务端查看文件

[root@uat-w2 home]# cd /data/nfs/
[root@uat-w2 nfs]# ll
total 4
-rw-r--r-- 1 root root 7 Dec 23 17:07 hello.txt
[root@uat-w2 nfs]# cat hello.txt 
my nfs
[root@uat-w2 nfs]# 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值