搭建nfs共享存储服务之一nfs服务端搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建nfs共享存储服务之一nfs服务端搭建相关的知识,希望对你有一定的参考价值。
NFS相当于房源,RPC相当于中介。
nfs-utils: NFS服务的主程序,包括rpc.nfsd、rpc.mountd这两个daemon和相关文件说明,以及执行命令文件等。
rpcbind: centos6.x下面RPC的主程序。NFS可以视为一个RPC程序,在启动任何一个RPC程序之前,需要做好端口和功能的对应映射工作,这个映射工作就是由rpcbind服务来完成的。因此,在提供NFS服务之前必须先启动rpcbind服务才行。
1.查看NFS软件包 :
可使用如下命令查看默认情况下centos6里NFS软件的安装情况
[[email protected] ~]# rpm -qa nfs-utils rpcbind #这个不用管道的命令更有效率
[[email protected] ~]#
vi /etc/yum.conf中把keepcache=0设置为keepcache=1意思是yum安装后不删除安装包。
当不知道软件名字时候,可以用rpm -aq |grep -E "nfs-|rpcbind"来过滤包含在引号内的字符串。grep -E在这里相当于egrep。grep、egrep这两个命令在运维工作中非常常用并且很好用。
先安装基础软件
[[email protected] ~]# yum install lrzsz nmap tree dos2unix nc -y
[[email protected] ~]#yum update或者yum upgrade两个至少要执行一个,相当于打补丁。
用yum安装nfs和rpc两个程序
[[email protected] ~]# yum install nfs-utils rpcbind -y
安装完成后可以看到rpm软件包没有被删除
[[email protected] ~]# tree /var/cache/yum/x86_64/6/base/packages/
/var/cache/yum/x86_64/6/base/packages/
|-- dos2unix-3.1-37.el6.x86_64.rpm
|-- keyutils-1.4-5.el6.x86_64.rpm
|-- libevent-1.4.13-4.el6.x86_64.rpm
|-- libgssglue-0.1-11.el6.x86_64.rpm
|-- lrzsz-0.12.20-27.1.el6.x86_64.rpm
|-- nc-1.84-24.el6.x86_64.rpm
|-- nfs-utils-1.2.3-75.el6.x86_64.rpm
|-- nfs-utils-lib-1.1.5-13.el6.x86_64.rpm
|-- nmap-5.51-6.el6.x86_64.rpm
`-- tree-1.5.3-3.el6.x86_64.rpm
用tar zcvf打包把/var/cache/yum/x86_64/6/base/packages/目录打包成nfs-rpm.tar.gz文件
[[email protected] ~]# tar zcvf nfs-rpm.tar.gz /var/cache/yum/x86_64/6/base/packages/
tar: Removing leading `/‘ from member names
/var/cache/yum/x86_64/6/base/packages/
/var/cache/yum/x86_64/6/base/packages/nfs-utils-lib-1.1.5-13.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/keyutils-1.4-5.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/nfs-utils-1.2.3-75.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/nc-1.84-24.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/libevent-1.4.13-4.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/libgssglue-0.1-11.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/tree-1.5.3-3.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/dos2unix-3.1-37.el6.x86_64.rpm
/var/cache/yum/x86_64/6/base/packages/nmap-5.51-6.el6.x86_64.rpm
/>rz
zmodem ° Ctrl+C
100% 3425 KB 3425 KB/s 00:00:01 0 Errors
2.启动NFS相关服务
启动rpcbind服务。
因为NFS及其辅助程序都是属于RPC(Remote Procedure CAll)协议的(使用的端口111),所以首先要确保系统运行了rpcbind服务。
启动rpc服务器:
[[email protected] ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
查看rpc服务对应的端口是111
[[email protected] ~]# netstat -lntup |grep rpc
tcp 0 0 0.0.0.0:111 &a 0.0.0.0:* LISTEN 2020/rpcbind
tcp 0 0 :::111 :::* LISTEN 2020/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 2020/rpcbind
udp 0 0 0.0.0.0:923 0.0.0.0:* 2020/rpcbind
udp 0 0 :::111 :::* 2020/rpcbind
udp 0 0 :::923 :::* 2020/rpcbind
[[email protected] ~]#
查看是否有房源
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmappe
启动nfs,相当于向rpc注册房源
[[email protected] ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
再看中介有没有房
[[email protected] ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100005 1 udp 34914 mountd
100005 1 tcp 43493 mountd
100005 2 udp 50054 mountd
100005 2 tcp 48624 mountd
100005 3 udp 37236 mountd
100005 3 tcp 39378 mountd
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100227 3 tcp 2049 nfs_acl
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 2 udp 2049 nfs_acl
100227 3 udp 2049 nfs_acl
100021 1 udp 45751 nlockmgr
100021 3 udp 45751 nlockmgr
100021 4 udp 45751 nlockmgr
100021 1 tcp 44021 nlockmgr
100021 3 tcp 44021 nlockmgr
100021 4 tcp 44021 nlockmgr
nfs主端口2049是不变的,rpc主端口是111
所有的进程都会对应一个用户,yum安装后就会自动创建
[[email protected] ~]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)
假设把rpc服务停了,就找不到nfs了。
[[email protected] ~]# /etc/init.d/rpcbind stop
Stopping rpcbind: [ OK ]
[[email protected] ~]# rpcinfo -p localhost
rpcinfo: can‘t contact portmapper: RPC: Remote system error - Connection refused
这时启动nfs就会报错
[[email protected] ~]# /etc/init.d/nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS quotas: [ OK ]
Shutting down RPC idmapd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]
刚刚只是测试而已,还是要启动rpcbind的
执行命令启用rcpbind
/etc/init.d/rpcbind srart
启动nfs服务
/etc/init.d/nfs srart
在到rpcbind查看是否有nfs
rpcinfo -p localhost
2.2设置开机启动
[[email protected] ~]# chkconfig nfs on
[[email protected] ~]# chkconfig rpcbind on
查看启动先后顺序:grep -E
[[email protected] ~]# ls /etc/rc.d/rc3.d/|grep -E "nfs|rpc"
K61nfs-rdma
K69rpcsvcgssd
S13rpcbind
S14nfslock
S19rpcgssd
S30nfs
[[email protected] ~]# head /etc/init.d/nfs
#!/bin/sh
#
# nfs This shell script takes care of starting and stopping
# the NFS services.
#
# chkconfig: - 30 60
# description: NFS is a popular protocol for file sharing across networks.
# This service provides NFS server functionality, which is \
# configured via the /etc/exports file.
# probe: true
运行NFS服务默认需要启动的服务或者进程至少有:NFS quotas(rpc.rquotad)、NFS daemon(nfsd)、NFS mountd(rpc.mountd)。可以通过执行如下命令查看启动NFS后,系统中运行的NFS相关进程。
[[email protected] ~]# ps -ef|egrep "nfs|rpc"
root 2080 2 0 12:35 ? 00:00:00 [rpciod/0]
root 2081 2 0 12:35 ? 00:00:00 [rpciod/1]
rpc 2499 1 0 12:47 ? 00:00:00 rpcbind
root 2567 1 0 12:49 ? 00:00:00 rpc.rquotad
root 2572 1 0 12:49 ? 00:00:00 rpc.mountd
root 2579 2 0 12:49 ? 00:00:00 [nfsd4]
root 2580 2 0 12:49 ? 00:00:00 [nfsd4_callbacks]
root 2581 2 0 12:49 ? 00:00:00 [nfsd]
root 2582 2 0 12:49 ? 00:00:00 [nfsd]
root 2583 2 0 12:49 ? 00:00:00 [nfsd]
root 2584 2 0 12:49 ? 00:00:00 [nfsd]
root 2585 2 0 12:49 ? 00:00:00 [nfsd]
root 2586 2 0 12:49 ? 00:00:00 [nfsd]
root 2587 2 0 12:49 ? 00:00:00 [nfsd]
root 2588 2 0 12:49 ? 00:00:00 [nfsd]
root 2619 1 0 12:49 ? 00:00:00 rpc.idmapd
root 2693 2677 0 13:01 pts/0 00:00:00 egrep nfs|rpc
NFS服务端总结:
1.打印系统版本
cat /etc/redhat-release
uname -r
uname -m
2.检查并安装NFS服务
rpm -qa nfs-utils rpcbind
LANG=en
yum install nfs-utils rpcbind
rpm -qa nfs-utils rpcbind
3.启动RPC及服务并检查
/etc/init.d/rpcbind start
ps -ef |grep rpc
/etc/init.d/rpcbind status
rpcinfo -p localhost
/etc/init.d/nfs start
rpcinfo -p localhost
4.设置开机自启动并检查
chkconfig nfs on
chkconfig rpcbind on
chkconfig --list nfs
chkconfig --list rpcbind
5.配置共享/data目录
cat >>/etc/exports<<EOF
#shared data for bbs by jeremy at 20170806
/data 172.16.1.0/24(rw,sync)
EOF
cat /etc/exports
6.创建共享目录
mkdir /data
ll /data
chown -R nfsnobody.nfsnobody /data
cat /var/lib/nfs/etab 参看配置参数
7.平滑加载NFS服务并检查服务。
/etc/init.d/nfs raload (相当于exports -rv)
showmount -e localhost
showmount -e 172.16.1.31
mount -t nfs 172.16.1.31:/data /mnt
umount /mnt
本文出自 “sandshell” 博客,请务必保留此出处http://sandshell.blog.51cto.com/9055959/1953976
以上是关于搭建nfs共享存储服务之一nfs服务端搭建的主要内容,如果未能解决你的问题,请参考以下文章