计算机系统应用教程网站

网站首页 > 技术文章 正文

NFS共享文件服务器搭建

btikc 2024-09-24 08:24:25 技术文章 20 ℃ 0 评论

简介

NFS ,Network File System的缩写,即网络文件系统。功能:可以通过网络进程文件共享。


环境准备:

1、操作系统为Centos 6.8

2、rpc服务、nfs服务

3、服务器

NFS服务器(双节点,这里只配一个节点):A

WEB服务器(双节点):B

数据中心服务器(双节点):C

A作为文件共享服务器,C生成的数据文件可以写到A,B可以从A进行文件查询、下载。


一、服务端(A):

1、检查服务必要的服务是否已安装。如果没安装则需要安装并且启动。

命令:rpm -qa |grep -i -E 'rpc|nfs'

实操:

[root@localhost etc]# rpm -qa |grep -i nfs

nfs-utils-1.2.3-78.el6.x86_64

nfs-utils-lib-1.1.5-13.el6.x86_64

[root@localhost etc]# yum install rpcbind

已加载插件:fastestmirror

设置安装进程

Loading mirror speeds from cached hostfile

包 rpcbind-0.2.0-16.el6.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost etc]# netstat -an|grep 2049

[root@localhost etc]# service nfs status

rpc.svcgssd 已停

rpc.mountd 已停

nfsd 已停

[root@localhost etc]# service rpc status

rpc: 未被识别的服务

[root@localhost etc]# service rpcbind status

rpcbind 已停

[root@localhost etc]# service rpcbind restart

停止 rpcbind: [失败]

正在启动 rpcbind: [确定]

[root@localhost etc]# service rpcbind status

rpcbind (pid 45196) 正在运行...

[root@localhost etc]#

[root@localhost etc]#

[root@localhost etc]# netstat -an|grep 2049

[root@localhost etc]#

[root@localhost etc]# service nfs start

启动 NFS 服务: exportfs: duplicated export entries:

exportfs: 10.98.201.16/255.255.255.0:/data/app/data-center/nfsfiles

exportfs: 10.98.201.16/255.255.255.0:/data/app/data-center/nfsfiles

[确定]

启动 NFS mountd: [确定]

启动 NFS 守护进程: [确定]

正在启动 RPC idmapd: [确定]

[root@localhost etc]#

[root@localhost etc]# netstat -an|grep 2049

tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN

tcp 0 0 :::2049 :::* LISTEN

udp 0 0 0.0.0.0:2049 0.0.0.0:*

udp 0 0 :::2049 :::*

[root@localhost etc]#

[root@localhost etc]#

2、配置exports

命令:vi /etc/exports

实操:

[root@localhost ~]$ vi /etc/exports

/data/app/data-center/nfsfiles 10.98.201.16/255.255.255.0(rw,no_root_squash,sync)

/data/app/data-center/nfsfiles 10.98.201.17/255.255.255.0(rw,no_root_squash,sync)

/data/app/data-center/nfsfiles 10.255.80.116/255.255.255.0(rw,all_squash,sync)

/data/app/data-center/nfsfiles 10.255.80.117/255.255.255.0(rw,all_squash,sync)

[root@localhost ~]$


二、客户端(C):

1、数据中心(data)节点,读写权限。本地的目录需要与配置中心的一致。譬如,配置中心配置的是 nfsfiles ,如下

#配置中心的导出文件路径

boxByLfsPath = nfsfiles

1)、C-节点1:10.98.201.16

命令:

mkdir -p ~/gnete-datasc-itfs-biz/datasc_file

mount -t nfs 10.211.201.91:/data/app/data-center/nfsfiles ~/gnete-datasc-itfs-biz/nfsfiles -o nolock

touch test.txt

实操:

[root@localhost ~]# mount -t nfs 10.211.201.91:/data/app/data-center/nfsfiles /home/app/data/datasc_file -o nolock

mount: wrong fs type, bad option, bad superblock on 10.211.201.91:/data/app/data-center/nfsfiles,

missing codepage or helper program, or other error

(for several filesystems (e.g. nfs, cifs) you might

need a /sbin/mount.<type> helper program)

In some cases useful info is found in syslog - try

dmesg | tail or so

[root@localhost ~]#

[root@localhost ~]# service nfs status

nfs: 未被识别的服务

[root@localhost ~]#

[root@localhost ~]# rpm -qa|grep -i nfs

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

已加载插件:fastestmirror

设置安装进程

Determining fastest mirrors

base | 4.0 kB 00:00

解决依赖关系

--> 执行事务检查

---> Package nfs-utils.x86_64 1:1.2.3-78.el6 will be 安装

--> 处理依赖关系 nfs-utils-lib >= 1.1.0-3,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libtirpc >= 0.2.1-11,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 keyutils >= 1.4-4,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 rpcbind,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 python-argparse,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libgssglue.so.1(libgssapi_CITI_2)(64bit),它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libgssglue,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libevent,它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libtirpc.so.1()(64bit),它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libnfsidmap.so.0()(64bit),它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libgssglue.so.1()(64bit),它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 处理依赖关系 libevent-1.4.so.2()(64bit),它被软件包 1:nfs-utils-1.2.3-78.el6.x86_64 需要

--> 执行事务检查

---> Package keyutils.x86_64 0:1.4-5.el6 will be 安装

---> Package libevent.x86_64 0:1.4.13-4.el6 will be 安装

---> Package libgssglue.x86_64 0:0.1-11.el6 will be 安装

---> Package libtirpc.x86_64 0:0.2.1-15.el6 will be 安装

---> Package nfs-utils-lib.x86_64 0:1.1.5-13.el6 will be 安装

---> Package python-argparse.noarch 0:1.2.1-2.1.el6 will be 安装

---> Package rpcbind.x86_64 0:0.2.0-16.el6 will be 安装

--> 完成依赖关系计算

依赖关系解决

============================================================================================================================================================================================================================================

软件包 架构 版本 仓库 大小

============================================================================================================================================================================================================================================

正在安装:

nfs-utils x86_64 1:1.2.3-78.el6 base 336 k

为依赖而安装:

keyutils x86_64 1.4-5.el6 base 39 k

libevent x86_64 1.4.13-4.el6 base 66 k

libgssglue x86_64 0.1-11.el6 base 23 k

libtirpc x86_64 0.2.1-15.el6 base 82 k

nfs-utils-lib x86_64 1.1.5-13.el6 base 71 k

python-argparse noarch 1.2.1-2.1.el6 base 48 k

rpcbind x86_64 0.2.0-16.el6 base 51 k

事务概要

============================================================================================================================================================================================================================================

Install 8 Package(s)

总下载量:716 k

Installed size: 2.0 M

下载软件包:

(1/8): rpcbind-0.2.0-16.el6.x86_64.rpm | 51 kB 00:00

(2/8): keyutils-1.4-5.el6.x86_64.rpm | 39 kB 00:00

(3/8): libevent-1.4.13-4.el6.x86_64.rpm | 66 kB 00:00

(4/8): nfs-utils-1.2.3-78.el6.x86_64.rpm | 336 kB 00:00

(5/8): nfs-utils-lib-1.1.5-13.el6.x86_64.rpm | 71 kB 00:00

(6/8): libtirpc-0.2.1-15.el6.x86_64.rpm | 82 kB 00:00

(7/8): python-argparse-1.2.1-2.1.el6.noarch.rpm | 48 kB 00:00

(8/8): libgssglue-0.1-11.el6.x86_64.rpm | 23 kB 00:00

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

总计 19 MB/s | 716 kB 00:00

运行 rpm_check_debug

执行事务测试

事务测试成功

执行事务

正在安装 : libgssglue-0.1-11.el6.x86_64 1/8

正在安装 : libtirpc-0.2.1-15.el6.x86_64 2/8

正在安装 : rpcbind-0.2.0-16.el6.x86_64 3/8

正在安装 : python-argparse-1.2.1-2.1.el6.noarch 4/8

正在安装 : libevent-1.4.13-4.el6.x86_64 5/8

正在安装 : keyutils-1.4-5.el6.x86_64 6/8

正在安装 : nfs-utils-lib-1.1.5-13.el6.x86_64 7/8

正在安装 : 1:nfs-utils-1.2.3-78.el6.x86_64 8/8

Verifying : rpcbind-0.2.0-16.el6.x86_64 1/8

Verifying : keyutils-1.4-5.el6.x86_64 2/8

Verifying : libevent-1.4.13-4.el6.x86_64 3/8

Verifying : 1:nfs-utils-1.2.3-78.el6.x86_64 4/8

Verifying : nfs-utils-lib-1.1.5-13.el6.x86_64 5/8

Verifying : libtirpc-0.2.1-15.el6.x86_64 6/8

Verifying : python-argparse-1.2.1-2.1.el6.noarch 7/8

Verifying : libgssglue-0.1-11.el6.x86_64 8/8

已安装:

nfs-utils.x86_64 1:1.2.3-78.el6

作为依赖被安装:

keyutils.x86_64 0:1.4-5.el6 libevent.x86_64 0:1.4.13-4.el6 libgssglue.x86_64 0:0.1-11.el6 libtirpc.x86_64 0:0.2.1-15.el6 nfs-utils-lib.x86_64 0:1.1.5-13.el6 python-argparse.noarch 0:1.2.1-2.1.el6 rpcbind.x86_64 0:0.2.0-16.el6

完毕!

[root@localhost ~]# mount -t nfs 10.211.201.91:/data/app/data-center/nfsfiles /home/app/data/datasc_file -o nolock

[root@localhost ~]#

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

46G 2.7G 41G 7% /

tmpfs 1.9G 0 1.9G 0% /dev/shm

/dev/sda1 477M 39M 413M 9% /boot

10.211.201.91:/data/app/data-center/nfsfiles

538G 2.5G 509G 1% /home/app/data/datasc_file

[root@localhost ~]#

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

46G 2.7G 41G 7% /

tmpfs 1.9G 0 1.9G 0% /dev/shm

/dev/sda1 477M 39M 413M 9% /boot

10.211.201.91:/data/app/data-center/nfsfiles

538G 2.5G 509G 1% /home/app/data/datasc_file

[root@localhost ~]# su - app

[app@localhost datasc_file]#cd /home/app/data/datasc_file

[app@localhost datasc_file]#

[app@localhost datasc_file]# touch test.txt

ls -lrt

总用量 0

-rw-rw-r--. 1 app app 0 2月 14 23:33 test.txt

[app@localhost datasc_file]#

2)、C-节点2:10.98.201.17

命令、操作与节点1相同


三、客户端(B):

1、该节点的权限为只读。本地的目录需要与配置中心的一致。譬如,配置中心配置的是datasc_file,如下

#下载交易明细文件使用目录

testFileRemotePath = datasc_file/

testFileLocalTempPath = temp/

1)、B-节点1:10.255.80.116

命令:

mkdir -p ~/aix-web/datasc_file

mount -t nfs -o nolock 10.211.201.91:/data/app/data-center/nfsfiles ~/aix-web/datasc_file

实操:

[root@localhost datasc_file]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

46G 2.6G 41G 6% /

tmpfs 1.9G 0 1.9G 0% /dev/shm

/dev/sda1 477M 39M 413M 9% /boot

10.211.201.91:/data/app/data-center/nfsfiles

538G 2.5G 509G 1% /home/app/aix-web/datasc_file

[root@localhost datasc_file]#

[root@localhost datasc_file]# pwd

/home/app/gnete-msc-web/datasc_file

[root@localhost datasc_file]#

[root@localhost datasc_file]# touch data.txt

touch: 无法创建"data.txt": 权限不够

[root@localhost datasc_file]#

2)、B-节点2:10.255.80.117

节点2操作与节点1相同

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表