NFS(Network File System)即网络文件系统
1、RPC的功能:
记录每个NFS功能所对应端口号,并且在NFS客户端请求时将该端口和功能对应的信息传递给请求数据的NFS客户端,从而可以确保客户端可以连接到正确的NFS端口上去,达到实现数据传输交互数据的目的。
2、启动原理:
1)服务端启动rpc服务(5:portmap,6:rpcbind)
2)服务端启动nfs服务,并向rpc服务注册
3)客户端请求服务
4)服务端rpc服务返回端口给客户端rpc服务
5)开始传输数据
3、实战
1)实战准备
操作系统:
版本:
CentOS 6.6 2.6.32-504.el6.x86_64
IP地址:
nfs_server: IP:192.168.1.12
nfs_client: IP:192.168.1.13
2)服务端、客户端安装软件
服务端 [[email protected]_server ~]# yum install -y rpcbind nfs-utils 客户端 [[email protected]_client ~]# yum install -y rpcbind nfs-utils
3)启动服务端
#启动prc服务 [[email protected]_server ~]# /etc/init.d/rpcbind start Starting rpcbind: [ OK ] #进程查看rpc服务 [[email protected]_server ~]# ps -ef|grep rpcbind|grep -v grep rpc 1145 1 0 12:46 ? 00:00:00 rpcbind #查看rpc服务状态 [[email protected]_server ~]# /etc/init.d/rpcbind status rpcbind (pid 1145) is running... #查看rpc对外服务 [[email protected]_server ~]# 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 ###rpc服务停止后,rpc对外服务的报错信息 #[[email protected]_server ~]# /etc/init.d/rpcbind stop #Stopping rpcbind: [ OK ] #[[email protected]_server ~]# rpcinfo -p localhost #rpcinfo: can‘t contact portmapper: RPC: Remote system error - Connection refused #启动NFS服务 [[email protected]_server ~]# /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 ] #再次查看对外服务信息,这时nfs服务已经在rpc服务中注册 [[email protected]_server ~]# 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 54673 mountd 100005 1 tcp 59044 mountd 100005 2 udp 40168 mountd 100005 2 tcp 47027 mountd 100005 3 udp 34129 mountd 100005 3 tcp 38298 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 60276 nlockmgr 100021 3 udp 60276 nlockmgr 100021 4 udp 60276 nlockmgr 100021 1 tcp 41624 nlockmgr 100021 3 tcp 41624 nlockmgr 100021 4 tcp 41624 nlockmgr #添加开机自启动服务,及检查 [[email protected]_server ~]# chkconfig nfs on [[email protected]_server ~]# chkconfig rpcbind on [[email protected]_server ~]# chkconfig --list nfs nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off [[email protected]_server ~]# chkconfig --list rpcbind rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4)启动客户端
客户端只要启动RPC服务即可 [[email protected]_client ~]# /etc/init.d/rpcbind start Starting rpcbind: [ OK ] [[email protected]_client ~]# /etc/init.d/rpcbind status rpcbind (pid 1266) is running... [[email protected]_client ~]# chkconfig rpcbind on [[email protected]_client ~]# chkconfig --list rpcbind rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5)配置服务端
#默认配置文件是空的 [[email protected]_server ~]# cat /etc/exports #创建共享目录 [[email protected]_server ~]# mkdir /data #编辑配置文件 [[email protected]_server data]# vim /etc/exports [[email protected]_server data]# cat /etc/exports #share data for bbs by king 20150708 /data 192.168.1.0/24(rw,sync) #重新加载服务,即平滑重启 [[email protected]_server data]# /etc/init.d/nfs reload #在服务端检查服务是否正常共享 [[email protected]_server data]# showmount -e localhost Export list for localhost: /data 192.168.1.0/24
6)配置客户端
#在客户端再次检查服务是否正常共享 [[email protected]_client ~]# showmount -e 192.168.1.112 Export list for 192.168.1.112: /data 192.168.1.0/24 #开始挂载 [[email protected]_client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 8.6G 1.7G 6.5G 20% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 32M 149M 18% /boot [[email protected]_client ~]# mount -t nfs 192.168.1.112:/data /mnt [[email protected]_client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 8.6G 1.7G 6.5G 20% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 190M 32M 149M 18% /boot 192.168.1.112:/data 8.6G 1.7G 6.5G 20% /mnt #测试 在服务端查看共享目录文件 [[email protected]_server ~]# ls -l /data/ total 16 -rw-r--r-- 1 root root 56 Jul 7 19:24 2.sh -rw-r--r-- 1 root root 8 Jul 7 22:27 2.txt -rw-r--r-- 1 root root 29 Jul 7 19:56 3.txt -rw-r--r--. 1 root root 10 Jul 3 19:07 5.txt 在客户端查看挂载的目录文件 [[email protected]_client ~]# ls -l /mnt/ total 16 -rw-r--r-- 1 root root 56 Jul 7 19:24 2.sh -rw-r--r-- 1 root root 8 Jul 7 22:27 2.txt -rw-r--r-- 1 root root 29 Jul 7 19:56 3.txt -rw-r--r-- 1 root root 10 Jul 3 19:07 5.txt ###其实基本NFS服务搭建成功
7)注意事项:
(1)在共享目录里创建和删除里面的文件,需要服务端的共享目录提供权限 (2)实际服务端配置文件位置 [[email protected]_server ~]# cat /var/lib/nfs/etab /data 192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)
时间: 2024-10-14 07:56:13