NFS网络文件系统服务实战(六)

NFS网络文件系统服务实战:

一、按要求搭建配置NFS服务前准备

准备三个服务器或虚拟机A、B、C配置NFS服务器:

要求:

  • 在NFS服务端A上共享/data/w_shared及/data/r_shared两个文件目录,允许从NFS客户端B,C上分别挂载共享目录后可实现从B,C上只读/data/r_shared,可写/data/w_shared
  • NFS客户端B上的挂载点为/data/b_w(写),/data/b_r(读)

NFS客户端C上的挂载点为/data/w_你的名字英文(写),/data/r_你的名字英文(读)

3)从NFS客户端B上的NFS可在挂载点目录创建任意文件,从C上可以删除这个创建的文件,反之也可以。

解答:

1.、系统环境准备


服务器系统


角色


IP


Centos64-130-server


NFS服务器A


192.168.221.130


Centos64-131-client


NFS客户端B


192.168.221.131


Centos58-133-client


NFS客户端C


192.168.221.133

主机名或规范:

nfs-A-C64  192.168.221.130

nfs-B-C64   192.168.221.131

nfs-C-C58  192.168.221.133

2.临时关闭selinux和iptables防火墙(将来工作中selinux可关,有外部ip的服务器要开iptables。)

关闭selinux

★修改配置文件需要重启机器:

修改/etc/selinux/config 文件

vim /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled

或者:

sed -i‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config      #修改配置文件永久生效,但必须重启系统

★清空iptables

iptables -F    #清理防火墙规则

iptables -L    #查看防火墙规则

/etc/init.d/iptables save  #保存防火墙配置信息

3.查看系统环境:

分别使用cat /etc/redhat-release

uname -n

uname -a

查看系统版本和内核版本,系统名等相关信息,

使用ifconfig分别查看A,B,C三台虚拟机的ip

二、NFS服务端配置

1.开启nfs 相关服务NFS和rpcbind(C5.8portmap),并设置开机自启动

★安装rpcbind (C5.8 portmap)

[[email protected] ~]# yum install rpcbind  nfs-utils –y

★检查启动rpcbind

[[email protected] ~]# /etc/init.d/rpcbindstatus
rpcbind is stopped
[[email protected] ~]# /etc/init.d/rpcbindstart
Starting rpcbind:                                         [  OK  ]

★检查并启动nfs

[[email protected] ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[[email protected] ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]

★设置rpcbind和nfs开机自启动,

[[email protected] ~]# echo "#NFS sharedat mrxiong to 2017.6.5">>/etc/rc.local
[[email protected] ~]# echo "/etc/init.d/rpcbindstart">>/etc/rc.local       
[[email protected] ~]# echo "/etc/init.d/nfsstart">>/etc/rc.local     
[[email protected] ~]# tail -3 /etc/rc.local
#NFS shared at Mrxiong to 2017.6.5
/etc/init.d/rpcbind start
/etc/init.d/nfs start

注:rpcbind一定要先于nfs启动

2.统一所有服务器的nfs共享用户,一般是nfsnobodyuid是65534。当然也可以自己创建一个NFS共享用户

[[email protected] ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin
[[email protected] ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin
[[email protected] ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin

3.配置nfs服务端

★创建要共享的目录

 [[email protected]~]# mkdir -p /data/w_shared /data/r_shared

★根据需求授权指定权限(不要777,太大)

[[email protected] ~]# chown -R nfsnobody.nfsnobody /data/w_shared/data/r_shared
[[email protected] ~]# ls -ld /data/*
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jan 19 22:25 /data/r_shared
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Jan 19 22:25 /data/w_shared

★配置NFS配置文件/etc/exports

[[email protected] ~]# echo "#NFS shared at dingjian 2017.6.5">>/etc/exports    
[[email protected] ~]# echo "/data/w_shared 192.168.221.1/24(rw,sync)">>/etc/exports
[[email protected] ~]# echo"/data/r_shared 192.168.221.1/24(ro,sync)">>/etc/exports [[email protected]~]# tail -3 /etc/exports
#NFS shared at dingjian 2017.6.5
/data/w_shared 192.168.221.1/24(rw,sync)
/data/r_shared 192.168.221.1/24(ro,sync)

★平滑重启reload或exportfs -rv

[[email protected] ~]# exportfs -rv
exporting 192.168.221.1/24:/data/r_shared
exporting 192.168.221.1/24:/data/w_shared

★showmount -elocalhost 一下看配置有没有成功

[[email protected] ~]#  showmount -e localhost
Export list for localhost:
/data/r_shared 192.168.221.1/24
/data/w_shared 192.168.221.1/24

:配置客户端

.配置nfs-B-C64,客户端

★安装和开启rpcbind(C5.8为portmap)服务,并加入到开机自启动rc.local (不需要开启nfs服务)

C64-B

[[email protected] ~]# yum install rpcbind -y
[[email protected] ~]# /etc/init.d/rpcbindstatus
rpcbind is stopped
[[email protected] ~]# /etc/init.d/rpcbindstart
Starting rpcbind:                                         [  OK  ]
[[email protected] ~]# /etc/init.d/rpcbindstatus
rpcbind (pid  1607) is running...

★创建挂载点,然后执行showmount命令查看挂载信息,如果不通可以使用ping ip或telnet ip port来检查

C64-B

[[email protected] ~]# mkdir /data/b_w/data/b_r -p
[[email protected] ~]# ls -l /data
total 8
drwxr-xr-x. 2 root root 4096 Jan 19 22:36b_r
drwxr-xr-x. 2 root root 4096 Jan 19 22:36b_w
[[email protected] ~]# showmount -e192.168.221.130   ----->提示找不到这个命令
-bash: showmount: command not found
[[email protected] ~]# yum install showmount-y
[[email protected] ~]# showmount -e192.168.221.130
Export list for 192.168.221.130:
/data/r_shared 192.168.221.1/24
/data/w_shared 192.168.221.1/24

★通过mount命令执行挂载

C64-B

[[email protected] ~]#  mount -t nfs 192.168.221.130:/data/w_shared/data/b_w 
[[email protected] ~]#  mount -t nfs 192.168.221.130:/data/r_shared/data/b_r

★配置mount挂载命令使开机自启动

a./etc/rc.local里。缺点:偶尔开机挂载不上,工作中对其监控挂载点

[[email protected] b_w]# echo "mount -tnfs 192.168.221.130:/data/w_shared /data/b_w">>/etc/rc.local
[[email protected] b_w]# echo "mount-t nfs 192.168.221.130:/data/r_shared /data/b_r">>/etc/rc.local
[[email protected] b_w]# tail -2 /etc/rc.local
mount -t nfs 192.168.1.121:/data/w_shared /data/b_w
mount -t nfs 192.168.1.121:/data/r_shared /data/b_r

.配置nfs-C-C64,客户端

C58-C

[[email protected]~]# /etc/init.d/portmap status
portmap (pid 2656)is running...
[[email protected] ~]# mkdir /data/w_dingjian/data/r_dingjian -p
[[email protected] ~]# ls -l /data
total 8
drwxr-xr-x 2 root root 4096 Jan 19 22:38r_dingjian
drwxr-xr-x 2 root root 4096 Jan 19 22:38w_dingjian
[[email protected] ~]# showmount -e192.168.221.130
Export list for 192.168.221.130:
/data/r_shared 192.168.221.1/24
/data/w_shared 192.168.221.1/24

C58-C

[[email protected] ~]# mount -t nfs 192.168.221.130:/data/r_shared/data/r_dingjian
[[email protected] ~]# mount -t nfs 192.168.221.130:/data/w_shared/data/w_dingjian

★配置mount挂载命令使开机自启动

/etc/rc.local里。缺点:偶尔开机挂载不上,工作中对其监控挂载点

[[email protected] ~]# echo " mount -tnfs 192.168.221.130:/data/r_shared /data/r_dingjian
">>/etc/rc.local
[[email protected] ~]#echo " mount -t nfs192.168.221.130:/data/w_shared /data/w_dingjian
">>/etc/rc.local
[[email protected] ~]#  tail -2 /etc/rc.local
mount -t nfs 192.168.221.130:/data/r_shared/data/r_dingjian
mount -t nfs 192.168.221.130:/data/w_shared/data/w_dingjian

四、使用df-h或者cat /proc/mounts查看挂载情况

C64-B

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.4G  16G   9% /
tmpfs                 491M     0 491M   0% /dev/shm
/dev/sda1             190M   27M 153M  15% /boot
192.168.221.130:/data/w_shared
                       19G  1.4G  17G   8% /data/b_w
192.168.221.130:/data/r_shared
                       19G  1.4G  17G   8% /data/b_r

C58-C

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  2.1G  15G  13% /
/dev/sda1             198M   13M 176M   7% /boot
tmpfs                 499M     0 499M   0% /dev/shm
192.168.221.130:/data/r_shared
                       19G  1.4G  17G   8% /data/r_dingjian
192.168.221.130:/data/w_shared
                       19G  1.4G  17G   8% /data/w_dingjian

★根据要求做实际测试检查

分别对应要求来进行读写测试

如果把mount写到/etc/fstab里。缺点:NFS服务器端处不可用状态时,那么客户端开机可能会导致无法启动的风险。Fstab最后两列,要设置0 0。工作中对监控挂载点

个人建义使用/etc/rc.local

察看挂载后的状态。

[[email protected] ~]# mount |grep‘\<nfs\>‘
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
192.168.221.130:/data/w_shared on /data/b_wtype nfs (rw,vers=4,addr=192.168.221.130,clientaddr=192.168.221.131)
192.168.221.130:/data/r_shared on /data/b_rtype nfs (rw,vers=4,addr=192.168.221.130,clientaddr=192.168.221.131)

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

可以看到已经挂到了当前的文件系统了。

时间: 2024-08-09 14:48:28

NFS网络文件系统服务实战(六)的相关文章

nfs网络文件系统服务介绍与实战第一部

1.NFS原理描述 什么是NFS?NFS是Network File System的缩写,它的主要功能是通过网络让不同的机器之间可以彼此共享文件或目录.NFS服务器可以允许NFS客户端将远端NFS服务器端的共享目录挂在到本地的NFS客户端中.在本地NFS客户端的机器看来,NFS服务器端共享的目录就好像是自己的磁盘分区或者目录一样. NFS一般用来存储共享视频.图片等静态数据,是当前互联网系统架构中最常用的服务之一. 2.NFS挂载结构图 图解:NFS对外共享了video这个目录,下面有两台NFS客

nfs网络文件系统服务介绍与实战第二部

本博文议程如下: 1.生产情况应用案例 2.NFS客户端可挂载的参数 3.人为模拟错误的学习方法 4.NFS在网站架构中的位置 5.NFS的优缺点 议程1.生产情况实际案例概述: 实现当多台客户端同时挂载一台NFS Server时,无论从哪个客户端写入数据,其他客户端同样可以读写,即让所有NFS客户端写入到NFS Server的文件或目录在NFS Server上的用户和组都是同一个名称nfsnobody .请给出操作步骤,并加以说明. 实现NFS服务端的/data目录共享,指定主机(自己设置),

NFS网络文件系统服务配置、验证及错误解决

NFS网络文件系统服务配置.验证及错误解决 前期准备: 1.至少准备一台服务器(nfs-server)和一台客户机(nfs-client).老表测试用的服务器端用的系统是ubuntu,客户机用的是CentOS 6.5,所以有些地方操作不一样. 2.给两台测试机都安装NFS服务和rpc服务.(一般安装NFS服务会自动安装rpc) 安装: ubuntu:sudo apt-get install nfs-kernel-server CentOS:yum groupinstall "NFS file s

Centos 7 nfs网络文件系统服务的安装

实验环境>>>>>>>>> nfs服务端:(nfs-server)192.168.100.2 nfs客户端:(nfs-client)192.168.100.3 nfs的介绍>>>>>>>>>> NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定, 由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操作系统能够彼此 分享

NFS中小企业常见的网络文件系统服务(network file system)

NFS中小企业常见的网络文件系统服务(network file system) RPC服务最主要的功能就是记录每个NFS功能所对应的端口号,并在NFS客服端请求时将该端口和功能对应的信息传递个给请求数据的NFS客服端 流程: 1,先开启RPC服务 2,再启动NFS服务 3,NFS服务向RPC注册启动的端口 4,客服请求NFS服务 5,RPC返回端口给客服端 环境搭建: 服务端为 nfsserver  客服端为 nfsclient NFS服务需要安装的软件包: yum install nfs-ut

NFS 网络文件系统介绍

NFS网络文件系统介绍 什么是NFS系统? NFS是Network File System 的缩写,它的主要功能是通过网络让不同的机器系统之间可以彼此共享文件和目录.NFS服务器可以允许NFS客户端,将远端NFS服务器端的共享目录,挂载到本地NFS客户端中.(注NFS客户端一般为应用服务器如:web) NFS服务器端共享的目录就好像NFS客户端自己的磁盘分区和目录一样. 一般客户端挂载到本地目录的名字可以随便,但为方便管理,建议和服务器端一样比较好. NFS一般是用来存储共享视频.图片等静态数据

通过nfs网络文件系统启动tiny6410开发板时uboot启动参数的设置 &nbsp;

通过nfs网络文件系统启动tiny6410开发时uboot启动参数应该设置为: console=ttySAC0 lcd=S70 root=/dev/nfs nfsroot=192.168.1.30:/opt/tiny6410/fs/rootfs_mini6410 ip=192.168.1.40:192.168.1.30:192.168.1.30:255.255.255.0:tiny6410:eth0:off 注意:这里一定要指明你的lcd的类型,不然通过nfs成功启动tiny6410时,你的lc

ARM开发板搭建NFS网络文件系统方法

前边 已经提到过吧vmare的IP改成了静态IP,对于上网来说,这个是个麻烦的事.现在重新配置Vmware的IP VMware-Edit-Virtual network editor 选择PC机的无线网卡(可以上网),name:VMnet0 2.VMware-VM-Setting-Network adapter 选择custom-VMnet0 3.在ubuntu系统中编辑网络: 选择编辑连接,添加网络命名无线连接: 如图配置,然后就可以重现上网了. 配置虚拟机与ARM(am335x开发板)的NF

Linux运维之NFS网络文件系统功能介绍及应用场景

NFS网络文件系统主要功能是通过网络使不同的主机系统间可以共享文件或目录.客户端可以将NFS服务器端共享的数据目录挂载到客户端本地系统中.从客户端本地看,NFS服务器端共享的目录就好像是客户端自己的磁盘分区或目录一样,而实际上却是远端的NFS服务器的目录. NFS网络文件系统很像windows系统的网络共享.安全功能.网络驱动器映射,这也和linux系统里的Samba服务器类似.只不过一般情况下,windows网络共享服务或Samba服务用于办公局域网共享,而互联网中小型网站集群架构后端常用NF