NFS sharing configuration in Linux

Source: Internet
Author: User

Network File System (NFS) is a mechanism for attaching partitions (directories) on remote hosts to local systems through the network, with support for the network file system, you can operate on the shared partition (directory) of the remote host on the local system just like operating on the local partition.

1. First, check whether NFS is installed (Portmap is used for RPC transmission)

[Root @ localhost etc] # rpm-Q nfs-utils Portmap

Nfs-utils-1.0.9-16.el5

Portmap-4.0-65.2.2.1

II,Configuration
1. Configuration File. Modify the/etc/exports file and add the shared directory/xen (Save the domainu image in this directory ).
# Vi/etc/exports
Configuration instance:
/Xen * (RW, sync, no_root_squash)

The meanings of parameters in parentheses are described as follows:

RW: read/write permission. the read-only permission parameter is Ro;

Sync: data is written to the memory and hard disk synchronously. You can also use async. Data is saved in the memory before being written to the hard disk immediately.

No_root_squash: attributes of the NFS server shared directory user. If the user is root, the shared directory has root permissions.

Iii. Maintain NFS
Format:
Exportfs option Parameters
-A: output all directories set in/etc/exports.
-R: re-read the settings in the/etc/exports file and take effect immediately without restarting the NFS service.
-U: Stop outputting a directory.
-V: displays the directory on the screen when outputting the directory.
1. After modifying VI/etc/exports, you do not need to restart the service and directly use the command to output the shared directory.
# Exportfs-RV
2. Stop outputting all shared directories
# Exportfs-AUV

 

4. Start and Stop the NFS service
1. Start the NFS service
To ensure that NFS works properly, you need to start the Portmap and NFS directories, and Portmap must be started before NFS.
#/Etc/init. d/Portmap start // or service Portmap start
#/Etc/init. d/nfs start // service NFS start

[Root @ localhost etc] # service Portmap start

Start Portmap: [OK]

[Root @ localhost etc] # service NFS start

Start the NFS service: [OK]

Disable NFS quota: [OK]

Start the NFS daemon: [OK]

Start NFS mountd: [OK]
2. Stop the NFS service.
Before stopping the NFS server, stop the NFS service and then stop the Portmap service. If other services in the system require Portmap, you do not need to stop the Portmap service.
/Etc/init. d/nfs stop
/Etc/init. d/Portmap stop
3. Self-starting NFS service
Chkconfig -- level 35 Portmap on
Chkconfig -- level 35 NFS on
V. Test
1. Check the options used in the output directory.
In the/etc/exports configuration file, even if only one or two options are set, many other options are included in the output directory. By viewing the/var/lib/nfs/etab file, you can see what options are used in the real output directory.
2. Use showmount to test the NFS output directory status
Format:
Showmount parameter option NFS server name or address
-A: displays all client hosts of the specified NFS server and Their Connected Directories.
-D: displays all shared directories connected by clients on the specified NFS server.
-E: displays all output shared directories on the specified NFS server.
(1) view shared directories of all outputs
# Showmount-e

 

[Root @ localhost etc] # exportfs-

[Root @ localhost etc] # showmount-e 127.0.0.1

Export list for 127.0.0.1:

/Xen *

(2) display all mounted output Directories
# Showmount-d

The above is the server configuration.

 

 

Vi. NFS client Configuration
1. View NFS server information
On the client, you can run the showmount command to view the shared directories on the NFS server.
# Showmount-e192.168.0.51
If an error is reported, first check whether the NFS and Portmap services on the server are enabled. Check whether it is blocked by the firewall.
2. Mount the shared directory on the NFS server
# Mount-t nfs 192.168.0.51:/xen/mnt/
-T: Specifies the file type of the mounted device (NFS is a Network File System)
192.168.0.51: IP address of the NFS server
/Home/test: shared directory of the NFS server
/Mnt/: local directory
3. Uninstall NFS
You can run the umount command to uninstall the NFS directory.
Note: When a client is connecting to the NFS server and wants to shut down the NFS server, you should first turn off the Portmap and NFS services. Otherwise, it will take a long time to shut down. If you cannot disable Portmap and NFS, kill the process. You can also stop all output directories on the current host by using the exportmap-auw command and then shut down the system.
 
4. automatically connect to the NFS server at startup
To automatically connect to the shared directory on the NFS server at startup, edit the/etc/fstab file. Add
192.168.0.51:/home/test/mnt NFS ults 0 0
192.168.0.51:/home/test: shared directory of the NFS server
/Mnt: Local Mount directory

 

 

 

 

 

My specific operations are as follows:

Remember,

1) After the server is configured, disable the server firewall: Service iptables stop.

2) When using showmount, remember to disable the firewall of the Client: Service iptables stop.

3) Enable the NFS service on both the client and server. Service Portmap start and service NFS start

 

 

The operations on the client are as follows:
Last login: Fri Apr 12 15:46:47 2013 from 172.21.5.93
[Root @ localhost ~] # Showmount-e 172.21.5.49
Mount clntudp_create: RPC: Port Mapper failure-RPC: unable to receive
[Root @ localhost ~] # Rpm-Q nfs-utils Portmap
Nfs-utils-1.0.9-16.el5
Portmap-4.0-65.2.2.1
[Root @ localhost ~] # Service iptables stop
Clear firewall rules: [OK]
Set chains to accept policy: Filter [OK]
Uninstalling the iiptables module: [OK]
[Root @ localhost ~] # Service Portmap start
Start Portmap: [OK]
[Root @ localhost ~] # Service NFS start
Start the NFS service: [OK]
Disable NFS quota: [OK]
Start the NFS daemon: [OK]
Start NFS mountd: [OK]
[Root @ localhost ~] # Showmount-e 172.21.5.49
Mount clntudp_create: RPC: Port Mapper failure-RPC: unable to receive
[Root @ localhost ~] # Mount-t nfs 172.21.5.49:/xen/mnt/
Mount: Mount to NFS server '2017. 21.5.49 'failed: system error: No route to host.
[Root @ localhost ~] #
[Root @ localhost ~] # Showmount-e 172.21.5.49
Export list for 172.21.5.49:
/Xen *
[Root @ localhost ~] #

[Root @ localhost ~] #
[Root @ localhost ~] # Mount-t nfs 172.21.5.49:/xen/mnt/
[Root @ localhost ~] #

 

 

The server side is as follows:

[Root @ localhost ~] # Showmount-e 127.0.0.1
Export list for 127.0.0.1:
/Xen *
[Root @ localhost ~] # Service iptables stop
Clear firewall rules: [OK]
Set chains to accept policy: Filter [OK]
Uninstalling the iiptables module: [OK]
[Root @ localhost ~] #
[Root @ localhost ~] #

 

 

View on the client:

[Root @ localhost ~] # Cd/mnt
[Root @ localhost MNT] # ls-l
Total 20500048
-Rwxr-XR-x 1 Root 7340032000 04-12 17:35 dom1024
-Rwxr-XR-x 1 Root 5242880000 03-05 22:31 dom256
-Rwxr-XR-x 1 Root 8388608000 03-27 dom512

 

 

3) then use DF-H
Check whether the mounting is successful.

[Root @ localhost xen] # DF-H

File System
Capacity in use available %
Mount point

/Dev/mapper/VolGroup00-LogVol00

71 GB 43G 24g 65%/

/Dev/hda1 99 m 25 m 70 m 26%/boot

Tmpfs 706 M 0 706 M 0%/dev/SHM

172.21.5.49:/xen 143g 28g 109g 21%/mnt

[Root @ localhost xen] #

 

Note: common parameters of the CP command during copy
CP-a-V/mnt/home/
-A this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of DPR options.
-V or-verbose displays the command execution process.
-V <backup mode> or-version-control = <backup mode> use the "-B" parameter to back up the target file. A backup string is added at the end of the backup file, this string can be changed not only by the "-s" parameter, but also by using the "-V" parameter to specify different backup methods.
-I and F options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is Y, the target file will be overwritten, which is an interactive copy.

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.