The configuration content of Linux NFS is not very difficult in general. In many system settings, this configuration is very regular. We know that for NFS (Network File System, Network File System), we can share different hosts (different OS) over the Network) directory-you can mount the remote host directory through NFS to access this directory just like accessing the local directory! Generally, nfs can be used to easily share unix-like systems. However, to share unix-like systems with windows systems, samba must be used! Linux NFS runs on the basis of SUN's Remote Procedure Call (Remote Procedure Call). RPC defines a system-independent method for inter-process communication. therefore, the NFS Server can also be viewed as an RPC server.
Because NFS is an RPC service program, you must map the port before using it-set it through portmap. for example, when an NFS client initiates an NFS service request, it must first obtain a port ). therefore, it first obtains the port number through portmap. (not only NFS, but portmap needs to be set before all RPC service programs start)
Linux NFS-related files and commands
1,/etc/exports
The access to the NFS volume is approved by exports, which enumerate several hostnames that have the right to access the file system on the NFS server.
2,/sbin/exportfs
Maintain NFS Resource Sharing. You can reset the shared directory of/etc/exports, unmount the shared directory of NFS Server, or share it again.
3,/usr/sbin/showmount
It is used on the NFS Server, while showmount is mainly used on the Client. showmount can be used to view NFS shared directory resources.
4,/var/lib/nfs/xtab
NFS record document: You can view which clients are connected to the NFS host.
The following are not directly responsible for NFS. In fact, they are responsible for all RPC
5,/etc/default/portmap
In fact, portmap maps all the RPC service ports. Its content is very simple (detailed later)
6,/etc/hosts. deny
Set the host to reject the portmap service
7,/etc/hosts. allow
Set the host that allows the portmap service
Install Linux NFS
By default, the NFS server is not installed on Debian/Ubuntu. First, install the NFS service program:
$ Sudo apt-get install nfs-kernel-server
(When nfs-kernel-server is installed, apt will automatically install nfs-common and portmap)
In this way, the host is equivalent to the NFS Server.
Similarly, if the target system is an NFS client, you must install the NFS client program. If it is a Debian/Ubuntu system, you must install nfs-common.
$ Sudo apt-get install nfs-commmon
Both nfs-common and nfs-kernel-server depend on portmap!
Configure Linux NFS
Configure portmap
Method 1: edit/etc/default/portmap and remove-I 127.0.0.1.
Method 2: $ sudo dpkg-reconfigure portmap, shocould portmap be bound to the loopback address? Select N.
Configure/etc/hosts. deny
Disable any host) to connect to your NFS server.) Add:
- ###NFSDAEMONS
- portmap:ALL
- lockd:ALL
- mountd:ALL
- rquotad:ALL
- statd:ALL
Configure/etc/hosts. allow
Allow the hosts you want to establish connections with your NFS server. the following steps allow a host starting with 192.168.2 to be connected to an NFS server.) You can also specify a specific IP address. see hosts_access (5) and hosts_options (5) on the man page ). join:
- ###NFSDAEMONS
- portmap: 192.168.2.
- lockd: 192.168.2.
- rquotad: 192.168.2.
- mountd: 192.168.2.
- statd: 192.168.2.
/Etc/hosts. deny and/etc/hosts. allow sets the access to portmap. using these two configuration files is a bit similar to "mask. now/etc/hosts. deny prohibits all users from accessing portmap. then in/etc/hosts. some users are allowed to access portmap in allow.
Run $ sudo/etc/init. d/portmap restart to restart portmap daemon.
Configure/etc/exports
The Linux NFS mount directory and permissions are defined by the/etc/exports file.
For example, to share the IP address of 192.168.2. * In the/home/zp/share directory of my home directory, add the following statement at the end of the file:
/Home/zp/share 192.168.2. * (rw, sync, no_root_squash)
Or:/home/zp/share 192.168.2.0/24 (rw, sync, no_root_squash)
192.168.2. * The NFS client in the network segment can share the contents of the NFS server/home/zp/share directory. the user has the read and write permissions, and the user's identity after entering the/home/zp/share directory is root. It is best to add sync. Otherwise, a warning will be given when $ sudo exportfs-r is used. sync is the default option of NFS.
(Run $ showmount-e to view the NFS server's export list.
If/etc/exports is changed, run $ sudo exportfs-r update.
Run $ sudo/etc/init. d/nfs-kernel-server restart to restart the nfs service)
/Etc/exports is actually the core configuration file of the nfs server.
Test Linux NFS
Try mounting the local disk (assuming the IP address of the local host is 192.128.2.1, Mount/home/zp/share to/mnt)
$ Sudo mount 192.168.2.1:/home/zp/share/mnt
Run $ df to check the result
$ Sudo umount/mnt
Pay attention to the read and write permissions of the Copied object!
In addition, some parameters can be used:
Add parameters: mount-o nolock, rsize = 1024, wsize = 1024, timeo = 15 192.168.2.130:/tmp // tmp/