Linux Configuration NFS Service

Source: Internet
Author: User



Brief introduction:

The Unix/linux system is a remote file folder sharing service that can share a remote file folder locally and operate the remote folder as if it were a local file.

For example: A host as a server, shared out test1 This folder, B host as client,b in its Test2 folder mount a host Test1 folder, then this time to view the contents of the test2 of Host B will be the same as the test1 of a host, The operation of the B host Test2 folder is to operate the Test1 folder of host a (add and revise the check, of course, to set sufficient permissions).



Note: When I configure, because there is only one Linux host, so here the server and client are on a machine, readers can not pay attention to.


"Service Side"

---------------------------------------------------


First, the installation of NFSServer check whether the Linux system has installed the Nfs-utils and Portmap two packages (the RHEL4 system has installed the two packages by default).
Log in to the Linux system as root and run the command to see if the NFS service is installed
Command:
-----------------------------------------
# rpm-q Portmap
# Rpm-qa | grep NFS


Assuming that the installation displays the version number information
-----------------------------------------


Second, the start-up service assumes that the server is not started, the service is turned on (NFS is not fully enabled under the default service)
Note: When starting, Portmap must be started first, when off, Portmap must be closed after
Start command:
-----------------------------------------
# service Portmap start//restart reboot
# Service NFS Start
Restart restart
-----------------------------------------
--Assuming the boot is complete will show OK



Third, check that the RPC program is started because NFS uses the files on the remote computer through the RPC (Remote Procedure Call) protocol, the RPC service in the system must start.
Command:
-----------------------------------------
# Rpcinfo | More
# Rpcinfo-p | More
-----------------------------------------
-assuming success can be seen
--proto Port
--TCP 111
--UDP 111



Four, set the folder to be shared (1), ready to share the folder, for example, the server wants to share the file system under the/java/tomcat1 folder.
Create a new/JAVA/TOMCAT1 folder under the file system
Command:
-----------------------------------------
# Mkdir/java
# MKDIR/JAVA/TOMCAT1


Then create a new 2 directory in the TOMCAT1, which will allow you to see the results after a successful configuration (and also directly manually).
# MKDIR/JAVA/TOMCAT1/T1
# MKDIR/JAVA/TOMCAT1/T2
# MKDIR/JAVA/TOMCAT1/T3
-----------------------------------------
--so you can see that there are 3 folders under the/JAVA/TOMCAT1 folder

(2), set the folder to be shared
Locate the file system under the/etc/exports file, open the edit join for example the following, format such as the following:
-----------------------------------------------------------
/JAVA/TOMCAT1 192.168.56.101 (Rw,sync,no_root_squash)
-----------------------------------------------------------
What this means: 192.168.56.101 This host is able to access my machine/JAVA/TOMCAT1 This folder with this privilege (Rw,sync,no_root_squash)
--then save the exit.
IP:192.168.56.101 is the IP of the Linux system in my virtual machine, and I can view this IP on the linux command line through Ifconfig



Explanation of the parameters configuration:
/java/tomcat1 --the folder name to be shared
Accessible host Address --192.168.56.101
The "Client host Address" field in the exports file can be used to represent the host address in multiple forms
192.168.152.13 hosts that specify IP addresses
Nfsclient.test.com the host for the specified domain name
192.168.1.0/24 all hosts in the specified network segment
*.test.com all hosts under the specified domain
* All hosts
(Rw,sync,no_root_squash)--access permissions
RW: Read/write permission, cannot be used in conjunction with RO
RO: Read Only permission, and RW cannot use together
Sync: Data is written to memory and hard disk, so it is not easy to lose data, it is recommended that all NFS Shared folders use this option.
You can also use async, where data is staged in memory and not immediately written to the hard disk.
No_root_squash:nfs Server shared folder user's properties, assuming that the user is root, then for this shared folder will have root permissions.


(3), again output shared folder format
Configuration file changed/etc/exports need to output the shared folder format again (or restart the service manually)
Once again, export the shared folder format command:
--------------------------------
Exportfs-rv
--------------------------------
--can see the information from the new output after running



(4), display the list of output folders shared in the host
Command:
--------------------------------
# SHOWMOUNT-E (Nfsserverip address)
--------------------------------
--Assuming that IP is not written, the list of output folders in the current host is displayed by default.
--I write my address directly here 192.168.56.101, also can not write.
--run this command to see the/JAVA/TOMCAT1 in the input folder, and have access to the appropriate information.






"Client"
---------------------------------------------------


V. Mount NFS
It's also the equivalent of setting up a shared folder that was previously set up to mount a single host.
Generally in the client's machine operation, I have only one Linux here, so directly here to operate, can achieve the same purpose.

(1), create mount point
Command:
---------------------------------
# MKDIR/JAVA/TOMCAT2
---------------------------------
This means that to mount the remote address to a local folder, I will create a new folder directly as a mount point.


(2), run mount command:
--------------------------------------------
# Mount 192.168.56.101:/java/tomcat1/java/tomcat2
--------------------------------------------
--Format: Mount NFSServer Address:/shared folder/mount point
--run successfully without display information


(3) To view shared Folders for NFS mounts
Command:
----------------------------------------
# df-h
----------------------------------------
--By viewing the command to see which remote addresses are attached to the shared folder, mounted on that mount point, respectively.
--assuming that you see 192.168.56.101 below the/JAVA/TOMCAT1 is attached to the/JAVA/TOMCAT2 on the machine proved successful.



(4), see if the information under the Mount folder is consistent with the remote folder
Command
----------------------------------------
# LS/JAVA/TOMCAT2
----------------------------------------
--assuming that there are t1,t2,t3 three folders under the folder is correct. Note: T1,T2,T3 is the content in the shared folder/java/tomcat1, which shows that the sharing was successful.
--also be able to delete a directory in TOMCAT1 or TOMCAT2 to see if the other directory has changed to prove that the mount is correct.


(5), unload mount point
Command:
----------------------------------------
# UMOUNT/JAVA/TOMCAT2
----------------------------------------
--Through this command can be canceled/JAVA/TOMCAT2 This mount point, run the command after the new view/JAVA/TOMCAT2 content found, there is no t1,t2,t3 and other content.
--note that when uninstalling the "drive letter" must not be removed from the current folder, that is, you cannot uninstall the/JAVA/TOMCAT2 in the/java/tomcat2 folder, be sure to exit.



Six, set the boot itself actively mount NFS shares
Write/etc/fstab configuration file

Format:
NFS Shared Address:/shared folder native mount point file system permissions whether the detection sequence

Demo Sample:

192.168.56.101:/JAVA/TOMCAT1/JAVA/TOMCAT2 NFS RW 0 0




References: HTTP://HI.BAIDU.COM/GUOQS/ITEM/8057C927E5800E889C63D1BC


Related Article

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.