前言
网络文件系统,英文Network File System(NFS),是由SUN公司研制的UNIX表示层协议(presentation layer protocol),能使使用者访问网络上别处的文件就像在使用自己的计算机一样
特点:
(1)提供透明文件访问以及文件传输;
(2)容易扩充新的资源或软件,不需要改变现有的工作环境;
(3) 高性能,可灵活配置。
准备工作:
关闭firewall、selinux
[root@localhost ~]# iptables -F #关闭防火墙
[root@localhost ~]# setenforce 0 #临时关闭selinux
服务端ip:192.168.1.1/24
客户端IP:192.168.1.10/24
1、安装及配置
[root@localhost /]# yum install rpcbind nfs-utils -y #安装服务
[root@localhost /]# systemctl start rpcbind #按照顺序启动服务
[root@localhost /]# systemctl start nfs #按照顺序启动服务
[root@localhost /]# mkdir /home/shared/ #创建共享目录
[root@localhost /]# chmod 755 -R /home/shared/ #加权限
[root@localhost /]# vi /etc/exports #配置nfs
/home/shared 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash ) #将共享目录/home/shared分享给192.168.10.0/24网段
#rw 表示设置目录可读写。
sync 表示数据会同步写入到内存和硬盘中。
no_root_squash 允许root用户客户机在远程NFS共享上保留root权限,一般不建议使用。
no_all_squash 不论nfs客户端连接服务端时是什么用户,对服务端分享的目录来说都不会拥有匿名用户权限。
[root@localhost /]# exportfs -r #重新加载
到这里服务器端已经配置完毕
2、客户端安装及配置
[root@www /]# yum -y install rpcbind #只需要安装rpcbind,不需要安装nfs服务
[root@www /]# showmount -e 192.168.1.1 #显示192.168.1.1上的共享目录
Export list for 192.168.1.1:
/home/shared 192.168.1.0/24
[root@www /]# mount -t nfs 192.168.1.1:/home/shared /mnt/shared/ #挂载到本机/mnt/shared/目录下
[root@www /]# df -h #
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.8M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 39G 5.4G 33G 15% /
/dev/sda1 1014M 217M 798M 22% /boot
/dev/mapper/centos-home 19G 33M 19G 1% /home
tmpfs 98M 0 98M 0% /run/user/0
192.168.1.1:/home/shared 18G 5.0G 13G 28% /mnt/shared
[root@www /]# umount /mnt/shared #取消挂载
[root@www /]# vim /etc/rc.local #修改成自动挂载
mount -t nfs 192.168.1.1:/home/shared /mnt/shared/ #添加到最后一行
重启客户端,df -h验证是否自动挂载
3、总结
安装遇到的问题:
本次安装非常顺利,到最后客户端重启验证是否自动挂载时,出现未挂载。经查看是/etc/rc.local缺少执行权限,添加后,再次重启验证成功