NFS网络文件系统
1、为了检验NFS服务配置的效果,咱们本次实验需要使用到两台Linux主机,您可以参考下表对系统网卡IP地址进行设置,另外也不要忘记清空iptables防火墙,避免默认的策略禁止了咱们正常的NFS共享服务:主机名称 操作系统 IP地址NFS服务端 红帽RHEL7操作系统 192.168.10.10NFS客户端 红帽RHEL7操作系统 192.168.10.20[root@linuxprobe ~]# iptables -F[root@linuxprobe ~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
2、在NFS服务端主机上面建立用于NFS文件共享的目录,设置较大的权限来保证其他人也一样有写入的权限:[root@linuxprobe ~]# mkdir /nfsfile[root@linuxprobe ~]# chmod -Rf 777 /nfsfile[root@linuxprobe ~]# echo "welcome to linuxprobe.com" > /nfsfile/readme
3、第3步:NFS服务程序的配置文件为/etc/exports,默认里面是空白没有内容的,可以按照共享目录的路径 允许访问的NFS资源客户端(共享权限参数)的格式来写入参数,定义要共享的目录与相应的权限,例如咱们想要把/nfsfile目录共享给所有属于192.168.10.0/24这个网段的用户主机,并且让这些用户拥有读写权限,自动同步内存数据到本地硬盘,以及将对方root超级用户映射为本地的匿名用户等等特殊权限参数,那么就可以按照下面的格式来写入配置文件:[root@linuxprobe ~]# vim /etc/exports/nfsfile 192.168.10.*(rw,sync,root_squash)
4、启动运行NFS共享服务程序,由于NFS服务在文件共享过程中是依赖RPC服务进行工作了,RPC服务用于将服务器地址和服务端口号等信息通知给客户端,因此咱们要使用NFS共享服务的话,盒作柩锟顺手也要把rpcbind服务程序启动,并且将这两个服务一起加入到开机启动项中吧:[root@linuxprobe ~]# systemctl restart rpcbind[root@linuxprobe ~]# systemctl enable rpcbind[root@linuxprobe ~]# systemctl start nfs-server[root@linuxprobe ~]# systemctl enable nfs-serverln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'配置NFS客户端的步骤也十分简单,首先用showmount命令查询NFS服务端的远程共享信息,输出格式为“共享的目录名称 允许使用客户端地址”:[root@linuxprobe ~]# showmount -e 192.168.10.10Export list for 192.168.10.10:/nfsfile 192.168.10.*然后在客户端系统上面创建一个挂载目录,使用mount命令的-t参数指定挂载文件系统的类型,以及后面写上服务端的IP地址,共享出去的目录以及挂载到咱们系统本地的目录。[root@linuxprobe ~]# mkdir /nfsfile[root@linuxprobe ~]# mount -t nfs 192.168.10.10:/nfsfile /nfsfile最后挂载成功后就应该能够顺利查看到刚刚写入文件内容了,当然如果同学们希望远程NFS文件共享能一直有效,还可以写入到fstab文件中:[root@linuxprobe ~]# cat /nfsfile/readmewelcome to linuxprobe.com[root@linuxprobe ~]# vim/etc/fstab## /etc/fstab# Created by anaconda on Wed May 4 19:26:23 2016## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/rhel-root / xfs defaults 1 1UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2/dev/mapper/rhel-swap swap swap defaults 0 0/dev/cdrom /media/cdrom iso9660 defaults 0 0192.168.10.10:/nfsfile /nfsfile nfs defaults 0 0