Installation and configuration of Linux Server for NFS

Source: Internet
Author: User
Tags nfsd

Http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html

First, NFS Service Introduction

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 6.5 (Final)

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

Selinux=disabled

NFS Server ip:192.168.23.128

NFS Client ip:192.168.23.129

Note: because of system differences, the previous Portman ( CentOS 5 and the following versions) in the CentOS 6 the name of the inside has changed, called Rpcbind

Third, installation NFS Service

1. See if the System has NFS installed

The system has nfs-utils rpcbind two packages installed.

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 Rpcbind two packages will be available on the system CD.

# mount/dev/cdrom/mnt/cdrom/

# cd/mnt/cdrom/centos/

# RPM-IVH rpcbind-0.2.0-11.el6.x86_64.rpm

# RPM-IVH nfs-utils-1.2.3-54.el6.x86_64.rpm

# rpm-q Nfs-utils Rpcbind

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

Five, NFS configuration of the server

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

Path

Description

/etc/exports

Primary configuration file for NFS services

/usr/sbin/exportfs

Management Commands for NFS services

/usr/sbin/showmount

View commands for clients

/var/lib/nfs/etab

Record full permission settings for NFS-shared directories

/var/lib/nfs/xtab

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

Six, NFS server Start-up and stop

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 Rpcbind and NFS two services, and Rpcbind must start before NFS.

# service Rpcbind Start

# Service NFS Start

2. Querying Server Status for NFS

# Service Rpcbind Status

# Service NFS Status

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 Rpcbind

# Chkconfig--list NFS

Set Rpcbind and NFS services to start automatically at System run level 3, 4, 5.

# chkconfig--level Rpcbind on

# Chkconfig--level NFS on

Vii. Examples1, 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:

# Vi/etc/exports

/OPT/CENTOS6 192.168.23.0/24 (rw)

2. Restart Rpcbind and NFS Services

# service Rpcbind Start

# Service NFS Start

# Exportfs

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

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

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

# SHOWMOUNT-E NFS Server IP

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:/opt/centos6//app/web/labs/nfs/

# Mount |grep NFS

Mounted successfully.

See if the file is consistent with the server side.

6. Sharing permissions and access Control for NFS

Now let's create a file in/app/web/labs/nfs/to see what the permissions are. That is, the client creates the file

# Touch 20150524

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

# Chmod-r 777/opt/centos6/

Create a file in client/app/web/labs/nfs/again

The file I created with the root user became a nfsnobody user? Why

Server-side NFS has a number of default parameters, open/var/lib/nfs/etab to view the shared/opt/centos6/full permission setting value.

# Cat/var/lib/nfs/etab

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.

# exit

$ cd/app/web/labs/nfs/

$ Touch 20150524-2

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

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/app/web/labs/nfs/

Eight, start Automatic Mount NFS file system

# Vi/etc/fstab

Format:

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

Save the exit and restart the system.

Check to see if the/app/web/labs/nfs/is automatically mounted.

Automatic mount succeeded.

Ix. related commands 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 connected to the client
-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,rpcbind 111 and the rest is RPC enabled.

Ten, note 1, permission settings

Although the permissions can be set to allow ordinary users to access, but when mounted by default only root can be mounted, ordinary users can execute sudo.

2. Shut down the machine

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 Killallpkill to end, (-9 forced end)

Installation and configuration of Linux Server for NFS

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.