14.1-14.3 NFS introduction, server installation, client mount NFS

14.1 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

blob.png

Application scenarios:

ABC is three machines

They each need to access the same directory, and the directory is full of pictures. The traditional way is to put these pictures into A, B, C respectively,

But if you use NFS, you only need to put the picture on A, and then A can share it with B and C. When accessing B and C, the directory on A is accessed through the network.


NFS schematic

blob.png

The NFS server starts the NFS service, and uses the RPC service (starting rpcbind to implement RPC communication) to provide the NFS client to use the NFS service

rpcbind listens on port 111

NFS services need to use the RPC protocol to communicate


14.2 NFS server installation configuration

outline

blob.png

Ready to work:

2 or more linux machines 

centos7-01 (192.168.189.128) client

centos7-02 (192.168.189.129) server

*All the following operations are performed on the server side

1 First install two packages on the server and client

[root@centos7-01 ~]# yum install -y nfs-utils rpcbindc

[root@centos7-02 ~]# yum install -y nfs-utils rpcbindc

2 After the installation is complete, edit the exports file

[root@centos7-01 ~]#vim /etc/exports //Add the following

/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

Format explanation:

Split by space (space bar), divided into three parts

The first part is the directory to be shared locally (if it does not exist, you need to create it yourself)

The second part is the host that is allowed to access (can be an IP or an IP range)

The third part is the permission options in parentheses.

3 Start the service

3.1 Preparations before starting the service

[root@centos7-01 ~]#mkdir /home/nfstestdirCreate a share directory

[root@centos7-01 ~]#chmod 777 /home/nfstestdirGrant 777 permission to facilitate later test permissions to pass

Check the listening port to see the status of the rpcbind listening port

[root@centos7-01 ~]# netstat -lntp |grep 111

tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd

In fact, port 111 is the service of rpcbind. Displaying systemd here does not mean that rpcbind is not being monitored.

Just remember that port 111 is used by the rpcbind service.

3.2 Start the service

#systemctl start rpcbindstart rpc service

#systemctl start nfsstart nfs service

#systemctl enable rpcbindStart the rpc service at boot

#systemctl enable nfsStart the nfs service at boot (server side)



14.3 NFS configuration options

outline

blob.png

First look at the parameter options of the server configuration

[root@centos7-01 home]# cat /etc/exports

/home/nfstestdir 192.168.189.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

Option Explanation:

 rw read and write

 ro Ragnarok Online

 sync synchronization mode, memory data is written to disk in real time (reduces disk efficiency)

 async Asynchronous mode, which means that data in memory is periodically written to disk. (Benefit: Guaranteed disk efficiency, Disadvantage: Power outage may lose some data)

 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 mounts NFS

outline

blob.png

1 Install the nfs-utils package

#yum install -y nfs-utils

2 View the status of the specified ip mount service, the following ip is the NFS server ip

[root@centos7-02 ~]# showmount -e 192.168.189.128

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

The error message indicates that the network is blocked and the communication fails (reason: the firewall and rpc ports are not monitored)

2.1 Turn off the firewall service of the client and server

[root@centos7-01 home]# systemctl stop firewalld

[root@centos7-01 home]# setenforce 0

[root@centos7-02 home]# systemctl stop firewalld

[root@centos7-02 home]# setenforce 0

2.2 After closing the firewall, showmount again

[root@centos7-02 ~]# showmount -e 192.168.189.128

Export list for 192.168.189.128:

/home/nfstestdir 192.168.189.0/24

After closing the firewall, output normally, you can see that the status information is the same as the NFS setting of the server

3 Mount NFS

[root@centos7-02 ~]# mount -t nfs 192.168.189.128:/home/nfstestdir /mnt/

3.1 Check mount

[root@centos7-02 ~]# df -h

Filesystem Capacity Used Free Used % Mount Points

/dev/sda3 28G 1.1G 27G 4% /

devtmpfs                          483M     0  483M    0% /dev

tmpfs                             493M     0  493M    0% /dev/shm

tmpfs                             493M  6.8M  486M    2% /run

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

/dev/sda1                         187M   97M   91M   52% /boot

tmpfs                              99M     0   99M    0% /run/user/0

192.168.189.128:/home/nfstestdir   28G  9.3G   19G   34% /mnt

3.2 Create a file test on the client

3.2.1 Creating a file on the client

[root@centos7-02 ~]# cd /mnt/

[root@centos7-02 mnt]# touch client.test

[root@centos7-02 mnt]# ls -l

Total usage 0

-rw-r--r--. 1 user5 user5 0 5月   9 16:14 client.test

3.2.2 Check whether the file is created on the server side

[root@centos7-01 home]# cd /home/nfstestdir/

[root@centos7-01 nfstestdir]# ls -l

Total usage 0

-rw-r-r-- 1 our our 0 5 月 9 16:14 client.test

file is created,

But you can see that the file username and group created by the client are different.

The reason is : the uid and gid are limited to 1000 on the server side, so the users and user groups of the client and server are different.

User with server ID 1000

[root@centos7-01 nfstestdir]# cat /etc/passwd |grep 1000

aming: x: 1000: 1000 :: / home / aming: / bin / bash

User with client ID 1000

[root@centos7-02 mnt]# cat /etc/passwd |grep 1000

user5:x:1000:1000::/home/user5:/bin/bash

This can prove that NFS is successfully built.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326341079&siteId=291194637