Linux NFS service configuration

1. First install nfs

rpm -ivh nfs-utils-1.0.9-16.rpm

 

rpm -qa|grep portmap to see if the portmap port mapper is installed

 

portmap listens on port 111 for TCP and UDP by default

netstat -anp |grep :111

It must be emphasized that portmap is just a port mapper, and the other two daemons that really provide NFS services, rpc.nfsd and prc.mountd. rpc.nfsd is the basic NFS daemon, the main function is to manage whether the client can log in to the server, rpc.mountd is the installation daemon, the main function is to manage the NFS file system, according to the set permissions to decide whether to allow the client to install and use The specified directory or file.

 

2. Start the nfs service

/etc/init.d/nfs start

The nfsd service uses port 2049, and the port used by the rpc.mountd service is not fixed and will change after each startup.

 

3. Export of NFS server shared directory

 

There are two ways to export shared directories: one is to set the /etc/exports file, and the other is to use the exports command to add or remove shared directories

 

The configuration of the /etc/exports file is very simple, the format is as follows:

directory path machine1(option1,option2,.....) machine2(option1,option2,.....)  …

The directory path indicates the shared directory to be exported, and the subdirectories under this directory are also exported at the same time. For security, the root directory is generally not exported. Machine represents the client computers that are allowed to access this shared directory, and can be represented by a machine name, domain name, or IP address. Each machine also contains multiple options, which specify the specific permissions of the client when accessing the shared directory. The options are separated by , and cannot have spaces. Common options are:

ro: Clients only have read access to this shared directory, which is the default option.

rw: read and write permissions

root_squash: When the client uses the root user to access the shared directory, the root user will be mapped to the anonymous user on the server (the default is the nobody user), which is the default option

sync: When the client writes data to the shared directory, it will be written to the server disk immediately, this is the default option

async: When the client writes data to the shared directory, it will be temporarily stored in memory instead of being written to disk immediately

insecure: Allows the client to connect to the server using a non-reserved port, a reserved port is a port less than 1024.

 

After the content of the /etc/exports file is modified, the NFS server process needs to be restarted to take effect. Another way to make it take effect is to execute the exportfs command

 

The options and functions available for the exportfs command are as follows:

-a: export all directories listed in the /etc/exports file

-v: output every directory that is exported or unexported

-r: re-export all directories listed in the /etc/exports file

-u: Cancel the export of the top directory, when used with -a, cancel the export of all directories listed in the /etc/exports file

-i: allow exporting of directories not listed in the /etc/exports file or with options not listed in the /etc/exports file

-f specifies another file to replace /etc/exports

-o: option to specify the export directory

 

4. The client uses the NFS service

There are two main commands for the client to use the NFS service:

showmount : through which you can view information about the NFS server

mount: Through it, you can mount the shared directory exported by the NFS server to a directory in the local file system, and then you can access the remote directory in the form of accessing the local file system.

showmount options: -a -d -e -h -v

The mount command is used to mount a file system to a directory of the local file system. For example, file systems on floppy disks and CD-ROMs can be mounted through it.

The format is as follows:

mount [-t vfstype] [-o options] device dir

Such as: mount -t nfs 192.168.1.10:/home /mnt

 

5. Realize automatic mounting of NFS file system

 

Modify the /etc/fstab file

The specified file system in the /etc/fstab file is not only mounted when the system is booted, but can also be mounted immediately by the root user executing the mount -a command. By default, the file specified in /etc/fstab The system can only be installed by the root user

In addition to the /etc/fstab file, linux can also use the automount process to manage the mounting of the file system, which is characterized by dynamically mounting the file system only when it is accessed. automount is a function provided by the autofs-5.0.1....rpm package, /etc/init.d/autofs start

The main autofs configuration file is /etc/auto.master Each line defines a mount point

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326904825&siteId=291194637