NFS is the abbreviation for the network file system, which is the web filesystem. A contract for the decentralized file system, developed by Sun, was announced in 1984. The function is to enable different machines, different operating systems to share individual data with each other, so that the application can access the data on the server disk through the network, and it is a way to implement disk file sharing among Unix-like systems.
Application Scenarios:
In the production environment, a system due to the changes in the architecture, the original single node expansion into two nodes, the front end of the use of Nginx to do the load of the architecture, and these two nodes need a public storage to store user uploaded pictures, the user's concurrency is not high, and then because the original business module from the Nginx host stripped out, On the original Nginx host has "IMG" This storage image directory, so consider installing the NFS service on the Nginx host, and then mount the "IMG" directory on the same point on the two nodes to achieve the cluster node access to the picture directory. The installation of the NFS service is relatively simple, but in the production environment should be verified in their own test environment, here the installation process is recorded as follows:
System environment: CentOS 6.4 x86_64
Server 3:10, 12 (client); 21 (service side)
1. Check if the system is turned on for NFS service: Service NFS Status results show nfs:unrecognized service, stating that the system does not have NFS services installed, note that Yum Install NFS is not installed and should be run with Yum Nfs-utils.
2, open Portmap Services, or unrecognized service, installation, yum install Portmap, Baidu +google, found that CentOS 6.4 Portmap has been replaced by Rpcbind, So continue to install, did not, check is not already installed in the Nfs-utils package when installed, service Rpcbind status, sure enough has been installed.
The above is the entire installation process, the summary is the CentOS 6.x system after a command yum install nfs-utils all done, Looks like the 5.x version can also be done with this command, can not make it possible to install Portmap, the main 6.x version of the thing Rpcbind, 5.x version with the Portmap.
Here is the startup process:
1. Configure the/etc/exports file first
Vi/etc/exports;
Then enter/opt/pic:192.168.1.1/255.255.255.0 (Rw,sync,no_root_squash,no_all_squash)
Save exit
2. Start Rpcbind Services service Rpcbind start
3. Start NFS Service Services NFS Start
SHOWMOUNT-E 192.168.1.21 outputs the following results:
Export list for 192.168.1.21:
/opt/pic 192.168.1.1/255.255.255.0
Description Successful start (note: After the CentOS 6.x version showmount-e must specify the IP, otherwise it will be stuck there, there is no output, 5.x version can not be specified)
The following is the directory that mounts NFS to the specified machine
SSH login to a machine b:ssh [email protected]
Mount-t NFS 192.168.1.21:/opt/pic/opt/pic
Set up the file Test.txt on the a machine, and then found that the B machine has the same file, the NFS server and the client are in sync.
The operation is not too difficult, but there are also some minor problems and precautions in the middle, here also talk about
1./etc/exports File Content format:
< output directory > [Client 1 options (access rights, user mappings, others)] [Client 2 options (access rights, user mappings, others)]
2. Insecure use this parameter when the Mount listener port is greater than 1024
3. Permissions configuration Parameters
RW Read-write, can read and write;
Sync: The file is written to both the hard disk and memory;
Async: Files are staged in memory instead of directly to memory;
No_root_squash:nfs the client connects to the server, if root is used, it also has root access to the directory shared by the server. Obviously it's not safe to turn it on.
4. Reload the/etc/exports configuration:
[Email protected] ~]# Exportfs-r
5. Client Configuration
In the client only need to install the nfs-client end, if there is no client terminal program, directly installed Nfs-utils
6. Set access permissions as needed
[[Email protected] ~] #vi/etc/hosts.allow
[[Email protected] ~] #vi/etc/hosts.deny
7. Mount Format:
MOUNT–T NFS hostname (or IP):/directory/mount Point
Unloading:
Umount/Local mount directory (local client offload method, but uninstall with Exports–au for server)
To set up automatic mounts:
On the server side: Chkconfig--add Rpcbind&&nfs
On the client: open/etc/fstab and add the following information on the last line:
192.168.1.21:/usr/pic/opt/pic NFS Defaults 0 0
8. View Shared
Showmount–e IP (see those directories shared on Server for NFS)
Showmount–a IP (for NFS server, displays the client (client) that has already been mount on the native NFS server)
Today encountered an NFS mount error problem with the following error message:
Mount:wrong fs type, bad option, bad superblock on * * *,
Missing codepage or helper program, or other error
(for several filesystems (e.g. NFS, CIFS) might
Need a/sbin/mount.<type> Helper Program)
In some cases useful info are found in Syslog-try
DMESG | Tail or so
According to the error prompt, view the/sbin/mount.<type> file, sure enough to find no/sbin/mount.nfs files, install nfs-utils can
Workaround: Yum Install Nfs-utils
After installation, there are two more mount files under/sbin/, respectively, Mount.nfs and MOUNT.NFS4:
[Email protected] data]# ll/sbin/mount*
-rwsr-xr-x. 1 root root 123776 November 2013/sbin/mount.nfs
lrwxrwxrwx. 1 root root 9 June 9 13:41/sbin/mount.nfs4-Mount.nfs
-rwxr-xr-x. 1 root root 1338 February 2013/sbin/mount.tmpfs
Workaround for "Access denied by server while mounting" appears when NFS shared service is mounted
Modify the/etc/sysconfig/nfs file to
# Turn off V2 and V3 protocol support
# rpcnfsdargs= "-N 2-n 3"
# Turn off V4 protocol support
#RPCNFSDARGS = "-N 4"/* Remove the # of this sentence */
NFS is divided into three versions, the NFS-2 NFS-3 NFS-4, which, by default, turns off the three NFS versions, and we only need to open NFS-4.
Last but not the other way, NFS allows users to access shared files on the network as if they were accessing local files. NFS is a successful file-sharing approach, but its biggest problem is that it is less suited to large decentralized systems. So a large number of users upload file storage should use what file system, it seems fastdfs good, and similar to the mogilefs and so on
This article is from the "ISKORPITX" blog, make sure to keep this source http://chinaxin.blog.51cto.com/1109725/1881488
Centos 6 Server for NFS and related problem solving