【Centos7笔记十】NFS的安装使用

xiaoxiao2021-02-28  53

NFS网络文件系统的使用: 场景:如果恰巧需要共享文件的主机都是Linux系统,则可以使用NFS文件系统来共享 1.[root@linuxprobe ~]# yum install nfs-utils //安装必要组件 2.在NFS服务端主机上面建立用于NFS文件共享的目录,设置较大的权限来保证其他人也一样有写入的权限: [root@linuxprobe ~]# mkdir /nfsfile [root@linuxprobe ~]# chmod -Rf 777 /nfsfile [root@linuxprobe ~]# echo "welcome to linuxprobe.com" > /nfsfile/readme 3.配置NFS: NFS服务程序的配置文件为/etc/exports,默认里面是空白没有内容的,可以按照 共享目录的路径 允许访问的NFS资源客户端(共享权限参数) 的格式来写入参数,定义要共享的目录与相应的权限。例如想要把/nfsfile目录共享给所有属于192.168.10.0/24这个网段的用户主机, 并且让这些用户拥有读写权限,自动同步内存数据到本地硬盘,以及把对方root超级用户映射为本地的匿名用户等等特殊权限参数, 那么就可以按照下面的格式来写入配置文件: [root@linuxprobe ~]# vim /etc/exports /nfsfile 192.168.10.*(rw,sync,root_squash) //共享目录的路径 允许访问的NFS资源客户端(共享权限参数) 其中共享权限参数及作用如下: 参数 作用 ro 只读默认 rw 读写模式 root_squash 当NFS客户端使用root用户访问时,映射为NFS服务端的匿名用户。 no_root_squash 当NFS客户端使用root用户访问时,映射为NFS服务端的root用户。 all_squash 不论NFS客户端使用任何帐户,均映射为NFS服务端的匿名用户。 sync 同时将数据写入到内存与硬盘中,保证不丢失数据。 async 优先将数据保存到内存,然后再写入硬盘,效率更高,但可能造成数据丢失。 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-server ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service' 5.配置NFS客户端: 首先用showmount命令查询NFS服务端的远程共享信息,输出格式为“共享的目录名称 允许使用客户端地址”: [root@linuxprobe ~]# showmount -e 192.168.10.10 Export list for 192.168.10.10: /nfsfile 192.168.10.* showmount命令常用的参数如下: 参数 作用 -e 显示NFS服务端的共享列表 -a 显示本机挂载NFS资源的情况 -v 显示版本号 然后在客户端系统上面创建一个挂载目录,使用mount命令的-t参数指定挂载文件系统的类型,以及后面写上服务端的IP地址,共享出去的目录以及挂载到系统本地的目录。 [root@linuxprobe ~]# mkdir /nfsfile [root@linuxprobe ~]# mount -t nfs 192.168.10.10:/nfsdirectory /nfsdirectory 如果希望远程NFS文件共享能一直有效,还可以写入到fstab文件中: [root@linuxprobe ~]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 4 19:26:23 2017 # # 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 1 UUID=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 0 192.168.10.10:/nfsdirectory /nfsdirectory nfs defaults 0 0
转载请注明原文地址: https://www.6miu.com/read-80206.html

最新回复(0)