码迷,mamicode.com
首页 > 其他好文 > 详细

2018-3-26 14周1次课 NFS服务端安装、配置

时间:2018-03-25 21:46:38      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:NFS

14.1 NFS介绍


·NFS是Network File System的缩写

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

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

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

技术分享图片

(A/B/C三台主机数据一致,仅仅将A上数据拷贝到B/C上的话,B/C上数据无法实现和A的实时同步)

技术分享图片

rpcbind服务产生的RPC协议进行通信(rpcbind服务默认监听111端口),NFS服务会在RPC注册一个端口,并告知RPC,PRC通过和用户PRC数据传输,告诉用户主机端口号,用户主机通过端口号访问

NFS服务需要借助RPC协议实现通信。





14.2 NFS服务端安装配置


·服务端安装nfs-utils和rpcbind

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

(过程省略)


·客户端安装nfs-utils

(过程省略,其实只要安装了nfs-utils,就会自动装上rpcbind包)


·服务端上编辑 vim /etc/exports

写入/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

[root@localhost ~]# vim /etc/exports

技术分享图片


·创建/ home/nfstestdir 目录,更改777权限

[root@localhost ~]# mkdir /home/nfstestdir
[root@localhost ~]# chmod 777 /home/nfstestdir
[root@localhost ~]# netstat -lntp

技术分享图片

[root@localhost ~]# ps aux |grep rpc
root        395  0.0  0.0      0     0 ?        S<   22:29   0:00 [rpciod]
root       1200  0.0  0.0 112676   984 pts/0    R+   22:32   0:00 grep --color=auto rpc
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# ps aux |grep nfs

技术分享图片

[root@localhost ~]# ps aux |grep rpc

技术分享图片

(启动nfs服务的时候,会自动启动rpc相关服务)


·设置开机启动:

[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.





14.3 NFS配置选项


·服务端上NFS配置选项:

rw //读写

ro //只读

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

async //非同步模式

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

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

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

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


showmount -e 查看对某台做了nfs服务的机器,有没有权限

mount -t 指定类型



[root@localhost ~]# showmount -e 192.168.65.128
Export list for 192.168.65.128:
/home/nfstestdir 192.168.65.0/24

技术分享图片


·挂载:mount -t 类型 远程ip:共享目录 挂载点

[root@localhost ~]# mount -t nfs 192.168.65.128:/home/nfstestdir /mnt
root@localhost ~]# df -h
文件系统                         容量  已用  可用 已用% 挂载点
/dev/sda3                         18G  3.8G   15G   21% /
devtmpfs                         479M     0  479M    0% /dev
tmpfs                            489M     0  489M    0% /dev/shm
tmpfs                            489M  6.7M  482M    2% /run
tmpfs                            489M     0  489M    0% /sys/fs/cgroup
192.168.65.128:/home/nfstestdir   18G  3.8G   15G   21% /mnt
/dev/sda1                        197M   97M  100M   50% /boot
tmpfs                             98M     0   98M    0% /run/user/0
[root@localhost ~]# touch /mnt/20180320.txt
[root@localhost ~]# ll /mnt/20180320.txt
-rw-r--r-- 1 mysql mysql 0 3月  20 21:27 /mnt/20180320.txt


客户端上创建一个新文件20180320.txt,再去服务端共享目录查看

[root@localhost ~]# ll /home/nfstestdir/
总用量 0
-rw-r--r-- 1 mysql mysql 0 3月  20 21:27 20180320.txt
[root@localhost ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)

(在NFS配置选项设置了anonuid和anongid为1000,所以一旦挂载了nfs共享目录,无论客户端上用什么用户去创建文件,在服务端上都显示为uid为1000,gid为1000,也就是mysql)


2018-3-26 14周1次课 NFS服务端安装、配置

标签:NFS

原文地址:http://blog.51cto.com/11530642/2090961

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!