Basic configuration and use of NFS services

Source: Internet
Author: User

First, installation
CentOS or RHL is installed by default, and if it is not installed, it can be installed via Yum:
Yum Install Nfs-utils
Yum Install Portmap

Ubuntu system, installed via Apt-get:

Apt-get Install Nfs-kernel-server

Second, the configuration
1. configuration file definition

The NFS configuration file is/etc/exports and the content format is as follows:
< shared directory > Client 1 (Options) [Client 2 (options) ...]

Shared directory: The directory that NFS shares to the client.

Client: A host in the network that can access this directory. Multiple clients are separated by a space.
Options: Set access permissions for the directory, user mappings, and more, with multiple options separated by commas.

For example:

/opt/public 192.168.1.0/24 (rw,insecure,sync,all_squash,anonuid= 65534,anongid=65534)


2, the client's designated way
Specify the IP address of the host: 192.168.0.100
Specify all hosts in the subnet: 192.168.0.0/24 or 192.168.0.0/255.255.255.0
Host of the specified domain name: nfs.test.com
Specify all hosts in the domain: *.test.com

All hosts: *

3. Option description
RO: Shared directory read only;

RW: The shared directory can be read and writable;
All_squash: All access users are mapped to anonymous users or user groups;
No_all_squash (default): The Access user first matches the native user, the match fails and then maps to the anonymous user or user group;

Root_squash (default): Maps the visiting root user to an anonymous user or user group;

No_root_squash: The root user has the root account privileges;

ANONUID=<UID>: Specifies the local user UID of the anonymous access user, which defaults to Nfsnobody (65534);
Anongid=<gid>: Specifies the local user group of the anonymous Access user GID, default is Nfsnobody (65534);

Secure (default): Restricts the client from connecting to the server only from TCP/IP ports less than 1024;

Insecure: Allow clients to connect to the server from TCP/IP ports greater than 1024;
Sync: It is inefficient to write data synchronously to memory buffer and disk, but it can guarantee the consistency of data;
Async: Save the data in the memory buffer first, and write to disk if necessary;
Wdelay (default): Check if there is a related write operation, if any, then perform these writes together, which can improve the efficiency;

No_wdelay: If a write operation is performed immediately, it should be used in conjunction with sync;
Subtree_check (default): If the output directory is a subdirectory, the NFS server will check the permissions of its parent directory;

No_subtree_check: Even if the output directory is a subdirectory, the NFS server does not check the permissions of its parent directory, which can improve efficiency;

Iii. NFS-related commands

1, Exportfs
To not restart the NFS Service app update, the following options are available:

-A all mount or unload content in/etc/exports
-R re-reads the information in/etc/exports and synchronizes updates/etc/exports,/var/lib/nfs/xtab
-U Uninstalls a single directory (used together with-A to unload directories in all/etc/exports files)
-V Exports detailed information to the screen at the time of export.

2, Nfsstat
View the running Status of NFS.

3, Rpcinfo

View the RPC service registration situation.

Related options:

-P Displays all port and program information.

Example:

Rpcinfo-p localhost #列出本机的RPC注册状况.


3, Showmount

To query NFS shared directory information, the following options are available:

-A displays directory information that is already on the client connection
-e IP or hostname display the directory shared by this IP address

Example:

SHOWMOUNT-E localhost #查询本机nfs共享目录情况

showmount-a localhost #查询本机共享目录连接情况


Iv. Linux Client Mount shared directory
1. Temporary mount
Mount via Mount, for example:

Mount-t NFS 192.168.1.1:/opt/public/mnt/public

2. Boot mount

To write mount information to the Fstab file

Vi/etc/fstab

192.168.1.1:/opt/public/mnt/public NFS Defaults

Save exit

Mount-a

3, based on AutoFS automatic mount

The autofs can be mounted automatically when used to mount the file system, and automatically unloaded when not in use for a long time, and the configuration is flexible and convenient.

Install AutoFS:

CENTOS,RHL:

Yum Install AutoFS

Ubuntu:

Apt-get Install AutoFS

Edit the main profile/etc/auto.master, and at the end add the directory information you want to mount.

The format is: Load profile name for native Mount home directory-mount parameter

Mounting parameters are mounted with mount parameters, and multiple parameters are separated by commas. The mount parameters here can be superimposed with the parameters defined in the corresponding load configuration file.

Example:

Vi/etc/auto.master

#本机挂载主目录为/mnt, the corresponding load configuration file is/etc/auto.nfs

/mnt/etc/auto.nfs

Save exit

Edit the Load profile to add the file system you want to mount.

Format: Mount directory-mount parameter mount file system

Mounting parameters are mounted with mount parameters, and multiple parameters are separated by commas.

Example:

Vi/etc/auto.nfs

Public-rw,bg,soft,rsize=32768,wsize=32768,nosuid,noexec,nodev 192.168.1.1:/opt/public

Save exit

Restart AutoFS

/etc/init.d/autofs restart

V. Windows client mount shared directory

1, to m$ website download sfu3.5,:http://www.microsoft.com/en-us/download/details.aspx?id=274

2. Create a group file locally, as follows:

root:x:0:

3, the local establishment of the passwd file, the contents are as follows:

Root:x:0:0:root:/root:/bin/bash

4, decompression and installation of SFU, select Custom installation, in the User Name mapping interface, select Password and group files, enter the next step into the previous established passwd and group file full path, click Next to complete the installation.

5, Configuration SFU

in the Start menu, locate Windows Services for UNIX in the program, click Services for UNIX administration. In theset interface Click on User Name Mapping, switch to maptabs,Click Show Group Maps, enter guests and root separately in the Windows group name and UNIX group name boxes, and then click Add. then click Show User Maps,in the Windows user name and UNIX user name boxes, enter guest and root, and then click Add. FinallyClick Apply app settings in the upper-right corner.


6. Make sure the Guest account is available in the Windows system

Run Gpedit.msc

In computer configuration->windowns settings->security settings->local Policies->user right Assignment- >deny access to this computer from the network: Remove Guest. and check if other related items have guest access allowed.

In computer configuration->windowns settings->security settings->local policies->Security Options->network access->sharing and security model for local accounts: Select Classic mode: Classic-local users authenticate as T Hemselves.

7. Map the network drive, CMD under mount (for example: Mount \\192.168.1.100\opt\public z:) or enter the address directly in the address bar (for example: \\192.168.1.100\opt\ public) to mount the shared directory.

VI. NFS permission settings
1, ordinary users

if (All_squash set) Then

The Access user forces the mapping to the specified NFS anonymous user;

Else

If (there is a user with the same name on NFS server) then

The Access user maps to a user with the same name on the server;

Else

Access user mapping into Nfsnobody;

2. Root

if (No_root_squash and All_squash are also set) then

Access user mappings for the specified NFS anonymous user;

Else

if (No_root_squash set) Then
The root mapping of the visiting root is the user on the specified server;
Else
if (All_squash set) Then
Access user mappings for the specified NFS anonymous user;
Else

Access user mapping into Nfsnobody;

Vii. related parameters of Mount

RO is loaded in read-only mode.
RW is loaded in read-write mode.

Sync performs the input and output actions of the file system in a synchronous manner.

Async performs the input and output actions of the file system in an asynchronous manner.
Defaults uses the default options. The default options are RW, suid, dev, exec, Anto Nouser, and async.

Atime Each access updates the Inode's access time, the default setting, and the Cancel option is noatime.

Noatime does not update inode access time for each access.
Dev readable character or block device on the filesystem, the Cancel option is Nodev.

Nodev does not read characters or block devices on the file system.
exec executable binary file, cancel option is noexec.

NOEXEC cannot execute binary file.

Auto must specify this option in the/etc/fstab file. When the-a parameter is executed, the device set to Auto is loaded and deselected as Noauto.
Noauto cannot use the-a parameter to load.

Suid start Set-user-identifier (set User ID) with Set-group-identifer (set group ID) Set bit, cancel option is nosuid.

Nosuid off Set-user-identifier (set User ID) with Set-group-identifer (set group ID) setting bit.

User normal users can perform load operations.
Nouser Normal user cannot perform load operation, default setting.
Remount Reload the device. Typically used to change the device's setting state.

Rsize read data buffer size, default setting of 1024.

Wsize Write data buffer size, default setting of 1024.

FG performs the mount operation in the previous form, the default setting. The normal operation response is affected when the mount fails.

BG performs a mount operation in the background form.

Hard rigid mount, default setting. If communication with the server fails, the operation that attempts to access it is blocked until the server recovers.
Soft soft mounted. If the server communication fails, the operation that attempts to access it fails, returning an error message. This feature is useful for avoiding process "hangs" on trivial installation operations.

RETRANS=N specifies the number of times a request is repeated before an error message is returned on a file system that is installed on a soft form.

NOINTR does not allow user interrupts, default settings.

INTR allows users to interrupt blocked operations (and have them return an error message).
Timeo=n sets the time-out period in one-tenth seconds for the request.

Note:

Automounter Special Parameters
Fstype= is used to specify the type of file system (if the file system being mounted is not NFS), mount is not available.


Eight, the matters needing attention
1, the NFS server shuts down to ensure that NFS does not have a client connection, otherwise it will not shut down properly. You can force the NFS service to stop or kill first.

2. The Windows client mount shared directory does not support UTF-8 encoding, so Chinese garbled characters may occur. can be resolved by modifying the default encoding for Server local.


Basic configuration and use of NFS services

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.