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 共享目录

  

原文地址:https://www.cnblogs.com/renyongbin/p/7987971.html