Server:
yum install -y nfs-utils
Create a directory: mkdir /nfs
Configuration: cat /etc/exports
/nfs *(rw,sync,no_root_squash)
Parameter Description:
rw read-write
ro read-only
sync data is written directly to disk
async data is written to memory first
no_root_squash does not suppress the root user, it is mapped to the server root user
root_squash if the client is the user root operation, it will be suppressed to the nobody user
all_squash Regardless of the client's user who uses nfs, it will be suppressed to the nobody user
nonuid=uid: the value of the specified uid
anongid=gid: the value of the specified gid
exportfs -rv # Take effect immediately
Start the service:
systemctl enable --now nfs-server.service
showmount -e
Client:
yum install -y nfs-utils
Create a mount directory: /mnt
View server: showmount -e nfs-server-ip
Mount: mount -t nfs nfs-server-ip:/nfs /mnt
Auto mount:
1. Install autofs
# yum install autofs
2. Create a mount directory
# mkdir /var/nfs
3. Automatically mount NFS configuration
# echo "/mnt /etc/auto.nfs" >> /etc/auto.master
# echo "data -fstype=nfs nfs-server-ip:/nfs" >> /etc/auto.nfs
4. Start the autofs service
# systemctl enable --now autofs.service
Firewall settings: (this part is more important, many posts on the Internet do not explain this place clearly)
systemctl start rpcbind (if this service does not start, the nfs service will fail to start)
systemctl start nfs-server
systemctl enable rpcbind;systemctl enable nfs-server 开机自启
firewall-cmd --permanent --add-service=nfs Let the firewall pass the NFS service
firewall-cmd --permanent --add-service=rpc-bind through the rpc service (if it is not turned on, rpcinfo cannot scan)
firewall-cmd --permanent --add-service=mountd through mountd service (if it is not enabled, remote showmount is not possible)
firewall-cmd --reload