NFS

简介: NFS

NFS

一、基础配置:

1、主机清单:

image.png2、网络配置:

nfs-server

[root@nfs-server ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.10"
PREFIX="24"
GATEWAY="192.168.10.254"
DNS1="114.114.114.114"

重启网络:

[root@nfs-server ~]# systemctl restart network
[root@nfs-server ~]# hostname -I
192.168.10.10

nfs-client1:

[root@nfs-client1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.10.20"
PREFIX="24"
GATEWAY="192.168.10.254"
DNS1="114.114.114.114"

重启网络:

[root@nfs-client1 ~]# systemctl restart network
[root@nfs-client1 ~]# hostname -I
192.168.10.20

二、搭建NFS服务:

1、关闭防火墙:

[root@nfs-server ~]# systemctl stop firewalld
[root@nfs-server ~]# systemctl disable firewalld

2、安装NFS

[root@nfs-server ~]# yum -y install rpcbind nfs-utils

3、启动NFS

[root@nfs-server ~]# systemctl start rpcbind nfs-server
[root@nfs-server ~]# systemctl enable rpcbind nfs-server

4、配置挂载目录:

[root@nfs-server ~]# vi /etc/exports
/mnt 192.168.10.0/24(rw,async)
/opt *(rw,async)

5、验证NFS

[root@nfs-server ~]# systemctl restart rpcbind nfs-server
[root@nfs-server ~]# showmount -e 127.0.0.1
Export list for 192.168.10.10:
/opt *
/mnt 192.168.10.0/24

三、客户端挂载:

1、安装NFS

[root@nfs-client1 ~]# yum -y install rpcbind nfs-utils

2、验证NFS:

[root@nfs-client1 ~]# showmount -e 192.168.10.10
Export list for 192.168.10.10:
/opt *
/mnt 192.168.10.0/24

3、挂载NFS:

[root@nfs-client1 ~]# mount -t nfs 192.168.10.10:/mnt /mnt
[root@nfs-client1 ~]# mount -t nfs 192.168.10.10:/opt /opt
[root@nfs-client1 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
# 省略输出
192.168.10.10:/mnt nfs4 17G 1.5G 16G 9% /mnt
192.168.10.10:/opt nfs4 17G 1.5G 16G 9% /opt

四、补充部分

1、关于放行防火墙:

查询NFS需要端口:

[root@nfs-server ~]# rpcinfo -p 127.0.0.1
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
100005 1 tcp 20048 mountd
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
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 52794 nlockmgr
100021 3 udp 52794 nlockmgr
100021 4 udp 52794 nlockmgr
100021 1 tcp 37951 nlockmgr
100021 3 tcp 37951 nlockmgr
100021 4 tcp 37951 nlockmgr

放行TCP端口:

[root@nfs-server ~]# firewall-cmd --permanent --add-port=111/tcp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=20048/tcp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=2049/tcp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=52795/tcp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=37951/tcp --permanent
[root@nfs-server ~]# firewall-cmd --reload

放行UDP端口:

[root@nfs-server ~]# firewall-cmd --permanent --add-port=111/udp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=20048/udp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=2049/udp --permanent
[root@nfs-server ~]# firewall-cmd --permanent --add-port=52795/udp --permanent
[root@nfs-server ~]# firewall-cmd --reload

查看放行端口:

[root@nfs-server ~]# firewall-cmd --list-ports

如何清空防火墙规则?

[root@nfs-server ~]# rm -rf /etc/firewalld/zones
[root@nfs-server ~]# systemctl restart firewalld

2NFS参数介绍:

ro #只读访问。
rw #读写访问。
sync #资料同步写入到内存与硬盘当中。
async #资料会先暂存于内存当中,而非直接写入硬盘。
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用户具有根目录的完全管理访问权限。

3、客户端参数优化:

mount挂载:

NFS高并发环境下的服务端重要优化(mount-o参数)。
async:异步同步,此参数会提高I/O性能,但会降低数据安全(除非对性能要求很高,对数据可靠性不要求
的场合。一般生产环境,不推荐使用)。
noatime:取消更新文件系统上的inode访问时间,提升I/O性能,优化I/O目的,推荐使用。
nodiratime:取消更新文件系统上的directoryinode访问时间,高并发环境,推荐显式应用该选项,提高
系统性能。
intr:可以中断不成功的挂载。
rsize/wsize:读取(rsize)/写入(wsize)的区块大小(blocksize),这个设置值可以影响客户端与
服务端传输数据的缓冲存储量。一般来说,如果在局域网内,并且客户端与服务端都具有足够的内存,这个值
可以设置大一点,比如说32768(bytes),提升缓冲区块将可提升NFS文件系统的传输能力。但设置的值也不
要太大,最好是实现网络能够传输的最大值为限。

内核优化:

[root@nfs-client1 ~]# vi /etc/sysctl.d/nfs.conf
net.core.wmem_default=8388608
net.core.rmem_default=8388608
net.core.rmem_max=16777216
net.core.wmem_max=16777216
[root@nfs-client1 ~]# sysctl -p /etc/sysctl.d/nfs.conf
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216


相关文章
|
3月前
|
Unix
|
12月前
|
网络安全
nfs autos
nfs autos
138 0
|
域名解析 网络协议 Unix
NFS服务器详解
NFS服务器详解
1245 0
|
存储 网络协议 Linux
NFS服务配置
NFS会经常用到,用于在网络上共享存储。这样讲,你对NFS可能不太了解,举一个例子来说明一下NFS是用来做什么的。假如有三台机器A, B, C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A, B, C. 但是使用NFS只需要放到A上,然后A共享给B和C即可。访问的时候,B和C是通过网络的方式去访问A上的那个目录的。
363 0
NFS服务配置
|
测试技术
|
Oracle 关系型数据库 网络安全
|
开发工具
nfs
1026 0