Network File System -NFS

1. What is the NFS

  NFS is an acronym for Network File System, that is network file system. Using a protocol for distributed file system, Sun has developed, in 1984 public. Function through the network to allow different machines, different operating systems to share data with each individual, so that the client application data server located on a network disk access, is a method for disk file sharing between Unix-like systems .

 

   Its main function is to allow the network can share files and directories from each other between different machines. NFS NFS server can allow the client to the NFS server shared directory distal end mounted to a local NFS client. In local NFS client machine seems, NFS server shared directory if your disk partitions and directories. General client mount to a local directory name can be casual, but for the convenience of management, advice and consistent server.

NFS is generally used to store shared video, pictures and other static data.

 

 

2. NFS mount principle

  NFS is the data transmission between the server and clients through a network. To transfer data between the two should have a corresponding network port for transmission. NFS server in the end what the network port to transmit data, NFS server is actually a randomly selected 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 achieved through remote calls (remote procedure call referred RPC) protocol / service. That NFS RPC services will be unified management of the port, the client and server to communicate through NFS RPC which ports to use, after transport use these ports (less than 1024) to the data.

  Port is the port assignment NFS RPC management server, the client data to be passed, and that the client's RPC will talk to the server to be an RPC server, go to the port after re-establish a connection, then transfer the data.

How to communicate with each other between RPC and NFS?

When the first NFS started, it will use some random port, then NFS RPC will go to register these ports. RPC will record these ports. And RPC will open 111 ports, RPC request to wait for the client, if the client has requested that the service side of the NFS RPC port information will be recorded telling the client.

RPC and NFS boot sequence is like?

Before starting the NFS services, we must first start the RPC service (ie portmap service, the same below), otherwise the service will not be able to register with the NFS RPC service area, in addition, if the RPC service is restarted, the original data has been registered good will all NFS port lost, so this time the NFS RPC service management service also needs to be restarted to re-think RPC registered. Note: After modifying the general NFS configuration file is no need to restart NFS directly /etc/init.d/nfs reload

Summary: NFS Client and NFS server communication process

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

2) enable NFS and RPC port registration information

3) client initiates RPC (portmap service), requesting NFS server port to the service side of the RPC service

4) the server's RPC (portmap) service feedback information to the client NFS port

NFS. 5) is established by the client to obtain the NFS server and is connected to the port and data transmission

 

 

3. NFS-related agreements and Software Installation

protocol:

  RPC (Remote Procedure Call Protocol) - remote procedure call protocol

software:

  nfs-util- *: command and control procedures, including NFS

  rpcbind- *: supports connection to install NFS RPC services

Note: In general, as the default bag system installed

Centos6. * Before called portmap rpcbind

4. NFS system daemons

nfs: basic NFS daemons, the main function is manages the client can login to the server

rpcbind:主要功能是进行端口映射工作。当客户端尝试连接并使用RPC 服务器提供的服务(如NFS服务)时,rpcbind 会将所管理的与服务对应的端口提供给客户端,从而使客户可以通过端口向服务器请求服务。

5.NFS 服务器的配置

NFS 服务器的配置相对比较简单,只需在相应的配置文件中进行设置,然后启动NFS 服务器即可。

NFS 服务的配置文件为 /etc/exports,这个文件是NFS 的主要配置文件,不过系统没有默认值,所以这个文件不一定会存在,可能需手动建立,然后在文件里写入配置内容。

/etc/exports 文件内容格式:

共享目录  客户端1 (访问权限,用户映射,其他) 客户端2 (访问权限,用户映射,其他)

a. 共享目录:共享目录是指NFS 服务器共享给客户机使用的目录

b. 客户端:客户端是指网络中可以访问这个 NFS 共享目录的计算机

客户端常用的指定方式:

  指定ip 地址的主机:192.168.80.130

  指定子网中所有的主机:192.168.80.0

  指定域名的主机:www.learn.com

  指定域中的所有主机:*.learn.com

  所有主机:*

c. 设置共享目录的访问权限、用户映射等。

访问权限设置:

  设置共享目录只读:ro

  设置共享目录读写:rw

 

用户映射选项:

  root_squash:将root用户的访问映射为匿名(nfsnobady)用户的 uid 和 gid(默认生效);

  no_root_squash:保留管理员权限,以服务器管理员的权限管理;

  all_squash:将远程访问的用户及所属组都映射为指定 uid 和 gid 的匿名用户;

    anonuid=xxx:将远程访问的所有用户都映射为指定 uid 的匿名用户;

    anongid=xxx:将远程访问的所有用户组都映射为指定 gid 的匿名组用户;

 

其他选项:

  sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性(同步);

  async:将数据先保存在内存缓冲区中,必要时再写入磁盘(异步);

6. NFS服务器的启动与停止

6.1 启动 NFS 服务器

为了使NFS 服务器能正常工作,需要启动 rpcbind 和 nfs 两个服务,并且 rpcbind 一定要先于 nfs 启动

[root@centos2 ~]# systemctl start rpcbind
[root@centos2 ~]# systemctl start nfs

Guess you like

Origin www.cnblogs.com/sswind/p/12055071.html