NFS service introduction and experiment

First, what is NFS

NFS is an acronym for Network File System, that is network file system. Agreement for use in distributed file system developed by Sun Microsystems in 1984 made 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 between different machines each other systems. 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.

NFS services are mainly used for file sharing, such as static files of music, videos, music and so on.

Two, NFS service connection principle

NFS is the data transmission between the server and clients through a network. To transfer data between the two will want to 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, through the NFS server remote procedure calls (remote procedure call referred RPC) protocol / service to achieve. That NFS RPC services will be unified management of the port, the client and server communicate via NFS RPC-come, first used the port which, after the re-use of these ports (less than 1024) for transmission of 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, and then to establish a connection to the port, and then transfer the data.
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 recorded NFS RPC will tell the client port information.
Before starting the NFS SERVER, you must first start the RPC service (ie portmap service, the same below) or NFS SERVER will not be able to register with the RPC service area, in addition, if the RPC service is restarted, the already registered good NFS port data will be lost . Therefore, at this time of NFS RPC service management program should be restarted to re-register with the RPC. Special Note: NFS is generally modified configuration file is no need to restart the NFS, execute directly on the command

/etc/init.d/nfs  reload
Three, NFS service connection 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), a service request to the NFS server port server-side RPC (portmap)
  • 4) the server's RPC (portmap) service feedback NFS port information to the client.
  • NFS. 5) is established by NFS client and server ports acquired connection and data transmission
Five related software installed

Protocol:
RPC (Remote Procedure Call Protocol) remote procedure call protocol
software:
nfs-utils- *: including NFS command and monitoring procedures
rpcbind- *: security support NFS RPC service connection

Note: Under normal circumstances, as the default system package installed
Cent OS6 * called before rpcbind portmap.

yum install nfs -y 
Six, NFS service configuration

NFS server configuration is relatively simple, only needs to be set in the appropriate configuration file, and then start the NFS server.
NFS Services configuration file is / etc / exports, the NFS file is the main configuration file, but the system does not default values, so this file does not exist, you may want to use vim to manually create and write configuration file contents inside .

共享目录  客户机(访问权限,用户映射,其他) 
Client computer
  • The host is specified ip address: 100.100.100.200
  • All hosts specified subnet: 100.100.100.0
  • Specify the domain name of the host: www.love1.com
  • All hosts in the specified domain:. * Love1.com
  • All hosts: *
access permission
  • Set the output directory read-only: ro
  • Set output directory write: rw
User Mapping
  • root_squash: The root user access mapped to anonymous (nfsnobody) user uid and gid; (default to take effect)
  • no_root_squash: Reserved administrator rights to server administrator rights management;
  • all_squash: The remote access user and the respective groups are mapped to the specified uid, gid of the anonymous user;
    anonuid = xxx: all users remote access are mapped to the specified uid anonymous user
    anongid = xxx: all the user groups remote access gid are mapped to the specified anonymous group account
other
  • sync: synchronize data written to the disk buffer memory, the efficiency is low, but you can guarantee data consistency (synchronous);
  • async: the first data stored in the memory buffer, if necessary written to disk (asynchronous)
Seven, NFS Service Management

1, start the NFS server

service rpcbind start 
service nfs start 

2, NFS server status query

service rpcbind status 
service nfs status   

3, stop the NFS server
to stop running NFS, you need to stop the service before stopping the rpcbind nfs service when the system for other services (such as NIS) is required, no need to stop rpcbind service.

service nfs stop 
service rpcbind stop 

4, set up an NFS server autostart state
setting boot, default startup level in 2345

chkconfig --level rpcbind on 
chkconfig --level  nfs on 

5. Check which ports RPC server is turned on

rpcinfo –p localhost
Eight experiments
1. Create a directory to modify configuration files
[root@centos ~]#mkdir /share
[root@centos ~]#vim /etc/exports
    /share  100.100.100.103(rw)   
[root@centos ~]#service nfs restart
[root@centos ~]# exportfs
/share          100.100.100.103
2, a view shared services
[root@centos ~]# showmount -e 100.100.100.102
Export list for 100.100.100.102:
/share 100.100.100.103
3, the client mount
[root@centos ~]# mkdir /share
命令格式:mount NFS服务器IP:共享目录 本地挂载点目录 
[root@centos ~]# mount 100.100.100.102:/share /share  
    #mount –o vers=3 共享 本地 #指定挂载使用nfs V3版本(避免同步延迟)
    #[root@centos /]# mount  -o vers=3 100.100.100.102:/share  /share
[root@centos ~]# mount | grep /share
 100.100.100.102:/share on /share type nfs (rw,vers=4,addr=100.100.100.102,clientaddr=100.100.100.103)
[root@centos share]# echo haha>1.txt
-bash: 1.txt: Permission denied  
#此时,无法写入文件,因为没有文件系统权限,/share目录所属用户是root,我们进行挂载时,用户为nfsnobody,因此没有权限。有多种方法,这里示例两种。
1)修改配置文件
[root@centos ~]# vim /etc/exports
    /share  100.100.100.103(no_root_squash,rw)
[root@centos share]# echo haha>1.txt
[root@centos share]# ll
total 4
-rw-r--r-- 1 root root 5 Jan  1 21:38 1.txt
2)修改文件系统权限
chmod 777 /share
4, unloading and automatically mount

Uninstall:

    1. 卸载客户端的挂载目录    
        umount 挂载点 
    2. 停止服务器端的共享 
        exportfs –au

Automatically mount

[root@centos ~]# vim /etc/fstab 
格式:
    <server>:</remote/export> </local/directory> nfs < options> 0 0 
    100.100.100.102:/share /sharenfs defaults 0 0 
    #100.100.100.102:/share /share                   nfs     defaults,vers=3 0 0(指定版本)
[root@centos ~]# mount –a 
exportfs command

After starting the NFS if we edited the / etc / exports, are you going to restart the nfs it? This time we can use the exportfs command to make the changes effective immediately, the command format is as follows:

格式:exportfs [-aruv] 
-a 全部挂载或卸载 /etc/exports中的内容  
-r 重新读取/etc/exports 中的信息 ,并同步更新/etc/exports、/var/lib/nfs/xtab 
-u 卸载单一目录(和-a一起使用为卸载所有/etc/exports文件中的目录) 
-v 在export的时候,将详细的信息输出到屏幕上。 

Specific examples:

# exportfs -au 卸载所有共享目录 
# exportfs -ra 重新共享所有目录并输出详细信息
rpcinfo command
rpcinfo -p 可以查看出RPC开启的端口所提供的程序有哪些,其中nfs 开启的是2049,portmapper(rpcbind) 开启的是111,其余则是rpc开启的

Guess you like

Origin www.cnblogs.com/hjnzs/p/12130989.html