NFS shared storage service
One, NFS overview
- NFS is a network file system protocol based on TCP/IP transmission. By using the NFS protocol, the client can access the shared resources in the remote server as if it were accessing a local directory.
- For most load balancing clusters, it is a common practice to use the NFS protocol to share data storage. NFS is also a protocol that NAS storage devices must support. But because NFS does not have a user authentication mechanism, and the data is transmitted in plain text on the network, soPoor security,generalCan only be used in LAN。
- The realization of the NFS service relies on the RPC (Remote Process Call) mechanism to complete the remote to local mapping process. Therefore, it is necessary to install the nfs-utils and rpcbind software packages to provide NFS sharing services. The former is used for NFS sharing publishing and access, and the latter is used for RPC support.
Two, NFS configuration file
The NFS configuration file is /etc/exports (server configuration). The
format is:
shared directory location client address (permission option)
3. The actual operation process
3.1 Use NFS to publish shared resources on the file server
3.1.1 Install the software package
rpm -q rpcbind nfs-utils #查询软件包是否已安装
yum install -y nfs-utils rpcbind #安装软件包
3.1.2 Set shared directory
3.1.3 Modify the configuration file
客户机地址可以是主机名、IP 地址、网段地址,允许使用“*”、 “?”通配符。
rw 表示允许读写。
ro 表示为只读。
sync 表示同步写入到内存与硬盘中。
no_root_squash 表示当客户机以root身份访问时赋予本地root权限(默认是root_squash)。
root_squash 表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户。
其它常用选项:
all_squash 所有访问用户都映射为匿名用户或用户组。
async 将数据先保存在内存缓冲区中,必要时才写入磁盘。
subtree_check(默认) 若输出目录是一个子目录,则nfs服务器将检查其父目录的权限。
no_subtree_check 即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率。
3.1.4 Start NFS service
When manually loading the NFS sharing service, you should start rpcbind first, and then start nfs
systemctl stop firewalld
setenforce 0
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
3.1.5 View the NFS shared directory published by this machine
exportfs -rv #发布共享
showmount -e
3.2 Access NFS shared resources in the client
3.2.1 Install nfs-utils and rpcbind software packages
rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind
3.2.2 View which directories are shared on the NFS server
3.2.3 Manually mount the NFS shared directory
3.2.4 Test
Create a new file in the client
and then go to the server /opt/share directory to check whether it is synchronized
3.2.5 Automatically mount NFS shared directories
vim /etc/fstab
92.168.153.10:/opt/share /share nfs defaults,_netdev 0 0
3.2.6 Forcibly uninstalling NFS
If the server-side NFS service suddenly stops while the client is being mounted and used, the client will be stuck when executing the df -h command. At this time, you cannot uninstall directly by using the umount command directly. You need to add the -lf option to uninstall.
umount -lf /share