Linux Mount network folder (simple NFS configuration)

Source: Internet
Author: User

######################################## ###
### Attach a network folder ###
######################################## ###

NFS description
========
NFS is short for net file system, that is, Network File System.
NFS allows a system to share directories and files with its users on the network. By using NFS, users and programs can access files on the remote system just like accessing local files.

Why NFS is used
==================
Because yum is configured in the company and is ready to be released using Apache, it can be accessed through HTTP. Server A has an HTTP service, but the space is insufficient. Server B has enough space. Both A and B are Linux
Therefore, you are going to mount/Yum on B to/mnt/Yum on a through NFS.
Suppose a IP: 192.168.0.100
Assume that IP address B: 192.168.0.200

NFS usage Overview
==============
Server Requirements: // in the preceding example, B is the server.
Portmap start # service Portmap start
NFS start # service NFS start

Client Requirements: // in the preceding example, A is the server.
Portmap start # service Portmap start

Run the mount command on:
# Mount-t nfs 192.168.0.200:/Yum/mnt/Yum (note the colon after the host)

Specific NFS server configuration
==============================
1. Install software
Included software packages:
NFS requires 5 rpm, which are:
Setup-*: the shared NFS directory is defined in/etc/exports.
Initscripts-*: includes the BASIC script for loading the network directory during the boot process.
Nfs-utils-*: includes basic NFS commands and monitoring programs.
Portmap-*: supports secure connections to the nfs rpc service.
Quota-*: The Directory quota shared on the network, including rpc. rquotad (this package is not required)
// Check whether the required suite is installed.
# Rpm-Qa | NFS
# Rpm-Qa | Portmap
// You must start the Portmap service before starting the NFS service.
Nfs-utils includes rpc. nfsd and rpc. mountd
If the above software is installed, you can start to configure it.

2. Server Configuration

Services required for nfs startup:
Rpc. nfsd: Manages whether the client can log on to the host. It also includes the login ID identification.
Rpc. mountd: manages the NFS file system. After the client logs on to the host through rpc. nfsd
Rpc. rquotad: Disk Quota Management

# Vi/etc/exports

// Edit the file to add NFS shared content. If the file does not exist, add NFS shared content.
Main Parameters of exports:
RW: read/write permission
RO: Read-Only permission
No_root_squash: if the user logs on to the NFS host's shared directory is root, the user has root permission on the directory. Doing so
Unsafe. We recommend that you do not use it!
Root_squash: if the user who logs on to the NFS host's shared directory is root, its permissions will be compressed to anonymous users.
Its UID and GID will become the identity of the nobody SYSTEM account.
All_squash: regardless of the identity of the user logging on to the NFS host, its identity will be compressed into an anonymous user, usually the nobody
Anonuid: anonuid = xxx, which indicates the UID of anonymous users in the NFS server/etc/passwd.
Anongid: anonuid = xxx, which specifies the GID of anonymous users in the NFS server/etc/passwd.
Sync: Write and share data during requests
Async: NFS can respond to requests before writing data
Secure: NFS is sent through a secure port below 1024
Insecure: NFS is sent over port 1024
Hide: does not share subdirectories of the NFS Directory
No_hide: a subdirectory that shares the NFS Directory

Set instance:
/Home/Public 192.168.0. * (RW) * (RO)
// Allow users in the 192.168.0 CIDR block to have read and write permissions on/home/public, and other users to have read-only Permissions

/Home/test 192.168.0.100 (RW)
// Allow users with IP address 192.168.0.100 to access/home/test and have read and write permissions

/Home/Linux * .linux.org (RW, all_squash, anonuid = 40, anongid = 40)
// All users in the linux.org domain can access and read/write permissions. No matter which user you are, your identity is changed to uid = 40.
This account name

/Tmp * (RW, no_root_squash)
// Allow all users to have the read and write permissions on TMP. If the permission is root, the user has the root permission on the directory.

Start the service:
# Service Portmap start
# Service NFS start

3. Client settings
-- Start the Portmap service
# Service Portmap start

-- Mount the NFS shared directory on the client
# Mount-t nfs 172.17.196.10:/home/test/mnt/share

// Mount the shared directory/home/test on NFS to/mnt/share on the local machine (the/mnt/share directory must be created first)
After successful connection, the NFS test directory will be mounted to the local share.

4. debug monitoring
Check the NFS running status:
# Nfsstat
View RPC running information:
# Rpcinfo-P IP
# Rpcinfo-u hostname

Exportfs [-aruv]
-A: All mounting (or unmounting)/etc/exports File Settings
-R: Re-mount the/etc/exports setting. You can also synchronously update the/etc/exports setting.
-U: unmount a directory
-V: displays the shared directory on the screen at the time of export.

Remount the exports content on the NFS server (usually used when the exports are changed in time but you do not want to restart the machine)
# Exportfs-RV

Unmount all the Mount directories exportfs-Au, so that the original Mount directory is invisible on the NFS client.
# Exportfs-Au

The NFS server displays the client machine that has mounted the local NFS directory.
# Showmount-
All mount points on test:
172.17.196.11:/share

Show Mounted Directories
# Showmount-e 172.17.196.10
Export list for 172.17.196.10:
/Share 172.17.196.11

5. Problems
// User permissions do not match:
# Mount-t nfs 172.17.196.10:/home/test/mnt/share
Mount: 172.17.196.10:/home/test failed, reason given by server: Permission denied

// The Portmap service is not started.
# Mount-t nfs localhost:/home/test/home/nfs
Mount: RPC: Port Mapper failure-RPC: unable to receive
Or mount: RPC: program not registered

Note: If a client is connected, the NFS server cannot be shut down. You want to solve this problem. You need to disable the Portmap and NFS services before shutdown.

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.