Centos7 安装配置NFS v4
Centos7 安装配置NFS v4
- 1 搭建、配置NFS服务器
- 1.1 安装
- 1.2 启动服务并配置开机自动启动
- 1.3 创建并配置共享目录
- 1.4 配置/etc/exports
- 1.5 检查共享目录是否设置成功
- 2 NFS客户端
- 2.1 安装客户端
- 2.2 检查共享目录是否设置成功
- 2.3 挂载远程服务器NFS分区到本地挂载点
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]#
还没有评论,来说两句吧...