设为首页 收藏本站
查看: 632|回复: 0

[经验分享] Linux系统NFS服务实战

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-9 08:58:51 | 显示全部楼层 |阅读模式
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)






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-84600-1-1.html 上篇帖子: linux实现RAID0 下篇帖子: 系统管理:查看cpu、内存、磁盘、I/O、负载、性能状态 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表