nfs以及autofs

1 安装部署NFS

1.1客户端、服务端关闭selinux和防火墙

##selinnux关闭
###临时关闭
setenforce 0
###永久关闭
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
##防火墙关闭
###临时关闭
syetemctl stop firewalld
###永久关闭
systemctl disable firewalld

1.2 安装nfs服务组件

yum install nfs-utils -y

1.3 启动服务

systemctl restart rpcbind
systemctl restart nfs

1.4 配置服务端

vim /etc/exports
/data/opsware 192.168.153.0/24(rw,sync)

#格式
#/opsware 要共享的目录
#192.168.53.0/24 谁能挂载使用,可以是网段,可以是ip
#(rw,sync) 挂载的一些参数,rw表示挂载为可读可写,sync表示同步

1.5 重新加载配置

exportfs -r
修改完配置文件都需要重新加载配置

1.6 配置客户端

#用showmount搜索网络中可用的共享文件
showmount -e 192.168.153.141
#创建目录挂载
mkdir -p /data/opsware
#挂载
mount -t nfs 192.168.153.141:/dara/opsware /data/opsware
##推荐挂载命令
mount -t nfs -o soft,timo=1 192.168.153.141:/dara/opsware /data/opsware
soft: 软挂载,遇到报错会终止挂载,并返回信息,默认是硬挂载,一直尝试挂载。
timeo: 超时时间,如果不设置,一直链接,可以设置小点
#强制取消挂载
umount -l 192.168.153.141:/data/opsware 

1.7 exportfs文件说明

[root@bubble01 opsware]# exportfs -v
/data/opsware 	192.168.153.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

#rw 表示可读可写
#ro 表示仅可读
#root_squash 如果客户端root访问,则被压缩成nobody,权限也将受到限制
#no_root_squash 客户端使用root登陆,所有权限,高危
#all_squash 不管什么用户访问,全部被压缩成nobody
#no_all_squash 保留访问用户的身份uid以及gid,一般只能查看,不能修改,权限问题,但是可以强制保存

2 NFS自动挂载技术

通过autofs程序实现自动挂载,autofs服务程序与mount命令不同之处在于它是一种守护进程,只有检测到用户试图访问一个尚未挂载的文件系统时才自动的检测并挂载该文件系统
autofs非常方便,主要有两点:
1 设置开机不一定要挂载的目录,当用的时候才实现自动挂载。
2 用户不使用自动挂载的目录一段的时间,会自动卸载。(默认时间为5分钟),可以在autofs.conf设置

2.1 安装autofs

yum install autofs -y
systemctl restart autofs

2.2 查看配置文件

[root@bubble ~]# rpm -qc autofs
/etc/auto.master
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
/etc/sysconfig/autofs
/usr/lib/systemd/system/autofs.service

2.3 auto.master和auto.misc

autofs默认安装好的配置,将/dev/cdrom挂载至/misc/cd目录
在这里插入图片描述
在这里插入图片描述

[root@bubble ~]# pwd
/root
[root@bubble ~]# cd /misc
[root@bubble misc]# ls
[root@bubble misc]# cd cd
[root@bubble cd]# pwd
/misc/cd
[root@bubble cd]# ls
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
[root@bubble cd]# 

2.4 nfs自动挂载配置

  • 编辑/etc/auto.master文件
# 添加以下行:
/opsware /etc/opsware.misc
  • 编辑/etc/opsware.misc
opsware	-fstype=nfs,rw,sync 192.168.153.141:/data/opsware
  • 重启 autofs
systemctl restart autofs
  • df 查看已挂载
[root@bubble data]# df
Filesystem                    1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root        19396608 1601552  17795056   9% /
devtmpfs                         485780       0    485780   0% /dev
tmpfs                            497948       0    497948   0% /dev/shm
tmpfs                            497948    7840    490108   2% /run
tmpfs                            497948       0    497948   0% /sys/fs/cgroup
/dev/sda1                        508580  128432    380148  26% /boot
tmpfs                             99592       0     99592   0% /run/user/0
192.168.153.141:/data/opsware  29878016 1577472  28300544   6% /data/opsware

注:默认5分钟不访问取消挂载,在/etc/autofs.conf配置文件中配置

  • 设置开机自启动
    systemct enable autofs
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值