两台linux 系统之间的NFS共享

本文详细介绍了在CentOS 7系统上搭建NFS服务的过程,包括服务端和客户端的配置步骤,解决防火墙问题,以及如何进行挂载和开机启动设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值