Introduction to NFS
NFS is short for Network File System
NFS was first developed by Sun, and divided into 2, 3, and 4 versions. 2 and 3 were drafted and developed by Sun. Netapp participated in and led the development since 4.0, and the latest version is 4.1.
NFS data transmission is based on the RPC protocol. RPC is short for Remote Procedure Call.
The NFS application scenario is: the three machines A, B, and C need to ensure that the files to be accessed are the same, A shares data, B and C mount the data directory shared by A respectively, so that B and C can access The data is consistent with that on A
NFS Architecture
NFS schematic
NFS server installation configuration
(The server configures NFS, and the client mounts NFS)
ifconfig
Server: yum install -y nfs-utils rpcbind
vim /etc/exports //Add the following
/home/nfstestdir 192.168.174.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
After saving the configuration file, perform the following preparations
mkdir /home/nfstestdir
chmod 777 /home/nfstestdir
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
Client: yum install -y nfs-utils
NFS configuration options
rw read and write
ro Ragnarok Online
sync synchronization mode, memory data is written to disk in real time
async asynchronous mode
no_root_squash After the client mounts the NFS shared directory, the root user is not restricted and has great permissions
root_squash In contrast to the above options, the root user on the client is constrained and limited to a common user
all_squash All users on the client are limited to a common user when using NFS to share directories
anonuid/anongid is used in conjunction with the above options to define the uid and gid of the limited user
client mount
yum install -y nfs-utils
showmount -e 192.168.174.128 //This ip is the NFS server ip
[root@c-72 ~]# showmount -e 192.168.174.128
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
The above problem occurs, set both sides at the same time
[root@c-72 ~]# systemctl stop firewalld
[root@c-72 ~]# setenforce 0
[root@anan-03 mnt]# showmount -e 192.168.174.128
Export list for 192.168.174.128:
/home/nfstestdir 192.168.174.0/2
mount -t nfs 192.168.174.128:/home/nfstestdir /mnt
df -h
cd /mnt/
touch /mnt/anan03.txt
ls -l /mnt/anan03.txt //You can see that the owner and group of the file are both 1000
[root@localhost ~]# ls -l /home/nfstestdir
Total usage 0
-rw-r--r--. 1 user1 test1 0 1月 6 21:49 anan03.txt
[root@localhost ~]# id user1
uid=1000(user1) gid=1006(user1) 组=1006(user1)