CentOS8 配置 NFS共享目录

CentOS8 配置 NFS共享目录192 168 123 165 data 17G 5 5G 12G 33 data dev sda1 1014M 137M 878M 14 boot

大家好,欢迎来到IT知识分享网。

# 环境说明:

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

CentOS8 配置 NFS共享目录

安装中

CentOS8 配置 NFS共享目录

安装完成

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

4 tcp 111 portmapper

3 tcp 111 portmapper

2 tcp 111 portmapper

4 udp 111 portmapper

3 udp 111 portmapper

2 udp 111 portmapper

1 udp 20048 mountd

1 udp 44356 status

1 tcp 20048 mountd

1 tcp 55217 status

2 udp 20048 mountd

2 tcp 20048 mountd

3 udp 20048 mountd

3 tcp 20048 mountd

3 tcp 2049 nfs

4 tcp 2049 nfs

3 tcp 2049 nfs_acl

1 udp 51865 nlockmgr

3 udp 51865 nlockmgr

4 udp 51865 nlockmgr

1 tcp 34861 nlockmgr

3 tcp 34861 nlockmgr

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/176169.html

(0)
上一篇 2025-04-12 22:45
下一篇 2025-04-13 07:00

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信