NFS network operating system introduction and related applications

Source: Internet
Author: User
Tags nfsd

    1. Introduction to Services for NFS

NFS is the abbreviation for the network file system, which is developed by Sun, which allows different machines and different operations to share data with each other, allowing applications to access data on the server's disk through the Web. is a method of implementing disk File sharing among Unix-like systems.

NFS relies on the RPC protocol during file transfer or information transfer. RPC (remote Procedure call), the Chinese name is a long-range procedure invocation, it is a mechanism that enables the client to execute programs in other systems, it can be said that NFS itself is a program to communicate using RPC, where NFS is used, whether NFS Server or NFS client, you need to turn on the RPC service, so that server and client can use RPC to implement program port, so to understand that NFS is a file system, RPC is responsible for the transmission of information.

2. NFS Installation and Configuration

Under Linux, installing NFS is very simple and requires only

nfs-utils-*: Contains basic NFS commands and monitoring programs

portmap-*: Support for secure NFS RPC Service connections

When the NFS service is started, it will have three daemons to work with for coordination.

NFSD: The most basic NFS daemon, the main function is to manage whether clients can log on to the server and provide services, using port 2049

MOUNTD:RPC Daemon, the main function is to manage the NFS file system, when the client through the NFSD Login successful NFS server, but also need authentication operation. Authentication based on NFS configuration file

/etc/exports

Portmap: Active port mapping, when a client tries to connect and uses NFS, PORTMAP provides the managed NFS service port to the client, allowing the client to make a request to the server through that port, using port 111, in the new version, Portmap was replaced by Rpcbind.

The above describes the installation and Daemon of NFS, in general, you need to configure the server first, and then configure the client, you can work properly. The following first describes how to configure Server for NFS.

Common Directories for NFS

/etc/Exports              Primary configuration file for NFS services /usr/sbin/Exportfs        NFS Service Management commands
/usr/sbin/showmount       Client view command /var/lib/nfs/etab         record NFS shared directory full permission setpoint /var /lib/nfs/xtab         Logging of client information that has been logged on

Server for NFS is configured primarily for/etc/exports, with the following file content format:

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

Shared directories have access to the shared directory host option to set the output Directory access rights (RO,RW), user mappings, etc.

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;

For example: Share the/home/david/of NFS Server to the 192.168.1.0/24 network segment, read and Write permissions,

Configuration file/etc/exports Add a line:/home/david 192.168.1.0/24 (rw)

After configuring the exports file, you can start the NFS server, and the NFS server program relies on the Protmap and NFS programs, so start both of them first.

Execute service PORTMAP[NFS] start to start the services, perform service Portmap[nfs] status to view the status of services.

After you modify the/etc/exports file, you need to perform the service Portmap restart, and in performing the service NFS restart, you can make the set parameters effective.

The EXPORTFS command can view the contents of the current NFS configuration file.

# 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

Users can view the running Status of NFS through Nfsstat, rpcinfo to detect RPC performance, rpcinfo–p see which programs use RPC ports.

Showmount See how many client connections are currently available.

Stop the NFS server, perform service NFS stop, stop Protmap and see who else in the system is using this service to decide.

After the server-side NFS settings are complete, set the client's NFS below.

Mount NFS Server IP: Shared directory local mount directory

For example, Mount 192.168.1.108:/home/hao/mnt/indicates that the/home/hao directory under the 108 server is attached to the local mnt directory.

By writing the 192.168.1.108:/home/hao/mnt NFS defaults 0 0 to the/etc/fstab file, you can automatically mount the NFS file system when the system boots.

After the mount succeeds, the files in both directories remain in sync. Uninstall the NFS shared directory Umount/home/hao that you have ledger.

The above describes the NFS mount knowledge, if you create files in the shared directory, then who is this file? This involves the permissions of NFS, as described below.

3. Permissions Control for NFS

The same folder can be changed and created on two different Linux systems at the same time. If a system is a user, B system is a B user, a user in their own directory (Non-NFS shared directory) to create a file, the owner of the file belongs to a, a, b user, so there is no conflict. If both A and B create files in the NFS shared directory, how can this be handled?

If the shared directory where the client is located cannot create the file, the reason may be that the write permission for the shared directory itself on the server side of NFS is not open to other users, which can be resolved by chmod 777–r directory.

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

Root user-created file owner and group default is Nfsnobody, and ordinary users write to the file is their own name, which ensures the security of the server

3. Application in the field of embedded

Using Nfsroot to launch the Development Board, you can avoid duplicating the root file system (ROOTFS) image and burning the file system, saving a lot of copies, transferring files, saving development time.

How do I turn on the nfsroot feature? The following conditions are required to open the Nfsroot function:

1. Host (typically a Linux system inside a virtual machine) to turn on the NFS Server service

2. The network port of the Development Board should be unblocked

3. The Linux kernel of the Development Board should support Nfsroot

1 and 2 are hardware conditions, which are generally supported. The third item needs to be related to the kernel and uboot, which is described below:

First, inside the kernel configuration, select the option for Nfsroot

After the selection is complete, compile and run, then burn to Flash to specify the partition on the line. This step is to allow kernel to mount the Rootfs from NFS, but the specific path parameters are not yet known, the remaining need to configure the Uboot terminal Bootargs parameters, this parameter will be passed to Kernel,kernel according to this parameter to find the specific path and mount. The following is a description of the relevant parameters for starting NFS in Uboot

On the uboot command line, enter

Setenv Bootargs ' mem=64m console=ttyama0,115200 root=/dev/nfs rw nfsroot=192.168.4.165:/home/nfsroot/rootfs_dir

ip=192.168.4.99:192.168.4.1:255.255.255.0 mtdparts=hi_sfc:256k (boot), 256K (env), 1792K (Kernel),-(ROOTFS) '

NFS network operating system introduction and related applications

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.