NFS

  NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

  我写的这篇文章在我的本地vmware测试机已经测试过了,建议有需要的伙伴,在上生产环境前,先测试有没有问题。

  本次NFS挂载共享目录文件,本人以两台虚拟机为例,进行测试:

    

环境:centos6

 

服务端192.168.143.14部署配置:

安装NFS服务端: 安装nfs-utils和rpcbind

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

 

为NFS指定固定端口:

[root@localhost ~]# cat /etc/sysconfig/nfs

#

# Define which protocol versions mountd

# will advertise. The values are "no" or "yes"

# with yes being the default

#MOUNTD_NFS_V2="no"

#MOUNTD_NFS_V3="no"

#

#

# Path to remote quota server. See rquotad(8)

#RQUOTAD="/usr/sbin/rpc.rquotad"

# Port rquotad should listen on.

#RQUOTAD_PORT=875

# Optinal options passed to rquotad

#RPCRQUOTADOPTS=""

RQUOTAD_PORT=30001

LOCKD_TCPPORT=30002

LOCKD_UDPPORT=30002

MOUNTD_PORT=30003

STATD_PORT=30004

……………………..省略

 

开放防火墙中的上述端口:

[root@localhost ~]# iptables  -I INPUT -p tcp --dport 111 -j ACCEPT

es  -I INPUT -p udp --dport 30001:30004 -j ACCEPT

service iptables save

service iptables restart[root@localhost ~]# iptables  -I INPUT -p udp --dport 111 -j ACCEPT

[root@localhost ~]# iptables  -I INPUT -p tcp --dport 2049 -j ACCEPT

[root@localhost ~]# iptables  -I INPUT -p udp --dport 2049 -j ACCEPT

[root@localhost ~]# iptables  -I INPUT -p tcp --dport 30001:30004 -j ACCEPT

[root@localhost ~]# iptables  -I INPUT -p udp --dport 30001:30004 -j ACCEPT

[root@localhost ~]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

[root@localhost ~]# service iptables restart

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Unloading modules:                               [  OK  ]

iptables: Applying firewall rules:                         [  OK  ]

 

设置SELinux为许可状态:

[root@localhost ~]# cat /etc/selinux/config

 

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

 

[root@localhost ~]# getenforce

Disabled

 

 

创建共享目录:

[root@localhost ~]# mkdir /data/test

[root@localhost ~]# mkdir /data/test1

[root@localhost ~]# mkdir /data/test2

 

配置exports文件:

[root@localhost ~]# cat /etc/exports

/data/test 192.168.143.36(rw,sync,no_root_squash)

/data/test *(ro)

/data/test1 192.168.143.36(rw,sync,no_root_squash)

/data/test1 *(ro)

/data/test2 192.168.143.36(rw,sync,no_root_squash)

/data/test2 *(ro)

 

上述文件这几行表示只有192.168.143.36客户端能够以读写权限挂载共享目录,其他客户端只能以只读权限挂载。

 

 

启动NFS相关服务:

[root@localhost ~]# chkconfig nfs on

[root@localhost ~]# chkconfig rpcbind on

[root@localhost ~]# service rpcbind start

Starting rpcbind:                                          [  OK  ]

[root@localhost ~]# service nfs start

客户端192.168.143.36部署配置:

NFS客户端不需要启动NFS服务,但需要安装nfs-utils.

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

 

手动挂载NFS共享目录:

       确定挂载点:

       [root@localhost ~]# showmount -e 192.168.143.14

Export list for 192.168.143.14:

/data/test2 (everyone)

/data/test1 (everyone)

/data/test  (everyone)

 

       创建挂载目录:

[root@localhost ~]# mkdir /data/test -p

[root@localhost ~]# mkdir /data/test1 -p

[root@localhost ~]# mkdir /data/test2 –p

 

挂载共享目录:

[root@localhost ~]# mount -t nfs 192.168.143.14:/data/test /data/test

[root@localhost ~]# mount -t nfs 192.168.143.14:/data/test1 /data/test1

[root@localhost ~]# mount -t nfs 192.168.143.14:/data/test2 /data/test2

 

 

共享目录使用结束之后,卸载共享目录:umount 共享目录

  

posted on   永远的大空翼  阅读(362)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示