服务端
1.安装
安装nfs-utils,rpcbind,提供NFS共享的服务为nfs,完成安装以后建议调整两个服务的自启动状态,以便每次开机后自动启动。手动加载NFS共享服务时,应该先启动rpcbind,然后在启动nfs。(因为NFS要向RPC注册端口信息)
[root@ c7-42 ~]# yum -y install nfs-utils rpcbind
2.设置共享目录
NFS的配置文件为/etc/exports,文件内容默认为空(无任何共享),在exports文件中设置共享资源时,记录格式为:”目录位置 客户机地址(权限选项)”。例如要将文件夹
/backup共享给192.168.152.0网段使用,允许读写操作。
[root@ c7-42 ~]# vim /etc/exports
/data 10.0.0.0/24(rw,sync,no_root_squash,no_all_squash)
解释一下:
/data: 共享目录位置。
10.0.0.0/24: 客户端 IP 范围,* 代表所有,即没有限制。
rw: 权限设置,可读可写。
sync: 同步共享目录。
no_root_squash: 可以使用 root 授权。
no_all_squash: 可以使用普通用户授权
3.创建共享目录
[root@ c7-42 ~]# mkdir -p /data
4.添加开始自启并重启nfs-server
[root@ c7-42 ~]#systemctl enable rpcbind
[root@ c7-42 ~]#systemctl enable nfs-server
[root@ c7-42 ~]#systemctl restart rpcbind
[root@ c7-42 ~]#systemctl restart nfs-server
客户端
1.安装
[root@ c7-41 ~]# yum -y install nfs-utils rpcbind
[root@ c7-41 ~]# systemctl enable rpcbind
[root@ c7-41 ~]# systemctl restart rpcbind
2.创建挂载目录并挂载
[root@ c7-41 ~]# mkdir -p /data
[root@ c7-41 ~]# mount 10.0.0.45=2:/data /data
#查看一下
[root@ c7-41 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 27G 2.1G 25G 8% /
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
10.0.0.42:/data 27G 2.1G 25G 8% /data
3.添加到开机自动挂载
[root@ c7-41 ~]# echo '/bin/mount 10.0.0.42:/data /data'>>/etc/rc.local
4.测试共享目录
[root@ c7-41 ~]# cd /data/
[root@ c7-41 data]# ls
[root@ c7-41 data]# mkdir www
[root@ c7-41 data]# ls
www
[root@ c7-41 data]# ls
aaa www
#######
[root@ c7-42 ~]# cd /data/
[root@ c7-42 data]# mkdir aaa
[root@ c7-42 data]# ls
aaa www