How to configure an NFS server in Linux

Source: Internet
Author: User

Network File System (NFS) is a mechanism for attaching partitions (directories) on remote hosts to local systems through the Network, with support for the network file system, you can operate on the shared partition (directory) of the remote host on the local system just like operating on the local partition.

During the development of embedded Linux, developers need to develop all the software on the Linux server. After cross-compilation, the executable files can be downloaded to the embedded system in the FTP mode, however, this method is not only inefficient, but cannot be used for online debugging. therefore, you can create NFS to share specific partitions on the Linux server to the Embedded Target System to be debugged, and then operate the Linux server directly on the embedded target system, at the same time, you can debug and modify the program online, greatly facilitating software development. therefore, NFS is an important part of Embedded Linux development. This section details how to configure the NFS development environment of embedded Linux.

The implementation of the NFS development environment in Embedded Linux includes two aspects: one is the support of the NFS server on the Linux server, and the other is the support of the NFS client on the embedded target system. therefore, to establish an NFS development environment, you must configure the Linux server and Embedded Target System.

NFS is developed and developed by Sun to share files between different machines and operating systems over the network. NFS server can also be seen as a file server, which is used to share files between UNIX-type systems and can be easily mounted to a directory, it is as convenient as a local file.

Type: System V-launched Service

Software Package: nfs-utils

Process: nfsd, lockd, rpciod, rpc. {mounted, rquotad, statd}

Script: nfs, nfslock

Port: port assigned by portmap (111)

Configuration File:/etc/exports

Auxiliary tool: portmap (required)

Related command: rpcinfo-p [IPADD]: view the rpc service provided by the server

Showmount-e: view the shared directory of the service.

Server:

1./etc/exports format:

DIRECTORY Options

For example, the shared/share directory is provided to users of 192.168.0.x.

/Share 192.168.0.0/24 (rw)

/Home/haiouc/haioucshare * (rw, sync, all_squash)

/Mnt/cdrom 192.168.0. * (ro)

====> * Indicates that all ip addresses are allowed to access the service;

Grant certain permissions to the directory/home/haiouc/haioucshare;

You can attach local CDs and share them with others using nfs.

2. Start the portmap service:

Service portmap start [restart]

3. Start the NFS service:

Service nfs start [restart]

Client:

1. Start the portmap service:

Service portmap start [restart]

2. Mount the shared directory on the server side (assuming 192.168.0.1 on the server side ):

Mkdir/mnt/localshare

Mount-t nfs 192.168.0.1:/share/mnt/localshare

========================================================== ======================================

Showmount // display NFS Server File System mounting information

Showmount-e // display the NFS server output list

========================================================== ======================================

Chkconfig -- level 35 nfs on // sets the automatic NFS startup mode;

========================================================== ======================================

You can modify the/etc/fstab file to automatically mount the nfs directory at startup.

[Root @ server6 nfs1] # cat/etc/fstab

# This file is edited by fstab-sync-see 'man fstab-sync' for details

LABEL = // ext3 defaults 1 1

None/dev/pts devpts gid = 5, mode = 620 0 0

None/dev/shm tmpfs defaults 0 0

None/proc defaults 0 0

None/sys sysfs defaults 0 0

LABEL = SWAP-hdc2 swap defaults 0 0

192.168.1.10:/home/haiouc/haioucshare/mnt/nfs1 nfs ults 0 0

========================================================== ======================================

NFS parameter information:

Access permission options

. Set the output directory read-only ro

. Set output directory read/write rw

User ing options

. All_squash maps all common users and groups remotely accessed to anonymous users or user groups (nfsnobody );

. No_all_squash and all_squash (default );

. Root_squash maps root users and groups to anonymous users or user groups (default );

. No_root_squash and rootsquash reverse;

. Anonuid = xxx maps all remotely accessed users to anonymous users and specifies the user as a local user (UID = xxx );

. Anongid = xxx maps all remotely accessed user groups to anonymous user group accounts, and specifies the anonymous user group account as the local user group account (GID = xxx );

Other options

. Secure limits that the client can only connect to the nfs server from a TCP/IP Port smaller than 1024 (default );

. Insecure allows the client to connect to the server from a TCP/IP Port greater than 1024;

. Sync writes data synchronously to the memory buffer and disk, which is less efficient, but can ensure data consistency;

. Async stores data in the memory buffer before writing data to the disk if necessary;

. Wdelay checks whether there are related write operations. If yes, execute these write operations together to improve the efficiency (the default setting );

. No_wdelay: if there is a write operation, it will be executed immediately and should be used with sync;

. Subtree if the output directory is a sub-directory, the nfs server checks the permissions of its parent directory (default setting );

. No_subtree even if the output directory is a sub-directory, the nfs server does not check the permissions of its parent directory, which improves efficiency;

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.