Home >Common Problem >what is nfs

what is nfs

青灯夜游
青灯夜游Original
2022-11-29 11:16:3623089browse

nfs refers to the network file system, which is one of the file systems supported by FreeBSD. It allows computers on the network to share resources through the TCP/IP network. NFS is an application based on the UDP/IP protocol. Its implementation mainly uses the remote procedure call RPC mechanism. RPC provides a set of operations for accessing remote files that are independent of the machine, operating system, and low-level transmission protocol.

what is nfs

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

1. Introduction to nfs

Network File System, English Network File System (NFS), is a UNIX presentation layer protocol developed by SUN. Enables users to access files elsewhere on the network just like using their own computer.

NFS is an application based on the UDP/IP protocol. Its implementation mainly uses the remote procedure call RPC mechanism. RPC provides a set of operations for accessing remote files that are independent of the machine, operating system, and low-layer transmission protocol. RPC uses XDR support. XDR is a machine-independent data description encoding protocol. It encodes and decodes data transmitted over the Internet in a format independent of any machine architecture, and supports the transmission of data between heterogeneous systems.

1.1 nfs features

  • NFS (Network File System) is a network file system. It is one of the file systems supported by FreeBSD. It allows Resources are shared between computers through the TCP/IP network
  • In NFS applications, the local NFS client application can transparently read and write files located on the remote NFS server, just like accessing local files
  • nfs is suitable for file sharing between Linux and Unix, but cannot realize file sharing between Linux and Windows.
  • nfs is a protocol running at the application layer, and it listens to 2049/tcp and 2049
  • nfs service on /udp socket can only be authenticated based on IP

1.2 Application scenarios of nfs

nfs has many practical applications Application scenarios, the following are some common scenarios:

  • Multiple machines share a CDROM or other device. This is cheaper and more convenient for installing software on multiple machines
  • In large networks, it may be convenient to configure a central NFS server to house all users' home directories. These directories can be exported to the network so that users can always get the same home directory no matter which workstation they log in on.
  • Different clients can watch movie and TV files on NFS, saving local space
  • The work data completed on the client can be backed up and saved to the user's own path on the NFS server

1.3 nfs system composition

nfs system must have at least Two main parts:

  • One nfs server
  • Several clients

The architecture diagram of the nfs system is as follows:

what is nfs

Clients remotely access data stored on the NFS server through the TCP/IP network
Before the NFS server is officially enabled, some NFS parameters need to be configured based on the actual environment and needs

2. nfs working mechanism

nfs is based on rpc to realize network file system sharing. So let’s talk about rpc first.

2.1 RPC

RPC (Remote Procedure Call Protocol), a remote procedure call protocol, is a method of requesting services from a remote computer program through the network without Understand the protocols of underlying network technologies.

The RPC protocol assumes the existence of some transport protocol, such as TCP or UDP, to carry information data between communicating programs. In the OSI network communication model, RPC spans the transport layer and application layer.

RPC adopts client/server mode. The requester is a client, and the service provider is a server.

what is nfs

The working mechanism of rpc is shown in the figure above. Let’s describe it below:

  • The client program initiates an RPC system call and sends it to another host (server) based on the TCP protocol.
  • The server listens on a certain socket. When receiving the client's system After calling the request, execute the received request and the parameters passed through the local system call, and return the result to the local service process
  • After receiving the returned execution result, the service process on the server side will It is encapsulated into a response message and then returned to the client through the rpc protocol
  • The client calls the process to receive the reply information, obtains the process result, and then calls the execution to continue

2.2 nfs working mechanism

The NFS server runs four processes:

  • nfsd

  • mountd

  • idmapd

  • portmapper

idmapd

Realize centralized mapping of user accounts and map all accounts to NFSNOBODY, but when accessing, they can access as a local user

mountd

Used to verify whether the client is in the list of clients allowed to access this NFS file system. If so, access is allowed (issue a token and hold the token to find nfsd), otherwise Access denied

The service port of mountd is random, and the random port number is provided by the rpc service (portmapper)

nfsd

nfs daemon, listening on 2049/tcp and 2049/udp ports

is not responsible for file storage (the local kernel of the NFS server is responsible for scheduling storage), Used to understand the rpc request initiated by the client, transfer it to the local kernel, and then store it on the specified file system

portmapper

NFS server's rpc service, which listens on 111/TCP and 111/UDP sockets, is used to manage remote procedure calls (RPC)

The following is an example to illustrate the simple work of NFS Process:

Requirements: View the information of the file file. This file is stored on the remote NFS server host (mounted in the local directory /shared/nfs)

what is nfs

  • The client initiates a command to view file information (ls file) to the kernel. The kernel learns through the NFS module that this file is not a file in the local file system. It is a file on the remote NFS host
  • The kernel of the client host encapsulates the instruction (system call) to view the file information into an rpc request through the RPC protocol and sends it to the NFS server host through TCP port 111 portmapper
  • The portmapper (RPC service process) of the NFS server host tells the client that the mountd service of the NFS server is on a certain port. You go to it to verify

Because mountd is on When providing services, a port number must be registered with portmapper, so portmapper knows which port it is working on.

  • After the client learns the port number of the server's mountd process, it uses the known server mountd Port number request verification
  • After receiving the verification request, mountd verifies whether the client that initiated the request is in the list of clients allowed to access this NFS file system. If so, access is allowed (issue a token, hold the token to Find nfsd), otherwise access is denied
  • After passing the verification, the client uses the token issued by mountd to find the nfsd process of the server and requests to view a certain file
  • The nfsd process of the server initiates a local system call. Request to the kernel to view the information of the file that the client wants to view
  • The kernel of the server executes the system call requested by nfsd and returns the result to the nfsd service
  • After the nfsd process receives the result returned by the kernel Encapsulate it into an rpc request message and return it to the client through the tcp/ip protocol

For more related knowledge, please visit the FAQ column!

The above is the detailed content of what is nfs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what does hdmi cable meanNext article:what does hdmi cable mean