Installation and configuration of Linux Server for NFS

Source: Internet
Author: User
Tags nfsd

I. Introduction TO Services for 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 operating systems to share individual data with each other, so that the application can access the data on the server disk through the network, and it 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.

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. 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, you start the RPC service, 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 transfer of information.

Second, the system environment

System platform: CentOS release 5.6 (Final)

NFS Server ip:192.168.1.108

The firewall is turned off/iptables:firewall is not running.

Selinux=disabled

III. Installation of NFS Services

The installation of NFS is very simple, requires only two packages, and is normally installed as the default package for the system.

    • nfs-utils-*: Includes basic NFS commands and monitoring programs

    • portmap-*: Support for secure NFS RPC Service connections

1. See if the System has NFS installed

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03130851-304eb5e6adeb482588dc653bf24a97a9.jpg "/>

The system has nfs-utils Portmap two packages installed by default.

2. If the software package required for NFS is not installed on the current system, it needs to be installed manually. The installation files for the nfs-utils and Portmap two packages will be available on the system CD.

# mount/dev/cdrom/mnt/cdrom/# cd/mnt/cdrom/centos/# rpm-ivh portmap-4.0-65.2.2.1.i386.rpm # RPM-IVH Nfs-utils-1.0.9-5 0.el5.i386.rpm# rpm-q nfs-utils Portmap

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03131853- D5136c3e80d64c68a835c524f94e77bf.jpg "/>

Iv. NFS System Daemon

    • NFSD: It is the basic NFS daemon, the main function is to manage whether the client can log on to the server;

    • Mountd: It is the RPC installation daemon, and the primary function is to manage the NFS file system. After the client has successfully logged on to the NFS server through NFSD, it must also authenticate with the file usage permissions before using the files provided by the NFS service. It reads the NFS configuration file/etc/exports to compare client permissions.

    • Portmap: The main function is to do port mapping work. When a client attempts to connect and use a service provided by the RPC server, such as an NFS service, PORTMAP provides the managed port to the client, which enables the client to request services from the server through that port.

V. Configuration of Server for NFS

Server for NFS is relatively simple to configure, just set it up in the appropriate configuration file, and then start Server for NFS.

Common Directories for NFS

/etc/exports Primary configuration file for NFS services

/USR/SBIN/EXPORTFS Management commands for NFS services

View commands for/usr/sbin/showmount clients

/var/lib/nfs/etab record full permission SetPoint for NFS-shared directory

/var/lib/nfs/xtab Logging of client information that has been logged on

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 be created manually using Vim, and then write the configuration content in the file.

/etc/exports File Content format:

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

A. Output directory:

The output directory is the directory that 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

Common ways for clients to specify

    • Specify the IP address of the host: 192.168.0.200

    • 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: david.bsmart.cn

    • Specify all hosts in the domain: *.bsmart.cn

    • All hosts: *

C. Options:

option to set the access permissions, user mappings, and so on for the output directory.

There are 3 main types of NFS options:

Access Permissions 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: Reverse with Rootsquash;

    • 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, and write to disk if necessary;

    • 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;

Vi. start and stop of Server for NFS

After you have configured the exports file correctly, you can start the NFS server.

1. Start the NFS server

In order for the NFS server to work properly, you need to start Portmap and NFS two services, and Portmap must start before NFS.

# Service Portmap start# Service NFS Start

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03134917-66ac8d9fab48490ba4167158c78eb3a9.jpg "/>

2. Querying Server Status for NFS

# Service Portmap status# Service NFS Status

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03135229- C2cf7d9dd6c0464fb9fcd494362a5adc.jpg "/>

3. Stop Server for NFS

To stop the NFS runtime, you need to stop the NFS service before stopping the Portmap service, and you do not need to stop the Portmap service if there are other services in the system (such as NIS) that you need to use

# Service NFS stop# service Portmap stop

4. Set the auto-start Status for NFS server

For the actual application system, it is unrealistic to manually start the NFS server after each boot of the Linux system, and it is necessary to set the system to automatically start the Portmap and NFS services at the specified runlevel.

# chkconfig--list portmap# Chkconfig--list NFS

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03140300-180710ca746b49eb914e8ace20add0e9.jpg "/>

Set Portmap and NFS services to start automatically at System run level 3 and 5.

# chkconfig--level portmap on# chkconfig--level NFS on

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03140345-54a300b91d8f41f2828273b18a4e710f.jpg "/>

Vii. examples

1, the NFS Server/home/david/share to the 192.168.1.0/24 network segment, permissions read and write.

Server-side files are detailed as follows:

650) this.width=650, "width=", "src=" http://images.cnitblog.com/blog/370046/201301/ 03150753-5df6a22cd90144ec82e5cbaf5b327ad6.jpg "/>

# Vi/etc/exports

/home/david 192.168.1.0/24 (rw)

2. Restart Portmap and NFS Services

# Service Portmap restart# service NFS restart# Exportfs

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03143637- Fbd4598e947b47f88ea87fb68c4702f9.jpg "/>

3, server side use the showmount command to query the sharing status of NFS

# SHOWMOUNT-E//default view of their shared services, provided that the DNS can resolve their own, otherwise prone to error

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03145702-57ec12d12a5a4806baf3915b6c6a018f.jpg "/>

# SHOWMOUNT-A//Displays directory information that has been connected to the client

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03160137- Aa3ad1df4d9a485d8b51d29e8e3af438.jpg "/>

4. The client uses the Showmount command to query the shared status of NFS

# SHOWMOUNT-E NFS Server IP

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03145143-9c1e1d7121b74576baf5be8d2ab2a284.jpg "/>

5. The client mounts the shared directory in the NFS server

Command format

# Mount NFS Server IP: Shared directory local mount point directory

# Mount 192.168.1.108:/home/david//tmp/david/

# Mount |grep NFS

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03150218-5c36a5e3aa354ddf84faca08117a2c88.jpg "/>

Mounted successfully.

See if the file is consistent with the server side.

650) this.width=650, "width=", "src=" http://images.cnitblog.com/blog/370046/201301/ 03150527-8d106cf8da254248a8cf6362b90bcd33.jpg "/>

6. Sharing permissions and access Control for NFS

Now let's create a file in/tmp/david/and see what the permissions are.

# Touch 20130103

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03151822-924b583fc6704cbeb4760a7b7786e9c8.jpg "/>

The permission denied appears here because the Write permission on the NFS server-side shared directory itself is not open to other users, and the permission is opened on the server side.

# chmod 777-r/home/david/

650) this.width=650, "width=", "src=" http://images.cnitblog.com/blog/370046/201301/03152214- Df1ef1f106b34b02aaf9200ca0f34abf.jpg "/>

Create a file in client/tmp/david/again

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03152358- F462cca215da47f1a16095a94654d4cc.jpg "/>

I used the root user to create a file that became a nfsnobody user.

NFS has a number of default parameters, open/var/lib/nfs/etab to view the shared/home/david/full permission set value.

# Cat/var/lib/nfs/etab

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03154008-8cac789d404e420e9ed5ef1504612aa2.jpg "/>

The default is sync,wdelay,hide and so on, No_root_squash is to allow root to maintain permissions, Root_squash is to map root to Nobody,no_all_squash do not keep all users in the Mount directory permissions. Therefore, the file owner created by Root is nfsnobody.

Below we use normal user mount, write file test.

# Su-david

$ Cd/tmp/david/

$ Touch 2013david

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03154802-2d303e13d0fe49d483ed64d6b7a4bb71.jpg "/>

Ordinary users write to the file is their own name, which will ensure the security of the server.

On the analysis of permissions

1. When the client connects, the check for the ordinary user

A. If the identity of the normal user is explicitly set, then the identity of the client user is converted to the specified user;

B. If there is a user with the same name on NFS server, then the identity of the client login account is converted to the same user name as NFS server;

C. If there is no explicit designation, there is no user of the same name, then the user identity is compressed into nfsnobody;

2. When the client connects, the root check

A. If the No_root_squash is set, then the root user's identity is compressed to root on NFS server;

B. If All_squash, Anonuid, Anongid are set, the root identity is compressed to the specified user;

C. If there is no explicit designation, the root user is compressed to nfsnobody at this time;

D. If you specify both No_root_squash and All_squash users will be compressed to Nfsnobody, if set Anonuid, Anongid will be compressed to the specified user and group;

7. Unmount The mounted NFS shared directory

# Umount/tmp/david/

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03161846- D7d33eb644ac4c8bb6c16cab1b23ed40.jpg "/>

Eight, start Automatic Mount NFS file system

Format:

<server>:</remote/export> </local/directory> NFS < options> 0 0

# Vi/etc/fstab

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/ 03170455-79707d519e22424da030ed724931cbc1.jpg "/>

Save the exit and restart the system.

Check to see if the/home/david is automatically mounted.

650) this.width=650; "Src=" http://images.cnitblog.com/blog/370046/201301/03171036- C9626aa6e1404d9dbae9ef8add3537d2.jpg "/>

Automatic mount succeeded.

Ix. Related Orders

1, Exportfs

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

2, Nfsstat

Viewing the running Status of NFS is a great help in adjusting the operation of NFS.

3, Rpcinfo

View RPC execution information, a tool that can be used to detect RPC health, and use RPCINFO-P to see what programs are available for RPC-enabled ports.

4, Showmount

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

5, Netstat

You can view the ports that are open for NFS service, where NFS is turned on by 2049,portmap 111 and the rest is RPC enabled.

Finally note two points, although the permission settings can be accessed by ordinary users, but when mounted by default only root can be mounted, ordinary users can execute sudo.

When NFS server shuts down, make sure that the NFS service is down and no clients are connected! Showmount-a can be viewed, if any, with kill Killall Pkill to end, (-9 forced end)


Installation and configuration of Linux Server for NFS

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.