Basic implementation of nfs

  NFS (Network File System) is a network file system, which is one of the file systems supported by FreeBSD. It allows computers in the network to share resources through the TCP/IP network. In NFS applications, local NFS client applications can transparently read and write files located on remote NFS servers, just like accessing local files.
   NFS was first developed by Sun Corporation.
  To put it simply: it allows different hosts and different operating systems to share storage through the network.

Basic implementation of nfs
Here are the most obvious benefits of NFS:

  1. Save local storage space, store commonly used data on an NFS server and access it through the network, then the local terminal can reduce the use of its own storage space.

  2. The user does not need to have a Home directory on every machine in the network. The Home directory can be placed on the NFS server and can be accessed and used on the network.

  3. Some storage devices such as CDROM and Zip (a high storage density disk drive and disk) can be used by other machines on the network. This reduces the number of removable media devices across the network.

  The basic principle of NFS is "allowing different clients and servers to share the same file system through a set of RPCs". It is independent of the operating system and allows systems with different hardware and operating systems to share files together.

  NFS relies on the RPC protocol during file transfer or information transfer. RPC, Remote Procedure Call (Remote Procedure Call) is a mechanism that enables clients to execute programs in other systems. NFS itself does not provide protocols and functions for information transmission, but NFS allows us to share data through the network, because NFS uses some other transmission protocols. And these transport protocols use this RPC function. It can be said that NFS itself is a program that uses RPC. Or NFS is also an RPC SERVER. So as long as NFS is used, the RPC service must be started, whether it is NFS SERVER or NFS CLIENT. In this way, SERVER and CLIENT can realize the correspondence of PROGRAM PORT through RPC. The relationship between RPC and NFS can be understood in this way: NFS is a file system, and RPC is responsible for the transmission of information.
1. Server configuration

nfs-utils: This is the main program of NFS service (including rpc.nfsd, rpc.mountd, daemons)
rpcbind: This is the RPC main program of CentOS6.X (portmap for CentOS5.X)

yum install -y nfs-utils rpcbind #Install nfs server

systemctl start rpcbind
systemctl enable rpcbind #Set boot start

netstat -lntup |grep rpcbind #Query the startup status of the rpcbind service
rpcinfo -p localhost #View the port registered by the NFS service item rpc server

Because in the process of FNS service, rpcbind must be started first, and then nfs must be started, so that NFS can be successfully registered on rpcbind

systemctl start nfs
systemctl enable nfs #Set boot up

rpcinfo -p localhost #View the port registered by the NFS service item rpc server

In order to standardize, it is best to use rc.local to manage boot auto-start

[root@NFS-server ~]# ps -ef |egrep "rpc|nfs" #View nfs phase process
rpcuser 1303 1 0 Nov22 ? 00:00:00 rpc.statd #Check file consistency
root 1512 2 0 Nov22 ? 00 :00:00 [rpciod/0]
rpc 2723 1 0 02:43 ? 00:00:00 rpcbind
root 2896 1 0 02:56 ? 00:00:00 rpc.rquotad #disk quota process
root 2901 1 0 02:56 ? 00:00:00 rpc.mountd #Permission management verification, etc.
root 2908 2 0 02:56 ? 00:00:00 [nfsd4]
root 2909 2 0 02:56 ? 00:00:00 [nfsd4_callbacks]
root 2910 2 0 02:56 ? 00:00:00 [nfsd]
root 2911 2 0 02:56 ? 00:00:00 [nfsd]
root 2912 2 0 02:56 ? 00:00:00 [nfsd]
root 2913 2 0 02: 56 ? 00:00:00 [nfsd] #NFS main process, management login, identity determination
root 2914 2 0 02:56 ? 00:00:00 [nfsd]
root 2915 2 0 02:56 ? 00:00:00 [ nfsd]
root 2916 2 0 02:56 ? 00:00:00 [nfsd]
root 2917 2 0 02:56 ? 00:00:00 [nfsd]
root 2948 1 0 02:56 ? 00:00:00 rpc.idmapd #Name mapping
2. Configuration
/etc/exports is the configuration file of the NFS program. And the default is empty
. The configuration format of the /etc/exports file is:
NFS shared directory NFS client address 1 (parameter 1, parameter 2, parameter 3...) client address 2 (parameter 1, parameter 2, parameter 3...)
NFS shared directory NFS client address (parameter 1, parameter 2, parameter 3...)

Configuration file (/etc/exports)

Lines starting with # indicate comments

格式: share_dir client_host(permission1,permission2,...,permissionn)

parameter:

(1)share_dir

The shared directory must be a directory. If it is a file, an error will occur during mounting.

If the directory name contains characters such as spaces, use double quotation marks

(2)client_host

Can be a single host (10.226.70.32) or a network segment (10.226.70.0/24), supports wildcards * and ?

(3)permission

ro: read-only

rw: read and write (read-write)

root_squash: Squash the root user. When the client is mounted as root, the NFS server treats root as an anonymous user service (nfsnobody)

no_root_squash: Do not squash the root user. When the client is mounted as root, the NFS server still regards root as the root user, not all.
all_squash: Map all ordinary users and their groups for remote access to anonymous users or user groups (nfsnobody)

anonuid=xxx: Map all remote access users as anonymous users, and specify the user as a local user (UID=xxx);

anongid=xxx: Map all remote access user groups to anonymous user group accounts, and specify the anonymous user group account as a local user group account (GID=xxx);
sync: synchronously write to disk

async: write to disk asynchronously.

(1) Separate multiple permissions with commas

E.g:

/testnfs 10.226.70.0/24(rw,sync,no_root_squash)

Share the server's /testnfs directory to the 10.226.70.0/24 network segment. The hosts belonging to this network segment have the permissions to read and write, synchronously write to disk, and not compress the root user.

(2) After modifying /etc/exports, to make the modified file take effect, you need to use the exportfs command or restart the nfs service

exportfs -ra

mkdir /data
chown -R nfsnobody.nfsnobody /data #Use nfs default account
mount /dev/sdb /data
vim /etc/exports #Add configuration file
/data 10.100.0.0/16(rw,sync)

systemctl reload nfs

showmount -e 127.0.0.1 #View local mounts
Basic implementation of nfs

3. Configure the NFS client
The client also needs to install the rpcbind and nfs-utils software, and set the boot to start automatically. (Just need to start rpcbind)

yum -y install rpcbind nfs-utils

systemctl start rpcbind
systemctl enable rpcbind #Set boot start

showmount -e 10.100.5.56 #Detect mount
Basic implementation of nfs

mount -t nfs 10.100.5.56:/data /mnt
Basic implementation of nfs

You can see that the mount is successful

Basic implementation of nfs

Basic implementation of nfs

4. Set up to automatically mount
vim /etc/
fatab 10.100.5.56:/data /mnt nfs defaults 0 0

Guess you like

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