美文网首页
centos 搭建 nfs (nfs+firewall 设置)

centos 搭建 nfs (nfs+firewall 设置)

作者: Mr_窦先生 | 来源:发表于2023-05-11 20:13 被阅读0次

centos 搭建 nfs (nfs+firewall 设置)

一、规划

机器IP: 192.168.21.6
共享路径:/home/data

二、 nfs 部署

1、安装 nfs

yum install -y nfs-utils
yum install -y rpcbind

2、配置开机启动

chkconfig nfs on
chkconfig rpcbind on

3、启动服务

service rpcbind start
service nfs start

4、配置共享位置

mkdir /home/data

#编辑文件
vim /etc/exports

/home/data  *(rw,async,insecure,no_root_squash,no_subtree_check)

#刷新-立即生效
exportfs -a

#验证配置内容
exportfs -rv

#重启服务
systemctl restart rpcbind  && systemctl restart nfs 

#开机启动
systemctl enable nfs && systemctl enable rpcbind

5、 修改nfs 进程数,提高读写速度
vim /etc/sysconfig/nfs

 15 # Number of nfs server processes to be started.
 16 # The default is 8. 
 17 RPCNFSDCOUNT=32

6、指定 nfs 端口

vim /etc/sysconfig/nfs

放开或添加如下代码:

RQUOTAD_PORT=30001
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662

7、配置 nfs 端口锁定

vim /etc/modprobe.d/lockd.conf

此文件是用来配置 lockd 内核模块的参数的。lockd 是一个 Linux 内核模块,用于支持 NFS (Network File System) 文件共享协议中的文件锁定功能

#
# Set the NFS lock manager grace period. n is measured in seconds. 
#options lockd nlm_grace_period=90
#
# Set the TCP port that the NFS lock manager should use. 
# port must be a valid TCP port value (1-65535).
options lockd nlm_tcpport=32803
#
# Set the UDP port that the NFS lock manager should use.
# port must be a valid UDP port value (1-65535).
options lockd nlm_udpport=32769
#
# Set the maximum number of outstanding connections 
#options lockd nlm_max_connections=1024
#
# Set the default time value for the NFS lock manager
# in seconds. Default is 10 secs (min 3 max 20)
#options lockd nlm_timeout=10
#
# Choose whether to record the caller_name or IP address
# this peer in the local rpc.statd's database.
#options lockd nsm_use_hostnames=0

8、重启服务

systemctl restart rpcbind.service
systemctl restart nfs.service
systemctl restart nfs-config
systemctl restart nfs-idmap
systemctl restart nfs-lock
systemctl restart nfs-server

9、验证

rpcinfo -p

三、firewall 防火墙设置

1、 添加 nfs 规则配置

vim /etc/firewalld/services/nfs.xml

该文件是用于配置 Firewalld 防火墙服务的 NFS (Network File System) 规则的文件

<service>
  <short>nfs</short>
  <description>nfs</description>
  <port protocol="tcp" port="111"/>
  <port protocol="udp" port="111"/>
  <port protocol="tcp" port="662"/>
  <port protocol="udp" port="662"/>
  <port protocol="tcp" port="892"/>
  <port protocol="udp" port="892"/>
  <port protocol="tcp" port="2049"/>
  <port protocol="udp" port="2049"/>
  <port protocol="udp" port="32769"/>
  <port protocol="tcp" port="32803"/>
</service>

说明:
Firewalld 是 CentOS 中默认使用的动态防火墙管理工具,它通过定义服务和区域来管理网络连接的访问权限。每个服务都有一个相应的 XML 配置文件,用于指定该服务的防火墙规则。

/etc/firewalld/services/nfs.xml 文件定义了 NFS 服务的规则。NFS 是一种网络文件系统协议,允许在网络上共享文件系统。为了确保安全和控制访问,Firewalld 可以使用该文件中的规则来限制 NFS 服务的访问权限。

该 XML 文件包含以下信息:

<service> 元素:定义服务的名称和描述。
<port>元素:指定 NFS 使用的端口号或端口范围。
<protocol>元素:指定使用的协议(通常是 TCP 或 UDP)。
<module> 元素:指定 Firewalld 使用的内核模块。
<source> 元素:指定允许连接到 NFS 服务的来源 IP 地址或地址范围。
通过编辑 /etc/firewalld/services/nfs.xml 文件,你可以修改 NFS 服务的防火墙规则,例如更改允许连接的来源 IP 地址、更改使用的端口号或协议等。一旦修改完成,你需要重新加载 Firewalld 配置才能使规则生效。

2、向 firewall 添加规则

firewall-cmd --permanent --add-service=rpc-bind --zone=public 
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd --zone=public 
firewall-cmd --permanent --add-service=nfs --zone=public 

# 重新加载配置
firewall-cmd --reload 

3、手动挂载

mount -o vers=3 192.168.21.6:/home/data /data

4、 自动挂载设置

vim /etc/fstab

192.168.21.6:/home/data /data nfs defaults,vers=3 0 0

相关文章

  • CENTOS6 NFS 环境构建

    CENTOS6 NFS 环境构建 nfs server => NFS Server 搭建, CENTOS6 安装N...

  • k8s基于NFS创建Storageclass

    结果展示 搭建NFS服务器 注意:安装nfs相关软件时需要在k8s的各个节点上都要安装参考Centos7搭建NFS...

  • centos 搭建nfs

    1.nas(存储端) 10.18.41.111 2.1web1 web2客户端 10.18.41.112 ...

  • hypervlinux

    网络network,netplan vim的设置 fstab设置 nfs设置 repo安装 谷歌源 基本编译环境搭建

  • rancher 中使用NFS共享存储

    本文解释如何在Centos 7中设置NFS服务器,并且如何Rancher中使用NFS 作为共享存储。解决volum...

  • IMX6-UBOOT-从网络启动内核与文件系统

    随着前面qt环境搭建完毕,开始有空搭建TFTP&NFS启动。系统:ubuntu14 LTSVM设置:网卡设置为桥接...

  • Centos 7 搭建 NFS

    服务端搭建 客户端搭建

  • Centos7搭建nfs

    nfs文件共享服务: 服务端: yum -y install nfs-utils 安装nfs vim /etc/e...

  • CentOS 7 搭建 NFS 服务

    [TOC] 参考资料 将图片服务和应用服务分离大型网站架构 图片服务器分离Nginx服务器上搭建图片缓存服务的基本...

  • CentOS7.6配置NFS共享存储

    linux CentOS7.6 配置NFS共享存储 个人搭建博客网站的时候有个需求,想把站点做成高可用集群,说是集...

网友评论

      本文标题:centos 搭建 nfs (nfs+firewall 设置)

      本文链接:https://www.haomeiwen.com/subject/otossdtx.html