NFS网络文件系统服务实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
--------------------------------------------------------------------
可以看到已经挂到了当前的文件系统了。
本文出自 “Mr.Xiong`s 运维日志” 博客,请务必保留此出处http://mrxiong2017.blog.51cto.com/12559394/1932434
以上是关于NFS网络文件系统服务实战的主要内容,如果未能解决你的问题,请参考以下文章