Introduction and construction of NFS service


prefaceThis is my first essay in the blog Garden platform, I hope to have a good start, come on.

1. Introduction to services for NFS:

NFS, English full name network file system, Chinese name is called network file system.

NFS service can mount the file sharing resources on the remote Linux system to the directory of the local host, so that the local host can read and write the shared files on the remote Linux system just like accessing its own resources. To a certain extent, it makes our work efficiency more efficient.

  NFS service adopts C / S architecture, which is composed of a client program and a server program. The server program provides access to the file system to other computers, and its process is called output. When the NFS client program accesses the shared file system, it “transports” them from the NFS server.

2. The system environment of this paper is as follows

  Operating system:CentOS 7.4

  Server IP: (for deploying services for NFS)

  Client IP: (used to verify whether service for NFS is deployed successfully)

3. Environment preparation before deployment:

  Close the server system firewall:

  systemctl stop firewalld.service

Close SELinux temporarily:

  setenforce 0

4. Officially start the deployment of NFS server:

  Create a new directory for NFS file sharing:

  mkdir  nfsfile

 Grant sufficient permissions to the shared directory to ensure that others have write permissions:

  chmod  -R  777  nfsfile

  Create a new test file in the shared directorytest.txtFor subsequent client verification:

  cd  nfsfile

  echo  “This is a test file” > /nfsfile/test.txt

5. Use VIM to open the configuration file / etc / exports of NFS service, and enter the configuration items related to the client

be careful:By default, the / etc / exports file is empty. We can configure it in the following format:

Shared directory path allowed NFS clients (shared permission parameter)

For example:

  /nfsfile  192.168.178.*(rw,sync,root_squash)   #Note: no space between NFS client address and permission!

The above configuration items are explained as follows:

/Nfsfile # local shared directory

192.168.178. * # all hosts in network segment are allowed to access the local shared directory

All hosts in the RW # network segment have read and write access to the local shared directory

Sync # every change will write data to memory and hard disk to ensure no data loss

root_ Square # when the client for NFS accesses the local shared directory as root, it maps to the anonymous user of the server for NFS

6. Start RPC service and NFS service:

Before using NFS service for file sharing, RPC (remote procedure call) service is needed to send the IP address and port number of NFS server to the client.

Therefore, before starting NFS service, we need to start RPC service first. (It must be in this order!

If the current system does not install NFS and RPC services by default, then we need to install services first!

The installation package corresponding to RPC service is rpcbind

The corresponding service program of RPC service is: rpcbind

The installation package corresponding to NFS service is:nfs-utils

The corresponding service program of NFS service is: NFS server

  RPM – QA NFS utils rpcbind # checks whether the corresponding two packages are installed. If the information is not returned after the execution, it means that they are not installed

Yum – y install NFS utils rpcbind # install NFS and RPC packages

  systemctl  start  rpcbind

Systemctl enable rpcbind # add rpcbind service to boot entry

  systemctl  start  nfs-server

Systemctl? Enable? NFS server? Adds the NFS server service to the boot entry

7. Start the deployment of client for NFS: (note that it is the client!)

Just like the server, if it is not installed, install NFS and RPC first, and start the service!

We learn a command:showmount

usageShowmount parameter NFS server IP

effect:Used to query remote shared information of NFS server. The output format is as follows:The shared directory name is the allowed client address

Common parameters:

-E displays the shared list of NFS servers

-A shows the file resources attached to the machine

-V displays the version number

We execute the following command on the client side:

  showmount  -e

The results are as follows

Export list for

/root/nfsfile  192.168.178.*

The client starts to mount the shared directory:

MKDIR nfsfile # client new mount point

Mount – t NFS / root / nfsfile / root / nfsfile ᦇ mount the server shared directory to the newly created mount point

The client verifies whether the mount is successful:

CD / root / nfsfile # after entering the directory, you will see the file created on the server test.txt file

  cat test.txt After opening, it is found that the content of the file is consistent with that of the server. Explain the NFS shared file systemBuild successfully

Finally, if you need to permanently mount the shared directory(That is to realize the automatic mounting after power on), which can be realized in the following ways:

  echo “mount -t nfs /root/nfsfile” >> /etc/rc.d/rc.local  #Write mount command to rc.local