自动挂载 Automount
挂载是由访问产生的、卸载是由超时产生的一、手动挂载(临时)
mount -t 文件系统类型 -o 选项1,选项2... 设备文件 挂载点===本地设备文件
/dev/cdrom
/dev/sr0
/dev/sda5
/dev/vg01/lv01
/dev/md0
/dev/md1
/var/dvd.iso
[root@localhost ~]# mount -t ext4 -o ro /dev/sda5 /mnt/sda5
[root@localhost ~]# mount
[root@localhost ~]# mount -t iso9660 /dev/cdrom /mn/cd
===网络设备文件
NFS: 192.168.10.10:/home/dir1
CIFS: //192.168.10.10/dir2
[root@localhost ~]# mount -t nfs 192.168.10.10:/home/dir1 /mnt/dir1
[root@localhost ~]# mount -t cifs -o username=alice%111 //192.168.10.10/dir2 /mnt/dir2 //centos6
[root@localhost ~]# mount -t cifs -o user=allice,pass=111 //192.168.10.10/dir2 /mnt/dir2 //centos7
二、实现自动挂载
[root@localhost ~]# yum -y install nfs-utils1、 /etc/fstab 、
/dev/sda5 /mnt/sda5 ext4 defaults 0 0
192.168.10.10:/home/dir1 /mnt/dir1 nfs defaults 0 0
//192.168.10.10/dir2 /mnt/dir2 cifs defaults,username=alice%111 0 0
优点:可以实现开机自动挂载
缺点:由于网络连接的不稳定性,会导致网络设备挂载失败
结论:适合挂载本地设备和持续使用的设备
2、 automount按需挂载
[root@localhost ~]# yum -y install autofs
[root@localhost ~]# grep '^TIMEOUT' /etc/sysconfig/autofs
TIMEOUT=300
例1:使用automount将光盘/dev/cdrom自动挂载到/mnt/disk/cdrom
父挂载点(监控目录): /mnt/disk
子挂载点(关键字): cdrom
[root@localhost ~]# vim /etc/auto.master
/mnt/disk /etc/auto.fengzhang
[root@localhost ~]# vim /etc/auto.fengzhang
cdrom - fstype=iso9660, ro,nosuid,nodev :/dev/sr0
[root@localhost ~]# service autofs restart
例2:使用automount将192.168.10.10:/home/dir1 /mnt/nfs /dir1
父挂载点: /mnt/nfs 不需要提前准备
子挂载点: dir1 不需要提前准备
[root@localhost ~]# vim /etc/auto.master
/mnt/nfs /etc/auto.nfs
[root@localhost ~]# vim /etc/auto.nfs
dir1 -ro 192.168.10.10:/home/dir1
[root@localhost ~]# service autofs restart
[root@localhost ~]# chkconfig autofs on
[root@localhost ~]# ls /mnt/nfs/
[root@localhost ~]# ls /mnt/nfs/zhang
passwd test.txt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
192.168.10.10:/home/dir1
1032192 44544 935424 5% /mnt/nfs/dir1
随记:存储端NFS服务器配置
[root@localhost ~]# yum -y install nfs-utils[root@localhost ~]# mkdir /home/dir1
[root@localhost ~]# chmod 777 /home/dir1
[root@localhost ~]# touch /home/dir1/test.txt
[root@localhost ~]# vim /etc/exports
/home/dir1 *(rw,sync) // *表示所有主机
[root@localhost ~]# service rpcbind restart
[root@localhost ~]# service nfs restart
[root@localhost ~]# chkconfig nfs on //将其设置为开机自动启动
[root@localhost ~]# chkconfig rpcbind on
[root@localhost ~]# iptables -F