自动挂载 Automount

自动挂载 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 -t iso9660 -o loop /dvd.iso /mnt/dvd
[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-utils

1、 /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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值