NFS deployment of combat and introduces the principle of

About NFS

The acronym NFS (Network File System), its main function is: through the network, so that different machines, different OS can share each other's files

NFS server can allow NFS client NFS server's shared directory distal to mount its own NFS client, so the client is like there is a piece in the local disk, like, just a network disk only.

Mount structure of FIG.

As shown above, when we set up a shared directory / data / share on the NFS server, the other has access to NFS client NFS server can tell this to their own local directory is mounted, and can see the server / data All data in / share

NFS is carried out by a network of data transmission between Server and Client-side end, since walking network, the two sides certainly should have port, which NFS Server how to know which port to use for data transmission, in fact, NFS will randomly select a port for data transmission. That NFS client and NFS server know how in the end is which port to use it? In fact, the NFS server is done by remote procedure calls RPC (Remote Procedure Call) protocol, therefore, NFS port assignment RPC management server, the client to transfer data, the client's RPC will begin with server-side RPC to go to the server's port , to the port, the re-connection is established, and data transmission, see below

NFS client / NFS server, RPC diagram

Communication process:

1. First start the RPC server-side service, and open port 111

2. Start the NFS server service, and RPC ports registration information

3. RPC client starts the service, the service request to the server end of the NFS RPC service port

4. The service side of the NFS RPC service port feedback information to the client.

The NFS client and server to establish a connection and transmitting data acquired by the NFS port.

Machinery list

CPU name

IP addresses

Operating system version

Remark

node100

172.20.20.100

NFS server

node200

172.20.20.200

 

NFS Client

lab environment

CentOS:CentOS Linux release 7.6.1810 (Core)

2 stations are operating

Configuring the host name:

# cat >> /etc/hosts << EOF

172.20.20.100 node100

172.20.20.200 node200

EOF

 

 

NFS server operation

# rpm -qa nfs-utils rpcbind

# yum install nfs-utils rpcbind

Create a directory

# mkdir  -p /data/share

# chmod 666 /data/share/

# cat >> /etc/exports << EOF

/data/share 172.20.20.0/24(rw,sync,insecure,no_subtree_check,no_root_squash)

EOF

# mkdir -p /data/share/soft/

Start the RPC service

# systemctl start rpcbind.service

[root@node100 ~]# ps -ef|grep rpcbind

rpc       15712      1  0 03:41 ?        00:00:00 /sbin/rpcbind -w

root      15714   8035  0 03:41 pts/0    00:00:00 grep --color=auto rpcbind

[root@node100 ~]# rpcinfo  -p localhost

program vers proto   port  service

100000    4   tcp    111  portmapper

100000    3   tcp    111  portmapper

100000    2   tcp    111  portmapper

100000    4   udp    111  portmapper

100000    3   udp    111  portmapper

100000    2   udp    111  portmapper

Start the NFS Services

# service nfs start

[root@node100 ~]# rpcinfo  -p localhost

program vers proto   port  service

100000    4   tcp    111  portmapper

100000    3   tcp    111  portmapper

100000    2   tcp    111  portmapper

100000    4   udp    111  portmapper

100000    3   udp    111  portmapper

100000    2   udp    111  portmapper

100024    1   udp  40044  status

100024    1   tcp  34946  status

100005    1   udp  20048  mountd

100005    1   tcp  20048  mountd

100005    2   udp  20048  mountd

100005    2   tcp  20048  mountd

100005    3   udp  20048  mountd

100005    3   tcp  20048  mountd

100003    3   tcp   2049  nfs

100003    4   tcp   2049  nfs

100227    3   tcp   2049  nfs_acl

100003    3   udp   2049  nfs

100003    4   udp   2049  nfs

100227    3   udp   2049  nfs_acl

100021    1   udp  37957  nlockmgr

100021    3   udp  37957  nlockmgr

100021    4   udp  37957  nlockmgr

100021    1   tcp  43494  nlockmgr

100021    3   tcp  43494  nlockmgr

100021    4   tcp  43494  nlockmgr

Whether to load the configuration / etc / exports

[root@node100 ~]# showmount  -e localhost

Export list for localhost:

/data/share 172.20.20.0/24

In the NFS client installation

# yum install nfs-utils

[Root @ node200 ~] # showmount -e 172.20.20.100

Export list for 172.20.20.100:

/data/share 172.20.20.0/24

Test the NFS client

# mkdir /root/soft/

# mount 172.20.20.100:/data/share/soft /root/soft

[root@node200 soft]# df -Th

Filesystem                     Type      Size  Used Avail Use% Mounted on

/dev/sda3                      xfs        36G  1.1G   35G   4% /

devtmpfs                       devtmpfs  224M     0  224M   0% /dev

tmpfs                          tmpfs     235M     0  235M   0% /dev/shm

tmpfs                          tmpfs     235M  5.6M  229M   3% /run

tmpfs                          tmpfs     235M     0  235M   0% /sys/fs/cgroup

/dev/sda1                      xfs       897M  127M  771M  15% /boot

tmpfs                          tmpfs      47M     0   47M   0% /run/user/0

172.20.20.100:/data/share/soft nfs4       36G  1.1G   35G   4% /root/soft

Problems encountered

[Root @ node200 ~] # showmount -e 172.20.20.100

clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

Because iptables rules did not add due, the solution:

First, turn off the firewall, this is not the whole ×××. Another iptables can add nfs to all ports

As used herein, the first method:

systemctl stop firewalld.service

service iptables stop

Related parameters:

parameter

Explanation

ro

Read-only access

rw

Read and write access

sync

All data written in the shared request

async

nfs in response to the request before the data can be written

secure

nfs security by 1024 following TCP / IP port to send

insecure

By transmitting the above nfs port 1024

wdelay

If multiple users want to write nfs directory, the grouping write (default)

no_wdelay

If multiple users want to write nfs directory, write immediately, when using async, you do not need this setting

hide

Does not share its subdirectories nfs shared directory

no_hide

Nfs shared directory subdirectories

subtree_check

If you share a subdirectory / usr / bin and the like, nfs inspection authority to force the parent directory (the default)

no_subtree_check

Do not check the parent directory permissions

all_squash

UID and GID mapping file sharing anonymous user anonymous, for public directory

no_all_squash

Reserved share files UID and GID (default)

root_squash

All root user requests as mapped to the same anonymous user rights (default)

no_root_squash

Full administrative access to the root user with root directory

anonuid = xxx

Specify nfs server / etc / passwd file in the anonymous user's UID

anongid=xxx

Specify nfs server / etc / passwd file in the anonymous user's GID

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159479.htm