ENV:
[test@nfs-s ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[test@nfs-s ~]$ uname -r
3.10.0-514.el7.x86_64
[test@nfs-c ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[test@nfs-c ~]$ uname -r
3.10.0-514.el7.x86_64
nfs-c 为nfs的客户端,nfs-s为nfs的服务端
实验只有操作过程,没有nfs的工作原理,哪想了解工作原理,请自行百度或google。
实验系统为最小化安装,并没有nfs组件,在系统上安装nfs-utils服务组件
[root@nfs-s ~]# yum -y install nfs-utils
[root@nfs-c ~]# yum -y install nfs-utils
服务端操作:
[root@nfs-s ~]# mkdir /public
[root@nfs-s ~]# chmod -Rf 777 /public
[root@nfs-s ~]# vi /etc/exports
/public 192.168.56.*(rw,sync,root_squash)
[root@nfs-s ~]# systemctl restart rpcbind
[root@nfs-s ~]# systemctl enable rpcbind
[root@nfs-s ~]# systemctl start nfs-server
[root@nfs-s ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
配置NFS服务程序配置文件的参数:
参数 作用
ro 只读
rw 读写
root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户
no_root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
all_squash 无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户
sync 同时将数据写入到内存与硬盘中,保证不丢失数据
async 优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据
客户端操作:
[root@nfs-c ~]# showmount -e 192.168.56.6
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
这个错误是因为服务端没有把防火墙关闭,centos7之后防火墙不再使用iptables ,而是使用firewalld,要在服务端操作:
[root@nfs-s ~]# iptables -F
[root@nfs-s ~]# service iptables save
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@nfs-s ~]# systemctl disable iptables
Failed to execute operation: No such file or directory
centos7之后不再使用iptables,要使用firewalld
[root@nfs-s ~]# systemctl stop firewalld
[root@nfs-s ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
继续客户端:
[root@nfs-c ~]# showmount -e 192.168.56.6
Export list for 192.168.56.6:
/public 192.168.56.*
[root@nfs-c ~]# mkdir /mnt/public
[root@nfs-c ~]# mount -t nfs 192.168.56.6:/public /mnt/public //临时挂载,要想开机启动,加入fstab中实现
[root@nfs-c ~]# vi /etc/fstab
192.168.56.6:/public /mnt/public nfs defaults 0 0
查看下挂载:
[root@nfs-c ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.3G 16G 8% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.4M 912M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 184M 0 184M 0% /run/user/1000
192.168.56.6:/public 17G 1.3G 16G 8% /mnt/public