Article Title: Automatic File System mounting: autofs. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
To use any file system in Linux, you must first connect it to a directory in the Linux directory tree. When the file system is no longer in use, you also need to uninstall it. In Linux, we generally use the Mount and Umount commands to complete the mounting and unmounting functions.
This article introduces Autofs, another tool that can complete file system mounting and uninstallation.
1. Features of Autofs
The difference between Autofs and Mount/Umount is that it is a guard program. If it detects that the user is attempting to access a file system that has not been attached, it will automatically detect the file system. If it exists, Autofs will automatically hook it. On the other hand, if it detects that a mounted file system is not used for a period of time, Autofs will automatically uninstall it. Therefore, after running Autofs, you no longer need to manually mount and uninstall the file system.
2. Software Installation
Installing Autofs is simple, just execute: rpm-ivh autofs-3.1.3-10.i386.rpm
After the installation is complete, Autofs runs automatically every time Linux is started.
3. Software Configuration
Autofs needs to read the configuration information from the/etc/auto. master file. You can specify multiple mount points in the file. Autofs is used to mount the file system. Each mount point in the file is defined by a single line. Each line can contain three parts, which are used to specify the mount point location respectively, the configuration file to be used when mounting and the time after which the mounted file system is automatically detached. For example, the following line is included in the file:
/Auto/etc/auto. misc -- timeout 60
The first part specifies the installation point as/auto, and the second part specifies the mount point configuration file as/etc/auto. misc, the third part specifies that the mounted file system is automatically uninstalled 60 seconds after it is idle.
Example of file/etc/auto. misc:
Cd-fstype = iSO9660, ro:/dev/cdrom
Fd-fstype = msdos:/dev/fd0
Each line of the file shows how a file system is mounted. In the first row, specify to mount/dev/cdrom to/auto/cd, and in the second row, specify to mount/dev/fd0 to/auto/fd. The second value of each row-fstype is an option that indicates the type and mounting options of the mounted file system. The mounting options used in the mount command also apply to-fstype.
After the configuration file is modified, run the "/etc/init. d/autofs restart" command to make the new configuration take effect.
Example:
Picture.dfe.cn-rw, soft, intr, rsize = 8192, wsize = 8192 192.168.0.22:/var/www/virtualhost/picture.dfe.cn
Www.dfe.cn-rw, soft, intr, rsize = 8192, wsize = 8192 192.168.14.3:/var/www/virtualhost/www.dfe.cn
4. Use Autofs
Enter the command "ls/auto/cd". Autofs will automatically check whether there is a cd in the optical drive. If yes, it will automatically attach it to/auto/cd, in this way, ls will list the content. If we do not access/auto/cd again within 60 seconds, Autofs will automatically unmount/dev/cdrom. You can also directly use a floppy disk without using Mount for mounting.
-----------------------------------------
Simple:
# Vi/etc/auto. master
/Var/www/html/nfs/etc/auto.51auto -- timeout = 60
# Vi/etc/auto.51auto
Www.dfs.cn-rw, soft, intr, rsize = 8192, wsize = 8192 192.168.0.214:/var/www/html/www.dfs.cn
-------------------------------------
On an nfs server:
Allow access from the client in/etc/hosts. allow.
For example, portmap: 192.168.0.33
Client:
Configure the file/etc/auto. master/etc/auto.51auto.
Start the portmap and nfs services.
You can manually mount the test for the first time.
------------------------------------
NFS server restarts. It is recommended that you disable portmap nfs and restart it first. Otherwise, it is easy to wait for a long time.
-----------------------------------
NFS Speed Optimization:
1. Set the block size
The risize and wsize of the mount command specify the block size transmitted between the server and client.
Mount-t nfs-o rsize = 8192, wsize = 8192, timeo = 14, intr client:/partition
If not specified, the system sets the default risize and wsize Based on nfs version. In most cases, 4 K is used for nfs v2 and the maximum is 8 K. For v3, use the server-side kernel to set the risize and wsize limits.
Vi/usr/src/linux2.4.22/include/linux/nfsd/const. h
Constant: NFSSVC_MAXBLKSIZE
All 2.4 clients support a maximum of 32 K transmission blocks. The default system block may be too large or too small. It depends mainly on your kernel and your Nic. too large or too small may lead to slow nfs speed.
Specifically, you can use benchmark such as Bonnie, Bonnie ++, and iozone to test the nfs speed for different risize and wsize instances. Of course, dd can also be used for testing.
# Time dd if =/dev/zero of =/testfs/testfile bs = 8 k count = 1024 test nfs write
# Time dd if =/testfs/testfile of =/dev/null bs = 8 k test nfs read
During the test, the file size must be at least twice that of the system RAM. In each test, umount and mount are used to mount/testfs. By comparing different block sizes, the optimized block size is obtained.
2. Size of the network transmission package
During packet transmission, packets must be grouped. The bandwidth of the network cannot be used too much or too small. Therefore, the network should be tested and optimized. You can use ping-s 2048-f hostname to ping and try different package sizes to view the packet loss. In addition, you can use nfsstat-o net to test the packet loss rate of nfs over udp transmission. Because statistics cannot be cleared, you must first run this command to remember the value and then run the statistics again. If the packet loss rate is much higher than the previous statistics. Then you can see the size of the network transmission package. Run the following command:
# Tracepath node1/port number
# Ifconfig eth0
Use # ifconfig eth0 mtu 16436 to compare the mtu of the network adapter with the previous pmtu. Of course, if risize and wsize are greater than mtu values, then the server package will be reorganized to the client, which will consume the cpu resources of the client. In addition, packet restructuring may lead to network failures and packet loss. Any packet loss will result in the re-transmission of rpc requests. The re-transmission of rpc requests will lead to timeout, seriously reducing nfs performance.
You can view
/Proc/sys/net/ipv4/ipfrag_high_thresh
/Proc/sys/net/ipv4/ipfrag_low_thresh
Understand the number of packages that the system can process. If the network package reaches ipfrag_high_thresh, the system will start to lose packets until the number of packets reaches ipfrag_low_thresh.
3. nfs mounting Optimization
Timeo: If the timeout occurs, the client waits for a second.
Retrans: number of times of timeout attempts.
Bg: supports background mounting.
Hard: if the server does not respond, the client keeps trying to mount
Wsize: Write block size
Rsize: Read block size
Intr: an unsuccessful mount can be interrupted.
Noatime: does not update the inode access time of the file, which can increase the speed
Async: asynchronous read/write
4. Number of nfsd instances
The default system has eight nfsd processes at startup.
# Ps-efl | grep nfsd
By viewing the th row of the/proc/net/rpc/nfsd file, the first is the number of nfsd, And the last 10 is the number of time used by the thread, if the second to fourth values are large, you need to increase the number of nfsd instances.
The details are as follows:
# Vi/etc/init. d/nfs
Locate RPCNFSDCOUNT and modify this value, which is generally the same as the number of clients.
# Service nfs restart
# Mount-
5. nfsd Queue Length
For 8 nfsd processes, the system's nfsd queue length is 64 K. If there are more than 8 processes, the corresponding queue size must be increased accordingly.
/Proc/sys/net/core/rwmem_default
/Proc/sys/net/core/wwmem_default
/Proc/sys/net/core/rmmem_max
/Proc/sys/net/core/wmmem_max
The queue length should be 8 KB for each nfsd. In this way, the server can queue client requests. If you want to change this value permanently
# Vi/etc/sysctl. conf
Net. core. rmmem_default = Number
Net. core. wmmem_default = Number
Net. core. rmmem_max = Number
Net. core. wmmem_max = Number
# Service nfs restart