NFS介绍、NFS服务端安装配置、NFS配置选项介绍

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上的一致,NFS服务须要借助RPC服务去通讯。mysql

NFS介绍、NFS服务端安装配置、NFS配置选项介绍
NFS介绍、NFS服务端安装配置、NFS配置选项介绍

NFS服务端安装配置

1.安装应用包

服务端linux

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

客户端sql

[root@gary-tao ~]# yum install -y nfs-utils
2.修改配置文件
[root@gary-tao ~]# vim /etc/exports

增长以下配置内容:

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

//注解:

第一部分是本地要共享出去的目录。
第二部分是容许访问的主机(能够是一个IP,也能够是一个IP段)
第三部分就是小括号里面的一些权限选项。
3.建立目录及更改权限
[root@gary-tao ~]# mkdir /home/nfstestdir
[root@gary-tao ~]# chmod 777 /home/nfstestdir/
4.启动NFS服务
[root@gary-tao ~]# systemctl start nfs  //启动nfs服务
[root@gary-tao ~]# ps aux |grep nfs
root      13990  0.0  0.0      0     0 ?        S<   21:40   0:00 [nfsd4_callbacks]
root      13996  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13997  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13998  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      13999  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14000  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14001  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14002  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14003  0.0  0.0      0     0 ?        S    21:40   0:00 [nfsd]
root      14007  0.0  0.0 112684   976 pts/1    S+   21:40   0:00 grep --color=auto nfs
[root@gary-tao ~]# ps aux |grep rpc
rpc       13799  0.0  0.1  64964  1412 ?        Ss   21:25   0:00 /sbin/rpcbind -w
rpcuser   13963  0.0  0.1  42380  1748 ?        Ss   21:40   0:00 /usr/sbin/rpc.statd
root      13964  0.0  0.0      0     0 ?        S<   21:40   0:00 [rpciod]
root      13969  0.0  0.0  42564   944 ?        Ss   21:40   0:00 /usr/sbin/rpc.mountd
root      13980  0.0  0.0  21404   536 ?        Ss   21:40   0:00 /usr/sbin/rpc.idmapd
root      14009  0.0  0.0 112680   976 pts/1    R+   21:41   0:00 grep --color=auto rpc
[root@gary-tao ~]# systemctl enable nfs  //设置nfs开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@gary-tao ~]# systemctl start rpcbind   //启动rpc服务
[root@gary-tao ~]# systemctl enable rpcbind  //设置rpc开机启动

NFS配置选项

  • rw 读写;
  • ro 只读;
  • sync 同步模式,内存数据实时写入磁盘;
  • async 非同步模式,表示把内存中的数据按期写入磁盘;
  • no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大
  • root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户
  • all_squash 客户端上全部用户在使用NFS共享目录时都被限定为一个普通用户
  • anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid

客户端挂载NFS

[root@gary ~]# showmount -e 172.16.111.100  //查看NFS的共享状况 
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

//以上报错缘由是由防火墙致使,按下面方法关闭服务端与客户端的防火墙

[root@gary ~]# systemctl stop firewalld //关闭防火墙
[root@gary ~]# getenforce     //关闭seLinux
Enforcing
[root@gary ~]# setenforce 0
[root@gary ~]# showmount -e 172.16.111.100
Export list for 172.16.111.100:
/home/nfstestdir 172.16.111.0/24
[root@gary ~]# mount -t nfs 172.16.111.100:/home/nfstestdir /mnt/   //挂载服务端nfs
[root@gary ~]# df -h  //查看磁盘挂载
文件系统                         容量  已用  可用 已用% 挂载点
/dev/sda3                         18G  1.1G   17G    7% /
devtmpfs                         479M     0  479M    0% /dev
tmpfs                            489M     0  489M    0% /dev/shm
tmpfs                            489M   19M  470M    4% /run
tmpfs                            489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                        197M  109M   88M   56% /boot
tmpfs                             98M     0   98M    0% /run/user/0
172.16.111.100:/home/nfstestdir   18G  6.9G   11G   39% /mnt

客户端创建文件测试:vim

[root@gary ~]# cd /mnt/
[root@gary mnt]# ls
[root@gary mnt]# touch aminglinux.111
[root@gary mnt]# ls -l
总用量 0
-rw-r--r--. 1 xietao xietao 0 1月  16 14:19 aminglinux.111
[root@gary mnt]# id xietao
uid=1000(xietao) gid=1000(xietao) 组=1000(xietao)

服务端查询创建文件是否同步:app

[root@gary-tao ~]# ls -l /home/nfstestdir/
总用量 0
-rw-r--r-- 1 mysql mysql 0 1月  16 14:19 aminglinux.111
[root@gary-tao ~]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
说明:在客户端创建文件时会发现文件用户属主与属组是xietao,并且在服务端查询文件时用户倒是mysql,这是由于nfs限定了用户,因此最终显示成这样。
相关文章
相关标签/搜索