网站首页 > 文章精选 正文
# 环境说明:
1、主机IP
nfs server端主机:cjzm(nfs1) 192.168.123.165
nfs client端主机:asan(nfs2) 192.168.123.231
[root@asan ~]# ip a #查看主机IP
2、系统:CentOS Linux release 8.0.1905 (Core)、CentOS Linux release 7.9.2009 (Core)为例
[root@cjzm ~]#cat /etc/redhat-release #查看系统版本信息
3、安装版本:
centos7:
nfs-utils-1.3.0-0.68.el7.x86_64
centos8:
nfs-utils-1:2.3.3-41.el8.x86_64
rpcbind-1.2.5-8.el8.x86_64
# cjzm主机部署server端部署(rpm安装)
## 本机具备yum源可以使用本机yum源安装,如果本机没有yum源,可参考压缩包提供的RPM包安装
1、安装软件
[root@cjzm ~]# yum -y install rpcbind nfs-utils
2、创建共享文件并设置访问权限(如果原来已有,就不必创建)
[root@cjzm ~]# mkdir /data
[root@cjzm ~]# chmod 666 /data -R
3、修改配置文件,填写授权权限
[root@cjzm ~]# vim /etc/exports
#授权给192.168.123.231主机权限
/data 192.168.123.231(rw,sync,insecure,no_subtree_check,no_root_squash)
##################################################################
权限参数说明:
参数 说明
ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
async nfs 在写入数据前可以响应请求
secure nfs 通过 1024 以下的安全 TCP/IP 端口发送
insecure nfs 通过 1024 以上的端口发送
wdelay 如果多个用户要写入 nfs 目录,则归组写入(默认)
no_wdelay 如果多个用户要写入 nfs 目录,则立即写入,当使用 async 时,无需此设置
hide 在 nfs 共享目录中不共享其子目录
no_hide 共享 nfs 目录的子目录
subtree_check 如果共享 /usr/bin 之类的子目录时,强制 nfs 检查父目录的权限(默认)
no_subtree_check 不检查父目录权限
all_squash 共享文件的 UID 和 GID 映射匿名用户 anonymous,适合公用目录
no_all_squash 保留共享文件的 UID 和 GID(默认)
root_squash root 用户的所有请求映射成如 anonymous 用户一样的权限(默认)
no_root_squash root 用户具有根目录的完全管理访问权限
anonuid=xxx 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID
anongid=xxx 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID
###############################################################
4、启动服务并设置开启自启动
[root@cjzm ~]# systemctl start nfs-server.service
[root@cjzm ~]# systemctl enable nfs-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
5、查看注册的端口列表
[root@cjzm ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 20048 mountd
100024 1 udp 44356 status
100005 1 tcp 20048 mountd
100024 1 tcp 55217 status
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100021 1 udp 51865 nlockmgr
100021 3 udp 51865 nlockmgr
100021 4 udp 51865 nlockmgr
100021 1 tcp 34861 nlockmgr
100021 3 tcp 34861 nlockmgr
100021 4 tcp 34861 nlockmgr
# nfs2主机部署client端部署(rpm安装)
# 本机具备yum源可以使用本机yum源安装,如果本机没有yum源,可参考压缩包提供的RPM包安装
1、安装软件
[root@asan ~]# yum -y install nfs-utils
2、nfs识别测试
[root@asan ~]# showmount -e 192.168.123.165
Export list for 192.168.123.165:
/data 192.168.123.231
#出现上面的结果 为测试通过
========================================================
!!!注意!!!----如果存在以下报错,有可能是网络不通或防火墙阻止,检查一下防火墙是否放通
[root@asan ~]# showmount -e 192.168.123.165
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
解决方式1 :nfs1主机防火墙放开部分服务
[root@cjzm ~]#firewall-cmd --permanent --add-service=rpc-bind 允许rpc nfs mountd服务通过防火墙
[root@cjzm ~]#firewall-cmd --permanent --add-service=nfs
[root@cjzm ~]#firewall-cmd --permanent --add-service=mountd 用于showmount
[root@cjzm ~]#firewall-cmd --reload 刷新防火墙配置
解决方式2:nfs2主机防火墙放开数据来源:
[root@asan ~]# iptables -A INPUT -s 192.168.123.165 -j ACCEPT
=========================================================
3、创建挂载目录,并挂载
[root@asan ~]# mkdir /data
[root@asan ~]# mount 192.168.123.165:/data /data
[root@asan ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 471M 0 471M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.3M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda3 18G 11G 7.4G 59% /
/dev/sda1 297M 188M 109M 64% /boot
tmpfs 98M 0 98M 0% /run/user/1000
tmpfs 98M 12K 98M 1% /run/user/42
192.168.123.165:/data 17G 5.5G 12G 33% /data/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 100M 0 100M 0% /run/user/0
192.168.253.146:/app 47G 1.5G 46G 3% /app
4、测试读写(nfs1和nfs2主机互写测试文件并查看)
[root@cjzm ~]# touch /data/test.txt
[root@asan ~]# ls -rlt /data/test.txt
-rw-r--r--. 1 root root 0 7月 18 18:59 /data/test.txt
[root@asan ~]# echo test2>/data/test.txt
[root@cjzm ~]# cat /data/test.txt
test2
- 上一篇: 本地启动服务访问静态html
- 下一篇: 教你查询自己或他人手机一天访问了哪些软件,用过哪些WiFi!
猜你喜欢
- 2025-04-28 国产化之银河麒麟.netcore3.1访问https服务的两个问题
- 2025-04-28 教你查询自己或他人手机一天访问了哪些软件,用过哪些WiFi!
- 2025-04-28 本地启动服务访问静态html
- 2025-04-28 linux下查看网络连接、进程、服务
- 2025-04-28 通过分批重启组件服务,阿里云大部分地域控制台服务已恢复访问
- 2025-04-28 最高检启用12309检察服务大厅 承诺群众“只进一个门”就能办成事
- 2025-04-28 「新系统」增值税发票综合服务平台(企业版)常见问题
- 2025-04-28 威联通(QNAP)NAS随时随地免费远程外网访问,myQNAPcloud云服务
- 04-28内网IP与外网IP
- 04-28打开文档提示“office你的许可证不是正版”该怎么办?
- 04-28腾讯云国际站:如何通过腾讯云服务器搭建私有网络?
- 04-28今天我们聊聊什么是ip地址,什么又是公网和私网
- 04-28内网测速平台
- 04-28什么是IP地址,IP地址详解
- 04-28熟悉电脑地址,快速配置上网
- 04-28外网利用ssh隧道访问内网
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 计算机网络的拓扑结构是指() (45)
- 稳压管的稳压区是工作在什么区 (45)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)