14.1 NFS介绍 14.2 NFS服务端安装配置 14.3 NFS配置选项

14.1 NFS介绍

1. NFS是Network File System的缩写

2. NFS最早由Sun公司开发,分2,3,4三个版本,2和3由Sun起草开发,4.0开始Netapp公司参与并主导开发,最新为4.1版本

3. NFS数据传输基于RPC协议,RPC为Remote Procedure Call的简写。

4. NFS应用场景是:A,B,C三台机器上需要保证被访问到的文件是一样的,A共享数据出来,B和C分别去挂载A共享的数据目录,从而B和C访问到的数据和A上的一致

wKioL1mdODaCRxDKAACY6CeoO4o883.png

NFS原理图:

wKioL1mdOFPR0Mw-AAJ3tf-MR0M464.pngspacer.gif14.2 NFS服务端安装配置

准备两个centos 7版本服务器:hao1服务端 hao2客户端

1. hao1服务端上安装:

[root@hao-01 ~]# yum install -y nfs-utils rpcbind

2. 编辑并添加内容:

[root@hao-01 ~]# vim /etc/exports

添加内容:

[ 共享目录 ip段.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) ]

/home/nfstestdir 192.168.211.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

3. 创建共享目录:

[root@hao-01 ~]# mkdir /home/nfstestdir

4. 共享目录设置777权限:

[root@hao-01 ~]# chmod 777 /home/nfstestdir

5. 启动rpcbind服务:

[root@hao-01 ~]# systemctl start rpcbind

6. 搜索rpcbind是否启动?

[root@hao-01 ~]# ps aux |grep rpcbind

wKioL1mdOI2iX8-pAAAaHDq-dhs914.png7. 查看rpcbind监听端口(显示systemd也是正常的):

[root@hao-01 ~]# netstat -lnpt

wKiom1mdOSuACpJLAAAjpqER6m4945.png8. 启动nfs:

[root@hao-01 ~]# systemctl start nfs

9. 搜索nfs是否启动?

[root@hao-01 ~]# ps aux |grep nfs

wKioL1mdOT7DAy7gAABIFXo_Jao815.png10. 设置nfs开机启动:

[root@hao-01 ~]# systemctl enable nfs

wKioL1mdOXqirm2MAAAVx34KsW0713.png14.3 NFS配置选项

NFS配置选项:

rw 读写

ro 只读

sync 同步模式,内存数据实时写入磁盘

async 非同步模式

no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大

root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户

all_squash 客户端上所有用户在使用NFS共享目录时都被限定为一个普通用户

anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid

 

1. hao2客户端上安装:

[root@hao-02 ~]# yum install -y nfs-utils rpcbind

2. 关闭hao1服务端防火墙:

[root@hao-01 ~]# systemctl stop firewalld

[root@hao-01 ~]# getenforce

[root@hao-01 ~]# setenforce 0

3. 关闭hao2客户端防火墙:

[root@hao-02 ~]# systemctl stop firewalld

[root@hao-02 ~]# getenforce

[root@hao-02 ~]# setenforce 0

4. 访问hao1服务端的ip,查看服务端共享目录和ip段:

[root@hao-02 ~]# showmount -e 192.168.211.128

wKioL1mdOZiz98pbAAAR6YopE_I671.png

5. hao2客户端 nfs挂载:

mount -t nfs 服务端ip:共享目录 挂载点

mount -t nfs 192.168.211.128:/home/nfstestdir /mnt

6. 查看挂载:

[root@hao-02 ~]# df -h

wKiom1mdOu7QJm0JAAA5XVQqx_8685.png

spacer.gif7. 挂载点mnt下,创建一个文件:

[root@hao-02 ~]# touch /mnt/hao.txt

8. hao2客户端查看挂载点下hao.txt文件 属主 属组:

[root@hao-02 ~]# ls -l /mnt/hao.txt

wKioL1mdOyrgtsBPAAANX9oTqvE836.png

spacer.gif9. hao2客户端查看mysql的id:

[root@hao-02 ~]# id mysql

wKiom1mdO1bAHT32AAAJvNRJYsA027.png

spacer.gif10. hao1服务端查看共享目录下的hao.txt文件 属主 属组:

[root@hao-01 ~]# ls -l /home/nfstestdir/hao.txt

wKioL1mdO4aiKz15AAAQYZoNjUo067.png

spacer.gif11. hao1服务端查看mysql的id:

[root@hao-01 ~]# id mysql

wKiom1mdO7XCWiHPAAAJdmDb018802.png

12. 因为/etc/exports里设置了anonuid=1000,anongid=1000

所以属主属组就显示的机器对应的1000id的用户。

 

posted on 2018-06-21 22:32  淡淡!!!  阅读(156)  评论(0编辑  收藏  举报

导航