|
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)服务端、客户端安装软件
1
2
3
4
| 服务端
[iyunv@nfs_server ~]# yum install -y rpcbind nfs-utils
客户端
[iyunv@nfs_client ~]# yum install -y rpcbind nfs-utils
|
3)启动服务端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| #启动prc服务
[iyunv@nfs_server ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
#进程查看rpc服务
[iyunv@nfs_server ~]# ps -ef|grep rpcbind|grep -v grep
rpc 1145 1 0 12:46 ? 00:00:00 rpcbind
#查看rpc服务状态
[iyunv@nfs_server ~]# /etc/init.d/rpcbind status
rpcbind (pid 1145) is running...
#查看rpc对外服务
[iyunv@nfs_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对外服务的报错信息
#[iyunv@nfs_server ~]# /etc/init.d/rpcbind stop
#Stopping rpcbind: [ OK ]
#[iyunv@nfs_server ~]# rpcinfo -p localhost
#rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused
#启动NFS服务
[iyunv@nfs_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服务中注册
[iyunv@nfs_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
#添加开机自启动服务,及检查
[iyunv@nfs_server ~]# chkconfig nfs on
[iyunv@nfs_server ~]# chkconfig rpcbind on
[iyunv@nfs_server ~]# chkconfig --list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[iyunv@nfs_server ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
4)启动客户端
1
2
3
4
5
6
7
8
| 客户端只要启动RPC服务即可
[iyunv@nfs_client ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[iyunv@nfs_client ~]# /etc/init.d/rpcbind status
rpcbind (pid 1266) is running...
[iyunv@nfs_client ~]# chkconfig rpcbind on
[iyunv@nfs_client ~]# chkconfig --list rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
5)配置服务端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #默认配置文件是空的
[iyunv@nfs_server ~]# cat /etc/exports
#创建共享目录
[iyunv@nfs_server ~]# mkdir /data
#编辑配置文件
[iyunv@nfs_server data]# vim /etc/exports
[iyunv@nfs_server data]# cat /etc/exports
#share data for bbs by king 20150708
/data 192.168.1.0/24(rw,sync)
#重新加载服务,即平滑重启
[iyunv@nfs_server data]# /etc/init.d/nfs reload
#在服务端检查服务是否正常共享
[iyunv@nfs_server data]# showmount -e localhost
Export list for localhost:
/data 192.168.1.0/24
|
6)配置客户端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| #在客户端再次检查服务是否正常共享
[iyunv@nfs_client ~]# showmount -e 192.168.1.112
Export list for 192.168.1.112:
/data 192.168.1.0/24
#开始挂载
[iyunv@nfs_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
[iyunv@nfs_client ~]# mount -t nfs 192.168.1.112:/data /mnt
[iyunv@nfs_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
#测试
在服务端查看共享目录文件
[iyunv@nfs_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
在客户端查看挂载的目录文件
[iyunv@nfs_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
3
4
| (1)在共享目录里创建和删除里面的文件,需要服务端的共享目录提供权限
(2)实际服务端配置文件位置
[iyunv@nfs_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)
|
|
|