Declared here: The experimental environment is Centos 6.5
NFS Server side: Nfs-utils
General default installation (if not installed: Yum install-y nfs-utils)
The main files generated are: (Can be viewed with RPM-QL nfs-utils)
/usr/sbin/rpc.mountd
/usr/sbin/rpc.nfsd
Start the service:
Service NFS Start
Note Before you start, make sure that Rpcbind starts (service rpcbind Start | Status
Rpcbind (formerly known as Portmap) works on 111/tcp 111/udp
View the corresponding port is also available
Rpcinfo-p localhost
After NFS is started, NFS registers a series of ports with RPC
NFS enables three sub-processes:
NFSD (primary service for NFS services)
MOUNTD (accepts client mount request)
Quotad (limit how much disk space the client can use locally-disk quotas)
Generally speaking:
The NFS port is activated when the RPC registry is mutable
NFSD monitoring in 2049/tcp 2049/udp This is immutable although it is registered to use.
But mounted and Quotad listen to the port is semi-random (RPC to help it select, RPC will choose a
Random ports that are not yet occupied for mounted and Quotad)
So it is possible to have ports that occupy other services such as Web 80.
Service script:
/etc/rc.d/init.d/nfslock file locking prevents simultaneous modification and prevents clients from crashing when accessing files.
The NFS request is locked when a file is accessed.
Okay, now, make sure that NFS is powered on from boot:
chkconfig NFS on (Can also Chkconfig--level NFS on Settings, Chkconfig--list | grep NFS View)
Configuration file to implement file output:
/etc/exports
In this file, each line contains a shared file system, and those clients can access, and the client's access characteristics, if there are multiple clients, separated by spaces, each client must follow (), which defines this client access attribute.
The format is:
/path/to/somedir Client list (Client Access attribute)
Such as:
/nfs_shared 128.1.1.5 (rw)
In this file, if you want to comment out a line, use #.
Here is the definition of the client: FQDN (i.e. domain name), IP address, IP address/mask
Let's talk about the client access properties:
ro (Read only, read files only)
RW (Read and write, can also be modified if the file is readable)
Sync (sync, changes to files are immediately written to disk)
Async (asynchronous, changes to files are not immediately written to disk, usually using async, not good synchronization performance)
Now start to operate: (the IP of the server is: 128.1.1.5 client IP: 128.1.1.7)
Make sure Iptables and SELinux are off before running
Assuming that the/nfs/shared directory has been created in advance on the server, the client creates the/nfs/mount1 directory
Modify/etc/exports
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/73/wKiom1V9CCqwxcoUAAB2i906UZk804.jpg "title=" 2.PNG " alt= "Wkiom1v9ccqwxcouaab2i906uzk804.jpg"/>
Remember to restart the service after you modify it:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/6F/wKioL1V9CfXzK_ldAAEQG5DbZvg518.jpg "title=" 3.PNG " alt= "Wkiol1v9cfxzk_ldaaeqg5dbzvg518.jpg"/>
To view the native exported directory:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/6F/wKioL1V9CiHhpPtdAABUNnrMItM794.jpg "title=" 4.PNG " alt= "Wkiol1v9cihhpptdaabunnrmitm794.jpg"/>
Here to say: Showmount is mainly used to view the local export to those directories, details please man showmount.
View the file systems exported by the NFS server
Usage:showmount-e nfs_server This command is available on the client side and on the server
such as: Showmount-e 128.1.1.7 (Here The 128.1.1.7 can also be written as:
128.1.1.7/255.255.255.0 or 128.1.1.7/24)
Mount the server-side exported directory on the client and use DF to see if it is already mounted (please create the client in advance
A directory/nfs/mount1)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/70/wKioL1V9DJfB6S-wAAI9-8SrXpE448.jpg "title=" 5.PNG " alt= "Wkiol1v9djfb6s-waai9-8srxpe448.jpg"/>
Here's how the client mounts:
Mount using the Mount command:
Usage:
mount-t NFS Nfs_server:/path/to/some_export/path/to/somewhere
Nfs_server:nfs server Address
/path/to/some_export:nfs Server Export Directory
/path/to/somewhere: Mount directory for clients
The mount directory can then be manipulated on the client side:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/70/wKioL1V9DuWgdF_JAABe0Dojk48437.jpg "title=" 6.PNG " alt= "Wkiol1v9duwgdf_jaabe0dojk48437.jpg"/>
If you want to implement write operations on the client, make sure that the server now has write access to the Mount directory.
such as chmod 777/nfs/shared
Now let's talk about the EXPORTFS command:
After modifying the/etc/exports configuration file, use the Exportfs command to mount without restarting the service.
Say the available options:
-A: Used in conjunction with the-R or-u option to mount all file systems again or to cancel exporting all files
System.
-R: Re-export
-U: Cancel Export
-V: Show more information
So exportfs-arv can be used to re-read/etc/exports
Exportfs-auv to cancel all exported directories
For example: Change 128.1.1.7 to 128.1.1.7/24 at this point all hosts in the 128.1.1.0/24 network segment can mount/nfs/shared
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/71/wKioL1V9MCviWdnjAACrG4GuYsA972.jpg "title=" 7.PNG " alt= "Wkiol1v9mcviwdnjaacrg4guysa972.jpg"/>
At this time, try to mount the directory on the host 128.1.1.3 and find that it can be mounted successfully
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/75/wKiom1V9L7PzmGYQAAG0Wesl6KA640.jpg "title=" 8.PNG " alt= "Wkiom1v9l7pzmgyqaag0wesl6ka640.jpg"/>
Test the EXPORTFS-AUV (the system did not export any directories after execution)
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/72/wKioL1V9MinBtJkkAABc5gPmPK8618.jpg "title=" 9.PNG " alt= "Wkiol1v9minbtjkkaabc5gpmpk8618.jpg"/>
If you want to implement the auto-mount when the client is powered on:
Please add the following line yourself in the/etc/fstab:
128.1.1.5/nfs/shared/mnt NFS Defaults , _rnetdev 0 0
Above the _rnetdev is to avoid the boot mount is not up, start not up.
If it does not uninstall after the client mounts:
Available Fuser-v mount directory to see which processes occupy this directory
fuser-km mount directory kills processes that are accessing a mount point
Let's talk about random port problems, if you don't want NFS to use random ports
Edit Profile /etc/sysconfig/nfs allows processes such as MOUNTD and Quotad to listen on a fixed port
rquotad_port=875
lockd_tcpport=32803
lockd_udpport=32769
mountd_port=892
All you need to do is turn on the 4 items above, or you can remove the 4
Installation and configuration of NFS services