四、NFS服务
1、概述
NFS(Network File System)网络文件系统,是FreeBSD支持的文件系统中的一种,它允许一个系统在网络上与其他人共享目录和文件。通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件。
2、服务安装
(1)服务端
[[email protected] Desktop]# rpm -ivh /mnt/Packages/nfs-utils-1.2.3-39.el6.x86_64.rpm
[[email protected] Desktop]# service nfs start
(2)客户端
安装mount或showmount
3、实例
(1)手动挂载
发现权限不被允许
(2)开机自动挂载
4、对共享参数做一些特殊的处理
[[email protected] ~]# vim /etc/exports
服务端:
[[email protected] zhang]# mkdir -p /tmp/zhang/{root_squash,no_root_squash,sync,ro,all_squash,async,rw}
[[email protected] zhang]# chmod 777 -R /tmp/zhang/
[[email protected] zhang]# useradd zyz
[[email protected] zhang]# echo zyz123 | passwd --stdin zyz
Changing password for user zyz.
passwd: all authentication tokens updated successfully.
[[email protected] zhang]# tail -1 /etc/passwd
zyz:x:501:501::/home/zyz:/bin/bash
[[email protected] zhang]# service nfs restart
客户端
[[email protected] ~]# mount 192.168.220.150:/tmp/zhang/root_squash /opt/
[[email protected] ~]# mount 192.168.220.150:/tmp/zhang/no_root_squash /opt/
[[email protected] ~]# mount 192.168.220.150:/tmp/zhang/all_squash /opt/
注:每次挂载前都需要重启服务
5、自动挂载
Autofs 软件包要实现自动挂载涉及到两个文件,auto.master和auto.misc
/etc/auto.master定义文件在本地的挂载点
/etc/auto.misc用来设置需要挂载的文件系统类型和选项
[[email protected] ~]# mkdir /tmp/zhang
[[email protected] ~]# vim /etc/auto.master
8 /tmp/zhang /etc/auto.nfs --timeout=30
[[email protected] ~]# vim /etc/auto.nfs
[[email protected] ~]# cat /etc/auto.nfs
nfs-fstype=nfs192.168.220.150:/tmp/zhang/root_squash
[[email protected] ~]# service autofs restart
Stopping automount: [ OK ]
Starting automount: [ OK ]
[[email protected] ~]# ls /tmp/zhang/
[[email protected] ~]# cd /tmp/zhang/nfs
[[email protected] nfs]# ls
1.txt
[[email protected] nfs]# df -h
192.168.220.150:/tmp/zhang/root_squash 9.7G 3.2G 6.0G 35% /tmp/zhang/nfs