NFS Introduction
NFS is the abbreviation for the network file system, which is the web filesystem;
The transmission is based on RPC protocol;
Server-side Installation
yum install -y nfs-utils rpcbind //安装rpcbind包与nfs-utils包vim /etc/exports //设置配置文件代码/home/nfstestdir 192.168.188.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)mkdir /home/nfstestdir //创建共享文件夹chmod 777 /home/nfstestdir/ //赋予共享文件夹777权限systemctl start rpcbind //启动rpcbind服务systemctl start nfs //启动nfs服务systemctl enable rpcbind //设置开机启动rpc服务systemctl enable nfs //设置开机启动nfs服务
Client Installation
yum install -y nfs-utils showmount -e 192.168.188.2 //检查服务端192.168.188.2的共享目录是否正常mount -t nfs 192.168.188.2:/home/nfstestdir /mnt //挂载nfs服务器的共享目录到客户端的/mnt下df -h //查看是否挂载成功cd /mnt/ //进入mnt目录(也就是共享目录)touch nfs.test //创建nfs.test文件登录服务端ls发现/home/nfstestdir 下被同步了nfs.test文件出来;如果检测服务端共享目录不通,可使用下列目录临时关闭防火墙与selinux(服务端和客户端都要关闭)systemctl stop firewalldsetenforce 0
NFS Mount Options
Cat/etc/exports
RW: Read and Write
RO: Read-only
Sync: Synchronous mode, memory data write in real time;
Async: Non-synchronous mode;
No_root_squash: After the client Mounts the NFS shared directory, the root user is not constrained and the permissions are large;
Root_squash: As opposed to the above option, the client root is first established as a normal user;
All_squash: All users on the client are restricted to an ordinary user when they use the NFS shared directory;
Anonuid/anongid: Use with the above several options, define the UID and GID of the qualified user;
Exportfs command
When the NFS server has a new configuration, it does not need to restart the NFS service to affect the client, and the EXPORTFS command allows the configuration to take effect;
-A: Mount all or uninstall all
-R: Reload
-U: Uninstalling a directory
-V: Show shared directory
vim /etc/exports增加/tmp/ 192.168.188.0/24(rw,sync,no_root_squash)exportfs -arv //不用重启nfs服务,配置文件直接生效
NFS file system, server and client installation, Exportfs command