Linux I have you also have-Shared platform NFS server build

Source: Internet
Author: User

Linux I have you also have-Shared platform NFS server build

Recently due to work needs, so you want to take a shared server for storage. Realize that you have a harmonious situation that I have shared with all of you. Thought of the Nfs-network File System. Next I'll talk about NFS and how it's built.

What is NFS 

Search engine which strong, have to ask degrees Niang (well, I admit that the technical question I asked is Google, here in order to rhyme, do not mind), degrees Niang is so to explain the NFS:

NFS is a shorthand for the network file system, which is the web filesystem. The network file system is one of the file systems supported by FreeBSD, also known as NFS. NFS allows a system to share directories and files with others on the network. By using NFS, users and programs can access files on the remote system as if they were accessing local files. NFS, a service that shares file systems over a network, is simple to build, but the biggest problem is "permissions." Because the client and server must have the same account to access certain directories or files. In addition, the start of NFS needs to be through the so-called Remote Procedure Call (RPC), that is, we do not just have to start NFS, but also need to start RPC this service is OK! This NFS server can let your PC to the network remote NFS Server share directory, mount to the local side of the machine, on the local side of the machine looks like, the remote host directory as if it is one of its own disk partition slot (partition)! Use the above quite convenient!

  

As shown above, when our NFS server is set up to share the/home/sharefile directory, other NFS clients can mount the directory to a mount point on their system (the mount point can be customized), such as the NFS in the preceding illustration Client 1 is not the same directory as the NFS client 2 mount. As long as I enter/home/data/sharefile in the NFS Client 1 system, I can see all the data in the/home/sharefile directory in the NFS server system (of course, the permissions are enough!). ^_^)! This/home/data/sharefile is like an NFS client 1 inside a partition of its own machine Oh! As long as the permissions are right, then you can use CP, CD, MV, RM ... Wait for disk or file related instructions! It's so convenient!

The software needed to build NFS

RPC Main program: Rpcbind

Our NFS can actually be regarded as an RPC service, and before starting any RPC service, we need to do a good job of port correspondence (mapping), this work is actually "rpcbind" this service is responsible for! In other words, before starting any RPC service, we need to start rpcbind!

NFS Main program: Nfs-utils

  is to provide RPC.NFSD and Rpc.mountd two NFS daemons and other related documents and documents, executable files and other software! This is the main software required for NFS services! There must be a Oh!

Because I use CentOS6.5, so the above two software have, do not have to install yourself, if you do not know there is wood, use the following instructions to see if there is this software:

1  grep NFS  #查询是否存在nfs2  grep rpcbind  #查询是否存在rpcbind

NFS Build

Next is the building, the most important is the simplest part, because just edit the configuration file /etc/exports, first start rpcbind (if it has been started, do not restart), and then start NFS, your NFS success! But can such a setting take effect on the client? Then you have to think about your ability to set permissions. Talk less, we will directly see the/etc/exports should be how to set it! Some distributions do not actively provide/etc/exports files, so please build them yourself manually. There are three ways to express this:

Method 1:

1 [[email protected] ~]# vim/etc/exports2 /tmp         192.168.  100.0/3 (RO)  [Share directory]   [Host (permissions)]  

Method 2:

1 [[email protected] ~]# vim/etc/exports2 /tmp            localhost (rw)   3 [Share directory]   [hostname (permissions)]     

Method 3:

1 [[email protected] ~]# vim/etc/exports2        /tmp * (RO,sync)3 [Share directory]   [wildcard means host (permissions)]    

The common parameters for the authority aspect (which is the parameter in parentheses) are:

Start server-side NFS

After the configuration file is done, of course, it starts to start! And we also mentioned earlier, the start of NFS also need rpcbind assistance! So hurry up and start it!

1[Email protected] ~]#/Service Rpcbind Start2 # If Rpcbind is already in the execution, then there is no need to start! 3 4[[Email protected] ~]# Service NFS Start5 # Sometimes some distributions may receive the following warning message:6Exportfs:/etc/exports [3]: No'Sync'Or'Async'option specified7  forExport"192.168.100.10:/home/test".8Assuming default behaviour ('Sync').9# The warning message above is only informed because we did not specifySyncor Async parameters,Ten# then NFS will use the defaultSyncof information. You can ignore him, or you can join/etc/.exports.  One  A[[Email protected] ~]# Service Nfslock start -[[Email protected] ~]# chkconfig rpcbind on -[[Email protected] ~]# chkconfig NFS on the[Email protected] ~]# chkconfig nfslock on

After your NFS server is set up, we can test the server to see if we can go online. is to use showmount this command to consult!

 1  [[email protected] ~]# showmount [-ae] [ hostname  | ip]  2   options and parameters:  3 -a: Displays the current status of NFS online sharing between host and client;  4 -E: Displays the/etc/exports.  5  6  # 1   7  [[email protected] ~]# showmount-e localhost  8  Export list for   localhost:  9 /tmp * 

It's simple! So, when you want to scan a host for NFS-shared directories, use SHOWMOUNT-E IP (or hostname)! It's very convenient! This is also the most common instruction for NFS client!

If the error, it is possible that the port is blocked by the firewall, can open the port, of course, the simple and brutal way is to turn off the firewall:

1 Service iptables stop

Or do not want to do it simply and rudely,

In general, services for NFS are only open to the internal domain and will not be open to the Internet. However, if you have special needs, you may also be able to cross different domains. However, the firewall for NFS is particularly difficult to engage in, why? Because in addition to the fixed port 111, 2049, there are many non-fixed port is opened by Rpc.mountd, Rpc.rquotad and other services, so your iptables is difficult to set rules! What do you do? Does the entire firewall mechanism have to be canceled?

To solve this problem, CentOS 6.x has a port configuration file that provides a fixed specific NFS service, which is/ETC/SYSCONFIG/NFS! You can specify a specific port in this file so that each time you start NFS, the port where the service starts will be fixed, so that we can set the correct firewall! This configuration file a lot of content, most of the data you do not change, as long as the PORT of the key word about the data can be. So what are the RPC services that need to be changed? There are mainly Mountd, Rquotad, nlockmgr these three, so you should change this:

1[Email protected] ~]# vim/etc/sysconfig/NFS2rquotad_port=1001<== about in -line around3lockd_tcpport=30001<== about in +line around4lockd_udpport=30001<== about in atline around5mountd_port=1002<== about in Aline around6 # Remember to set the left-most annotation service to take away, port value you can also decide at your own discretion. 7 8[Email protected] ~]#/etc/init.d/NFS Restart9[Email protected] ~]# Rpcinfo-p |grep-E'(Rquota|mount|nlock)'Ten     100011    2Udp1001Rquotad One     100011    2Tcp1001Rquotad A     100021    4Udp30001Nlockmgr -     100021    4Tcp30001Nlockmgr -     100005    3Udp1002Mountd the     100005    3Tcp1002Mountd

Then the corresponding port number is opened.

NFS Client Mount

How do you mount the file system provided by Server for NFS? Basically, you can do this:

    1. Confirm that the Rpcbind service has been started on the local side!
    2. Scan the NFS server for shared directories and see if we can use them (showmount);
    3. Establish a mount point directory (mkdir) that is expected to mount on the local side;
    4. Use mount to mount the remote host directly to the relevant directory.

For example, the client is on the 192.168.100.10 machine, and the server is 192.168.100.254, and the directory on the server is hung on the client.

1 192.168. 100.254 2  for 192.168. 100.254 : 3 /tmp         *

Next I want to mount the remote host's/home/public to the local host's/home/nfs/public, so I have to build this mount point directory on the local side host first! You can then mount the NFS file system directly with the Mount command!

1 mkdir -p/home/nfs/public2mount192.168. 100.254:/home/public/home/nfs/public

Then look at the mount situation:

1 DF 2 File system               1k-section      has been used with     available% mount point 3.... (omitted in the middle) .... 4 192.168. 100.254:/home/public5                        7104640    143104   6607104   3%/home/nfs/public

Do not want to mount the words you want to cancel use the following command:

1 Umount /home/nfs/public

Well, today's study ends, catch the train to go also ~

Linux I have you also have-Shared platform NFS server build

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.