首页 > 编程知识 正文

centos7搭建nfs详细步骤(Centos下nfs rpcbind实现服务器之间的文件共享)

时间:2023-05-03 06:48:47 阅读:123507 作者:1323

这里的服务器环境为Centos6.8 64位,防火墙已关闭。

网络文件系统(NFS )是FreeBSD支持的文件系统之一,可以通过TCP/IP网络在网络上的计算机之间共享资源。 在NFS APP应用程序中,本地NFS客户端APP应用程序可以透明地读写位于远程NFS服务器上的文件,就像正在访问本地文件一样。

http://www.Sina.com/http://www.Sina.com /

[ root @ localhostsoftinstall ] # rpm-AQ|grep NFS [ root @ localhostsoftinstall ] # rpm-AQ|grep rpcbind 3358 www.Sina .

yum -y install nfs-utils rpcbind

安装后的检测如下

[ root @ localhostsoftinstall ] # rpm-AQ|greprpcbindrpcbind-0.2.0-16.el6.x86 _ 64 [ root @ localhostsoftinstald

此处使用/mnt/app目录。

mdir-p/mnt/app http://www.Sina.com /

命令:

vim /etc/exports将需要以下输出的目录添加到此文件中:

/mnt/app192.168.73.130(rw )/mnt/app192.168.73.131 ) rw,sync,no_root_squash, no_subtree_check ) #/mnt/app :指示NFS服务器必须与其他客户端服务器共享的文件夹#192.168.73.130 :指示服务器目录可以装载

rw :读写权限; ro :只读权限; no _ root _ squash :如果登录到NFS主机的用户是root,则该用户具有root权限。 (不添加此选项的ROOT仅限RO权限) ROOT _ squash :如果登录到NFS主机的用户是root,则用户权限限于匿名用户的nobody。 all _ squash :无论登录到NFS主机的用户具有何种权限,它都将重新设置为匿名用户nobody。 anonuid—将登录到NFS主机的所有用户设置为指定的用户id。 此id必须存在于/etc/passwd中。 Anong id :和Anonuid一样,但是到了组id就这样了! sync )数据同步写入内存。 同步:数据暂时存储在内存中,不直接写入硬盘。 insecure :允许从这台机器非法访问。 配置更新将立即生效

exportfs -r 【1】安装nfs和rpcbind

电源接通启动的设定

启动chkconfignfsonchkconfigrpcbindonrpcbind服务

服务rpcbind start将启动nsf服务

服务NFS start

查看RPC服务的注册情况

[root@localhost mnt]# PC info-plocalhostprogramversprotoportservice 100004 TCP 111 portmap per 1000003 TCP 111 portmap per 100002 TCP 111 portmap per 10000004 UDP 11 PP t mapper 100002 UDP 111 portmap per 100011 UDP 875 rquotad 100012 UDP 875 rquotad 1000111TCP 875 rquotad 100051 UDP 52791 mount d 1000000051 TCP 4294 mm TD 100052 TCP 54774 mount d 1000053 UDP 50872 mount d 100005

ntd 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 46920 nlockmgr 100021 3 udp 46920 nlockmgr 100021 4 udp 46920 nlockmgr 100021 1 tcp 39362 nlockmgr 100021 3 tcp 39362 nlockmgr 100021 4 tcp 39362 nlockmgr

检测服务状态

service nfs statusservice rpcbind status

查看服务开机启动状态

[root@localhost mnt]# chkconfig --list |grep nfsnfs 0:off 1:off 2:off 3:off 4:off 5:off 6:offnfs-rdma 0:off 1:off 2:off 3:off 4:off 5:off 6:offnfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off[root@localhost mnt]# chkconfig --list |grep rpcbindrpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off

可以手动设置服务运行级别,如下实例:

[root@localhost mnt]# chkconfig --level 2345 nfs on[root@localhost mnt]# chkconfig --list |grep nfsnfs 0:off 1:off 2:on 3:on 4:on 5:on 6:offnfs-rdma 0:off 1:off 2:off 3:off 4:off 5:off 6:offnfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off

④ 检测配置文件

如下所示,打印配置文件内容:

[root@localhost mnt]# showmount -eExport list for localhost.localdomain:/mnt/app 192.168.73.130

注意:在执行这个命令的时候如果出现错误,说明DNS不能解析当前的服务器,那就是hosts文件没有配置。

【3】客户端挂载NFS中共享的目录

① 创建本地路径(也就是挂载点)

mkdir /mnt/app

② 安装并启动nfs与rpcbind服务

yum -y install nfs-utils rpcbindchkconfig nfs onchkconfig rpcbind onservice nfs startservice rpcbind start

③ 查看服务器抛出的共享目录信息

[root@localhost ~]# showmount -e 192.168.73.129Export list for 192.168.73.129:/mnt/app 192.168.73.130

④ 挂载目录

为了提高NFS的稳定性,使用TCP协议挂载,NFS默认用UDP协议

mount -t nfs -o vers=3 192.168.73.129:/mnt/app /mnt/app -o proto=tcp -o nolock #服务器IP:服务器共享路径 本机挂载点#192.168.73.129:/mount/app /mount/app


⑤ 测试验证

服务器(192.168.73.129)创建文件:

cd /mnt/apptouch test.txt

客户机验证:

cd /mnt/appll


⑥ 取消挂载

客户机执行命令

umount /mnt/app

这里可以联想服务器挂载磁盘,设置开机挂载、取消挂载同样操作。

⑦ 查看挂载的状态

命令:

mount | grep nfs

实例:

[root@localhost app]# mount | grep nfssunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)192.168.73.129:/mnt/app on /mnt/app type nfs (rw,vers=3,proto=tcp,nolock,addr=192.168.73.129) 【4】固定nfs服务端口

NFS启动时会随机启动多个端口并向RPC注册,这样如果使用防火墙对NFS端口进行限制就会有点麻烦,可以更改配置文件固定NFS服务相关端口。

分配端口,编辑配置文件:

[root@localhost app]# vim /etc/sysconfig/nfs

添加如下(或者可以直接从配置文件里面修改):

RQUOTAD_PORT=30001 LOCKD_TCPPORT=30002 LOCKD_UDPPORT=30002 MOUNTD_PORT=30003 STATD_PORT=30004


重启nfs服务

[root@localhost app]# service nfs restartShutting down NFS daemon: [ OK ]Shutting down NFS mountd: [ OK ]Shutting down NFS quotas: [ OK ]Shutting down NFS services: [ OK ]Shutting down RPC idmapd: [ OK ]Starting NFS services: [ OK ]Starting NFS quotas: [ OK ]Starting NFS mountd: [ OK ]Starting NFS daemon: [ OK ]Starting RPC idmapd: [ OK ]

查看服务注册状态

[root@localhost app]# 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 30001 rquotad 100011 2 udp 30001 rquotad 100011 1 tcp 30001 rquotad 100011 2 tcp 30001 rquotad 100005 1 udp 30003 mountd 100005 1 tcp 30003 mountd 100005 2 udp 30003 mountd 100005 2 tcp 30003 mountd 100005 3 udp 30003 mountd 100005 3 tcp 30003 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 30002 nlockmgr 100021 3 udp 30002 nlockmgr 100021 4 udp 30002 nlockmgr 100021 1 tcp 30002 nlockmgr 100021 3 tcp 30002 nlockmgr 100021 4 tcp 30002 nlockmgr 【5】客户机设置系统开机挂载磁盘

通过修改/etc/fstab实现挂载,添加完成后执行mount –a 即刻生效。

vim /etc/fstab#添加配置如下192.168.73.129:/mnt/app /mnt/app nfs defaults 0 0


参考博文:
Linux服务管理与chkconfig命令
Linux添加硬盘并进行分区、格式化、挂载及卸载

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。