How to configure NFS server under Linux?

  

Network File System (NFS) is a mechanism for mounting partitions (directories) on remote hosts to the local system via the network. With the support of the system, the user can operate the shared partition (directory) of the remote host on the local system as if the local partition was operated.

In the development process of embedded Linux, developers need to carry out all software development on the Linux server. After cross-compilation, the general FTP method downloads the executable file to the embedded system, but this way Not only is it inefficient, but it cannot be debugged online. Therefore, by establishing NFS and sharing a specific partition on the Linux server to the embedded target system to be debugged, the Linux server can be directly operated on the embedded target system. The program can be debugged and modified online, which greatly facilitates the development of software. Therefore, NFS is an important part of embedded Linux development. This section will explain in detail how to configure the NFS development environment for embedded Linux.

The implementation of the NFS development environment for embedded Linux includes two aspects: one is the NFS server support on the Linux server side; the other is the NFS client support for the embedded target system. Therefore, the establishment of the NFS development environment needs to be configured. Linux server and embedded target system.

NFS is developed and developed by Sun to share files between different machines and different operating systems through the network. NFS server can also Think of it as a FILE SERVER, which is used to share files between UNIX-like systems. It can be easily mounted to a directory and is as convenient as a local file.

Type: System V-launched Service

Package: nfs-utils

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

Script: nfs, nfslock

Port: Port assigned by portmap service (111)

Configuration file: /etc/exports

Accessibility: portmap (required )

Related Commands: rpcinfo -p [IPADD]: View the rpc service provided by the server

showmount -e: View the directory shared by the service

Server:

1./etc/exports format:

Directory Options

Example: Sharing /share directory to 192.168.0.x users

/share 192.168.0.0 /24 (rw)

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

/mnt/cdrom 192.168.0.*(ro)

= ===> * refers to all ip access;

gives a certain privilege to the directory /home/haiouc/haioucshare;

can load a local disc and then use Nfs is shared with others

2. Start the portmap service:

service portmap start[restart]

3. Start the NFS service:

service nfs start[ ,null,null,3],Restart]

Client:

1. Start the portmap service:

s Ervice portmap start[restart]

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

mkdir /mnt/localshare

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

=========================================== =============================================================== NFS server file system mounted information

showmount -e //display NFS server output list

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

chkconfig --level 35 nfs on //Set the NFS autostart mode;

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

You can auto-mount the nfs directory by modifying the /etc/fstab file

[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 proc defaults 0 0

none /sys sysf s defaults 0 0

LABEL=SWAP-hdc2 swap swap defaults 0 0

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

=========================================================== ========================================================================================== Output directory read-only ro

. Set output directory read and write rw

User mapping options

. all_squash Maps all common users and groups that are remotely accessed to anonymous users Or user group (nfsnobody);

. no_all_squash and all_squash inversion (default);

. root_squash maps root user and owning group to anonymous user or user group (default setting) ;

. no_root_squash and rootsquash are negated;

. anonuid=xxx maps all users of remote access to anonymous users and specifies that the user is a local user (UID=xxx); Br>

. anongid=xxx Map all user groups for remote access to anonymous user group accounts and specify that the anonymous user group account is a local user group account (GID=xxx);

Other options

. secure limit Clients can only connect to nfs servers from tcp/ip ports less than 1024 (default);
. insecure allows clients to connect to servers from tcp/ip ports greater than 1024;

. sync Synchronously writing data to the memory buffer and disk is inefficient, but can guarantee data consistency;

. async saves the data in the memory buffer first, and then writes to the disk if necessary; >

. wdelay Check if there are related write operations, if any, then execute these write operations together, which can improve efficiency (default setting);

. no_wdelay If there is a write operation, it should be executed immediately. Use with sync;

. subtree If the output directory is a subdirectory, the nfs server will check the permissions of its parent directory (the default);

. no_subtree even if the output directory is a child Directory, nfs server does not check the permissions of its parent directory, which can improve efficiency;

Copyright © Windows knowledge All Rights Reserved