Autofs: automatic mounting Device
The automatic mount device is a daemon that monitors directories. When the target subdirectory is referenced, it automatically performs a predefined NFS mount.
The automatic mount device is managed by the autofs service script.
The auto mount device is configured in the auto. master configuration file, which references a level-2 configuration file named/etc/auto. misc or similar by convention.
Autofs and NFS are usually used after configuration.
The mount command has many parameters. The following are NFS-related parameters.
(1)-a: Mount all the paths listed in/etc/fstab.
(2)-t: Specifies the mount type, such as nfs.
(3)-r: Set the mount path to read only.
(4)-v mount: each operation in the process has a message sent back to the screen.
(5) rsize = n: the number of bytes used by NFS when the NFS server reads files. The default value is 1 024 bytes.
(6) wsize = n: number of bytes used by NFS to write files to the NFS server. The default value is 1 024 bytes.
(7) timeo = n: The number of 1st seconds from the timeout period to the 1/7 re-transfer. The default value is 7/7 seconds.
(8) retry = n: number of times that can be tried before the backend mount operation is abandoned. The default value is.
(9) soft: The system is mounted in soft Mounting Mode. If the Client request does not receive a response, the system will send a new request and return an error message.
(10) hard: mount the system by means of hard mounting. This value is the default value. Repeat the request until the NFS server responds.
(11) intr: Allows NFS to interrupt file operations and return values to programs that call it. By default, file operations are not allowed to be interrupted.
(12) fg: Repeat mounting at the prompt.
(13) bg: if the file system fails to be mounted for 1st times, continue to try mounting in the background. The default value is not processed in the background after the failure.
(14) tcp: mount the file system using TCP instead of the default UDP.
Note: Another important parameter for mounting NFS servers is hard mount or soft mount.
With hard mount, NFS customers constantly try to connect to the NFS server (no prompt is provided in the background) until it is mounted.
When soft mount is used, the system tries to connect to the NFS server on the foreground. When an error message is received, the system terminates the mount attempt and provides related information.
###################### Simple configuration ################ ###########
1. Mount local partitions
In RHEL5.5, The autofs software package is installed by default.
[Root @ kumu ~] # Rpm-qa autofs
Autofs-5.0.1-0.rc2.143.el5
[Root @ kumu ~] #
[Root @ kumu ~] # Grep-v '^ #'/etc/auto. master
/Misc/etc/auto. misc
# Misc is the magic directory, and auto. master defines the magic directory as misc auto. misc is the configuration file automatically mounted.
/Net-hosts
+ Auto. master
[Root @ kumu ~] # Grep-v '^ #'/etc/auto. misc
Cd-fstype = iso9660, ro, nosuid, nodev:/dev/cdrom
# If cd is the middle segment of the target directory name, it is the mount option and the last is the Mount directory.
[Root @ kumu ~] #
[Root @ kumu misc] # ls
[Root @ kumu misc] # grep sda4/etc/auto. master
/Misc/sda4/etc/auto. sda -- timeout = 60
[Root @ kumu misc] # grep sda4/etc/auto. sda
Sda4-fstype = ext3:/dev/sda4
[Root @ kumu misc] # service autofs start // start the service
Start automount: [OK]
[Root @ kumu misc] # ls // The Magic directory appears automatically
Sda4
[Root @ kumu misc] # cd sda4/
[Root @ kumu sda4] # ls // There is nothing after it enters
[Root @ kumu sda4] # cd sda4 // directly cd sda4. It's amazing to go in.
[Root @ kumu sda4] # pwd
/Misc/sda4/sda4
[Root @ kumu sda4] # ls
Lost + found
[Root @ kumu sda4] # mount | grep sda4 // mount
/Dev/sda4 on/misc/sda4/sda4 type ext3 (rw)
[Root @ kumu sda4] #
2. Mount the NFS shared directory
[Root @ kumu ~] # Cat/etc/exports
/Tmp 192.168.0.0/24 (rw)
[Root @ kumu ~] # Service nfs restart
Disable NFS mountd: [failed]
Disable the NFS daemon: [failed]
Disable NFS quotas: [failed]
Disable NFS: [failed]
Start the NFS service: [OK]
Disable NFS quota: [OK]
Start the NFS daemon: [OK]
Start NFS mountd: [OK]
[Root @ kumu ~] # Showmount-e 127.0.0.1
Export list for 127.0.0.1:
/Tmp 192.168.0.0/24
[Root @ kumu ~] # Vi/etc/auto. master
[Root @ kumu ~] # Grep tmp/etc/auto. master
/Misc/tmp/etc/auto. nfs
[Root @ kumu ~] # Vi/etc/auto. nfs
[Root @ kumu tmp] # grep tmp/etc/auto. nfs
Tmp-typefs = nfs, rw 127.0.0.1:/tmp
# Here is a local test. For Remote Test, change the IP address to the remote NFS server.
[Root @ kumu ~] # Service autofs restart
Stop automount: [OK]
Start automount: [OK]
[Root @ kumu ~] # Cd/misc/tmp
[Root @ kumu tmp] # ls
Gconfd-root scim-panel-socket: 0-root whatis. Qs3891
Mapping-root setuplog.txt
[Root @ kumu tmp] #
3. Mount samba
Mounting samba is not demonstrated here. In addition to adding similar statements in auto. master, create an auto. smb file and fill in:
Windows-fstype = smbfs, username = admin % password: // hostname/login folder
You can.
4. mount a local image
[Root @ kumu ~] # Grep iso/etc/auto. master
/Misc/iso/etc/auto. iso
[Root @ kumu ~] # Cat/etc/auto. iso
Iso-fstype = iso9660, ro, nosuid, nodev, loop:/root/rhel5u5. iso
[Root @ kumu ~] # Service autofs restart
Stop automount: [OK]
Start automount: [OK]
[Root @ kumu ~] # Cd/misc/
[Root @ kumu misc] # ls
Iso
[Root @ kumu misc] # cd iso/
[Root @ kumu iso] # ls
[Root @ kumu iso] # cd iso
[Root @ kumu iso] # ls
Cluster README-te.html RELEASE-NOTES-U5-en
ClusterStorage README-zh_CN.html RELEASE-NOTES-U5-en.html
EULA README-zh_TW.html RELEASE-NOTES-U5-es.html
Eula. en_US RELEASE-NOTES-as.html RELEASE-NOTES-U5-fr.html
GPL RELEASE-NOTES-bn.html RELEASE-NOTES-U5-gu.html
------ Omitted ------
[Root @ kumu iso] # mount | grep rhel5u5. iso
/Root/rhel5u5. iso on/misc/iso type iso9660 (ro, nosuid, nodev, loop =/dev/loop1)
[Root @ kumu iso] #
In this way, autofs can be used with yum to install software. If it is not installed, it will not be mounted. When the software is installed, it will be automatically mounted.
[Root @ kumu mnt] # tail-5/etc/yum. repos. d/rhel-debuginfo.repo
[Repo]
Name = repo
Baseurl = file: // misc/iso/Server
Enabled = 1
Gpgcheck = 0
[Root @ kumu mnt] # yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[Root @ kumu mnt] # yum list
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Repo | 1.3 kB: 00
Repo/primary | 753 kB: 00
Repo 2348/2348
------ Omitted ------
#####################################
This article is from the "dry wood Linux blog" blog