您的位置:首页 > 理论基础 > 计算机网络

搭建NFS网络文件共享

2014-04-19 22:51 330 查看
实验要求:

将/root文件夹共享给192.168.80.188,保留root的身份及完整权限
将/usr/src文件夹共享给192.168.80.0/24网段,只有读取权限,不可写入,所有用户均视为nfsnobody对待

步骤1、配置NFS配置文件
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# cat /etc/exports
/root 192.168.80.188(rw,no_root_squash)
/usr/src 192.168.80.0/24(ro,all_squash)
步骤2、开启服务
[root@localhost ~]# /etc/init.d/portmap restart
停止 portmap: [确定]
启动 portmap: [确定]
[root@localhost ~]# service nfs restart
关闭 NFS mountd: [确定]
关闭 NFS 守护进程: [确定]
关闭 NFS quotas: [确定]
关闭 NFS 服务: [确定]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS 守护进程: [确定]
启动 NFS mountd: [确定]
Stopping RPC idmapd: [确定]
正在启动 RPC idmapd: [确定]
步骤3、在客户端验证
1)查看服务状态
[root@localhost ~]# service portmap status
portmap (pid 19000) 正在运行...
2)查看nfs共享列表
[root@localhost ~]# showmount -e 192.168.80.253
Export list for 192.168.80.253:
/root 192.168.80.188
/usr/src 192.168.80.0/24
3)挂载NFS共享目录
[root@localhost ~]# mkdir /mnt/dir1 /mnt/dir2
[root@localhost ~]# ls /mnt
dir1 dir2 hgfs
[root@localhost ~]# mount 192.168.80.253:/root /mnt/dir1
[root@localhost ~]# mount 192.168.80.253:/usr/src /mnt/dir2
4)在客户端写入测试文件
[root@localhost dir1]# mkdir dir1
[root@localhost dir1]# touch file1
[root@localhost dir1]# ls -lh
总计 64K
-rw------- 1 root root 1015 2013-07-10 anaconda-ks.g
drwxr-xr-x 2 root root 4.0K 2013-07-23 Desktop
drwxr-xr-x 2 root root 4.0K 04-14 20:05 dir1
-rw-r--r-- 1 root root 0 04-14 20:05 file1
-rw-r--r-- 1 root root 33K 2013-07-10 install.log
-rw-r--r-- 1 root root 3.8K 2013-07-10 install.log.syslog

[root@localhost dir2]# mkdir dir2
[root@localhost dir2]# touch file2
[root@localhost dir2]# ls -lh
总计 28K
drwxr-xr-x 2 root root 4.0K 2009-10-01 debug
drwxr-xr-x 2 root root 4.0K 04-14 20:06 dir2
-rw-r--r-- 1 root root 0 04-14 20:06 file2
drwxr-xr-x 2 root root 4.0K 2009-10-01 kernels
-rw-r--r-- 1 root root 5 04-14 19:02 scim-bridge-0.3.0.lockfile-0@localhost:0.0
drwxr-xr-x 7 root root 4.0K 2012-11-01 vmware-tools-distrib

扩展

将上面/root共享通过fstab实现开机自动挂载
在客户端操作
[root@localhost ~]# tail -n 1 /etc/fstab
192.168.80.253:/root /mnt/dir1 nfs defaults 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# df -h | grep nfs
192.168.80.253:/root 19G 2.7G 16G 15% /mnt/dir1

将上面/usr/src共享通过autofs实现触发挂载
[root@localhost ~]# rm -rf /data/src/
[root@localhost ~]# grep nfs /etc/auto.master
/data /etc/auto.data
[root@localhost ~]# cat /etc/auto.data
src -fstype=nfs,rw 192.168.80.253:/usr/src(注意前面没有冒号,别的需要加上冒号)
[root@localhost ~]# service autofs restart
[root@localhost ~]# cd /data/src/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: