NFS Service Setup

Source: Internet
Author: User

I. Introduction to NFS

1. What is NFS

NFS is the abbreviation for the network file system, which is the web filesystem. A contract for the decentralized file system, developed by Sun, was announced in 1984. The function is to enable different machines, different Unix-like operating systems to share individual data with each other, listen to the TCP and UDP Port 2049, let the application in the client through the network to access the data located on the server disk, is a way to implement disk file sharing among Unix-like systems.

The basic principle of NFS is to "allow different clients and services to share the same file system through a set of RPC", which is independent of the operating system, allowing different hardware and operating systems to share files together.

2. The Relationship between NFS and RPC

NFS relies on the RPC protocol during file transfer or information transfer. RPC, remote procedure invocation (Procedure call) is a mechanism that enables clients to perform programs in other systems, listening on port 111 on TCP/UDP. NFS itself does not provide the protocol and functionality for transmitting information, but NFS allows us to share information over the network, because NFS uses some other transport protocols. And these transport protocols are used for this RPC function. It can be said that NFS itself is a program that uses RPC. Or, NFS is also an RPC SERVER. So whenever you use NFS, start the RPC service first, whether it's NFS server or NFS CLIENT. This allows the server and client to implement the program port correspondence via RPC. You can understand the relationship between RPC and NFS: NFS is a file system, and RPC is responsible for the transmission of information.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/71/8A/wKiom1XTODSz5sa3AAGvhgKqJAg154.jpg "title=" Clipboard.png "alt=" Wkiom1xtodsz5sa3aagvhgkqjag154.jpg "/>

Second, build NFS

1. Introduction to the Environment


Client Ip System Installing the Software
server hpf-linux   192.168.1.8 centos 6.6 rpcbind,  , Nfs-utils
Client Webserver 192.168.1.20 CentOS 6.6 Rpcbind, nfs-utils


2. Installation Related software description

First, both the client and the server to install the Rpcbind, nfs-utils two software, to start the service should be aware of: before enabling NFS services must first enable the Rpcbind service, and then start the NFS service. This will cause NFS to not start properly. When shutting down the service, be aware that the Rpcbind service is turned off before the NFS service is turned off.

After you start the service, you can view the port that the server and Client NFS service listens on through the rpcinfo-p IP command, in addition to the RPC listener on port 111 and NFS listening on port 2049, the ports that the rest of the process listens on will change after restarting the service.

Services that start the client in the following order after the service is started by the service:

[[email protected] ~]#/etc/init.d/rpcbind start is starting rpcbind: [OK][[email protected] ~]#/etc/init.d/nfs s                        Tart Start NFS Service: [OK] start NFS mountd: [OK] start the NFS daemon: [OK] starting RPC IDMAPD: [OK]


3. NFS Service configuration file description

Before you say configure the service, the installation of the Nfs-utils package is a few important files:

/etc/exports The primary configuration file for the NFS service/USR/SBIN/EXPORTFS the management commands of the NFS service/usr/sbin/showmount client view commands/var/lib/nfs/etab Record the full set of permissions for NFS-shared Directories/var/lib/nfs/xtab log the client information that has been logged in

The NFS service configuration file is/etc/exports, which is the primary NFS configuration file, but the system does not have a default value, so this file does not necessarily exist, it may have to be created manually, and then write the configuration content in the file.

/etc/exports File Content format:

< shared directory > [Client 1 options (access rights, user mappings, others)] [Client 2 options (access rights, user mappings, others)]

A. Shared directory:

The output directory refers to the directory that the server in the NFS system needs to share with the client;

B. Client:

A client is a computer in the network that can access this NFS output directory

The client is commonly used in the specified manner:

Specify the IP address of the host: 192.168.0.20

Specify all hosts in the subnet: 192.168.0.0/24 192.168.0.0/255.255.255.0

Host of the specified domain name: www.example.com

Specify all hosts in the domain: *.example.com

All hosts: *

C. Options:

Options are used to set the output Directory access rights, user mappings, and so on, there are three main categories.

Access permission options:

Set output Directory read-only: RO

Set output directory Read/write: RW

User Mapping Options:

All_squash: Maps all normal users and groups that are accessed remotely to anonymous users or user groups (Nfsnobody);

No_all_squash: Reverse with All_squash (default setting);

Root_squash: The root user and the owning group are mapped to anonymous users or groups of users (default setting);

No_root_squash: In contrast to the Root_squash option, do not compress the root user, it is not recommended to turn on this option;

ANONUID=XXX: Maps All remote access users to anonymous users and specifies that the user is a local user (uid=xxx);

ANONGID=XXX: Maps All remote Access user groups to anonymous user group accounts and specifies that the anonymous user group account is a local user group account (GID=XXX);

Other options:

Secure: Restrict clients from connecting to Server for NFS (default setting) 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, write to disk if necessary, default to this mode;

Wdelay: Check if there is a related write operation, if any, then perform these writes together, which can improve the efficiency (default setting);

No_wdelay: If a write operation is performed immediately, it should be used in conjunction with sync;

Subtree: If the output directory is a subdirectory, the NFS server will check the permissions of its parent directory (default setting);

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

4. Configuration Service

In this case, add a virtual disk of size 5G, then format it to the/nfsdata directory, and then write the NFS configuration file on the server, with the following contents:

[Email protected] ~]# cat/etc/exports/nfsdata 192.168.0.0/16 (Rw,no_root_squash)

Since RPC and NFS services for both server and client have been started separately, the NFS service configuration file is reloaded after changing the NFS profile on the server side:

[Email protected] ~]#/etc/init.d/nfs Reload

After the server has loaded the NFS configuration file, you can use the Showmount command on the client to view the directories shared by NFS:

[[email protected] ~]# showmount-e 192.168.1.8Export list for 192.168.1.8:/nfsdata 192.168.0.0/16

The following is a description of the common options for the showmount command:

-A: Server-side execution, displaying all directories and sessions mounted on NFS servers;

-D: Server execution, showing only directories that have been loaded by NFS clients;

-E: The client executes and displays all shared directories on the NFS server.

Create a file on the server to test and mount the/nfsdata directory on the server to the client:

[[email protected] ~]# Touch/nfsdata/test.txt[[email protected] ~]# echo "1111111111111" >/nfsdata/test.txt[[email P Rotected] ~]# mount-t NFS 192.168.1.8:/nfsdata/mnt/data/[[email protected] ~]# cat/mnt/data/test.txt 1111111111111

5,the use of exportfs command

If we change/etc/exports after we start NFS, do we have to restart NFS? At this point we can use the EXPORTFS command to make the change take effect immediately, the command format is as follows:

# Exportfs [-aruv]

-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.

Specific examples:

# Exportfs-au Uninstall all shared directories

# EXPORTFS-RV re-share all directories and output detailed information

6. Automatic Mount NFS file system on boot

[[email protected] ~]# vim/etc/fstab//Add the following line at the end of the Fstab File 192.168.1.8:/nfsdata/mnt/data NFS Defaults , _netdev 0 0





This article is from the "Bread" blog, make sure to keep this source http://cuchadanfan.blog.51cto.com/9940284/1685716

NFS Service Setup

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.