NFS 概念 网络文件系统 (NFS) 是 Unix 系统和网络附加存储文件管理器常用的网络文件系统 , 允许多个客户端通过网络共享文件访问。它可用于提供对共享二进制目录的访问 , 也可用于允许用户在同一工作组中从不同客户端访问其文件。 一、nfs配置文件常用参数 服务端: 安装nfs服务 [root@server ~]# yum install nfs-utils -y 实验环境设置 1、关闭防火墙 [root@server ~]# systecmtl stop firewalld 2、打开nfs服务 [root@server ~]# systemctl start nfs 编辑nfs配置文件 [root@server ~]# vim /etc/exports /mnt *(sync,ro) ##/mnt只读挂载 sync ##数据同步 刷新nfs配置 [root@server ~]# exportfs -rv exporting *:/mnt 客户端: 实验环境设置 安装nfs服务 [root@client ~]# yum install nfs-utils -y 同步服务端nfs设置 [root@client ~]# showmount -e 172.25.254.208 Export list for 172.25.254.208: /mnt * 挂载 [root@client ~]# mount 172.25.254.208:/mnt/ /mnt 建立文件:只读 touch /mnt/file4 touch: cannot touch ‘/mnt/file4’: Read-only file system nfs配置文件的其他参数 在服务端修改配置文件并刷新 [root@server ~]# vim /etc/exports [root@server ~]# exportfs -rv 1、对/mnt文件可写 服务端: 修改参数 /mnt *(sync,rw) 为了方便实验,给予目录权限 [root@server ~]# chmod 777 /mnt 客户端: 挂载 [root@client ~]# mount 172.25.254.208:/mnt /mnt 建立文件 [root@client ~]# touch /mnt/file4 查看文件组 [root@server ~]# ll /mnt -rw-r--r--. 1 nfsnobody nfsnobody 0 Jun 2 04:49 file4 2、将建立的/mnt文件组改为root 服务端: 修改参数 /mnt *(sync,rw,no_root_squash) 客户端: 挂载 [root@client ~]# mount 172.25.254.208:/mnt /mnt 建立文件 [root@client ~]# touch /mnt/file5 查看文件组 [root@server ~]# ll /mnt -rw-r--r--. 1 root root 0 Jun 2 04:51 file5 3、将建立的/mnt文件组改为student 服务端: 修改参数 /mnt *(sync,rw,anonuid=1000,anongid=1000) 客户端: 挂载 [root@client ~]# mount 172.25.254.208:/mnt /mnt 建立文件 [root@client ~]# touch /mnt/file6 查看文件组 [root@server ~]# ll /mnt -rw-r--r--. 1 student student 0 Jun 2 04:53 file6 4、指定用户、指定主机才可执行权限 服务端: 修改参数 /mnt *(sync,rw,anonuid=1000,anongid=1000,no_root_squash) /westos 172.25.254.0/24(sync) 172.25.254.250(sync,rw) ##IP为250的主机可写 172.25.254.0/24(sync) ##网段 给予目录权限 [root@server ~]# chmod 777 /westos 客户端: 挂载 [root@client ~]# mount 172.25.254.208:/westos/ /mnt 建立文件 IP为108的主机不可写 [root@client ~]# touch /mnt/file8 touch: cannot touch ‘/mnt/file8’: Read-only file system 二、autofs自动挂载 使用目录时自动挂载,不用时自动卸载我们所操作的网络文件系统。 实验: 服务端: 创建根目录,给予权限 [root@server ~]# mkdir /westos [root@server ~]# chmod 777 /westos/ 1 2 编辑nfs配置文件: [root@server ~]# vim /etc/exports /mnt *(sync,rw,anonuid=1000,anongid=1000,no_root_squash) /westos 172.25.254.0/24(sync) 172.25.254.108(sync,rw) 刷新nfs配置 [root@server ~]# exportfs -rv 客户端: 同步208的配置 [root@client ~]# showmount -e 172.25.254.208 安装软件,开启软件 [root@client mnt]# yum install autofs -y [root@client mnt]# systemctl start autofs 进到指定目录查看 [root@client mnt]# cd /net/172.25.254.208/westos [root@client westos]# ls 编辑配置文件,重启服务 [root@client westos]# vim /etc/sysconfig/autofs TIMEOUT=5 ##退出目录后多长时间取消自动挂载,为方便查看实验设置为5s [root@client westos]# systemctl restart autofs.service 查看挂载 [root@client westos]# df 172.25.254.208:/westos 10473984 3156352 7317632 31% /mnt 172.25.254.208:/westos 10473984 3156352 7317632 31% /net/172.25.254.208/westos 退出目录,5s后查看挂载(已自动取消挂载) [root@client westos]# cd [root@client ~]# df 172.25.254.208:/westos 10473984 3156352 7317632 31% /mnt 取消挂载 [root@client ~]# umount /mnt 三、指定挂载点目录 客户端: 编辑主文件:最终挂载点位置 [root@client ~]# vim /etc/auto.master 8 /nfs /etc/auto.westos ##指定最终挂载点的上层目录 1 2 编辑子文件:最终挂载点名称 [root@client ~]# vim /etc/auto.westos westos -rw,vers=3 172.25.254.208:/westos ##指定最终挂载的设备:真实的网络文件系统 -rw,vers=3 ##挂载参数 重启服务 [root@client ~]# systemctl restart autofs.service 1进到指定目录查看挂载(最终挂载点目录已修改) : [root@client ~]# cd /nfs/westos [root@client westos]# df 172.25.254.208:/westos 10473984 3156480 7317504 31% /nfs/westos 查看挂载参数 [root@client westos]# mount 注:再次修改内容时需退出目录修改文件并重启 [root@client westos]# cd [root@client ~]# vim /etc/auto.westos [root@client ~]# systemctl restart autofs.service |
|