手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux下资源共享之NFS服务的搭建

[日期:2012-10-17] 来源:Linux社区  作者:gjp0731 [字体:大 中 小]

测试:

192.168.10. 0/24的客户机192.168.10.9访问

[root@mail ~]# rpcinfo –p  //先查看是否有端口映射!
  program vers proto  port
    100000    2  tcp    111  portmapper
    100000    2  udp    111  portmapper
    100024    1  udp    900  status
    100024    1  tcp    903  status
[root@mail ~]# showmount -e 192.168.10.99 //查看服务器上的共享列表
Export list for 192.168.10.99:
/public 192.168.10.0/24

创建挂载点:
[root@mail ~]# mkdir /mnt/nfs
[root@mail ~]# mount 192.168.10.99:/public /mnt/nfs //手动挂载

[root@mail ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2            9.5G  2.3G  6.7G  26% /
/dev/sda1              99M  12M  83M  12% /boot
tmpfs                506M    0  506M  0% /dev/shm
192.168.10.99:/public
                      9.5G  2.3G  6.8G  26% /mnt/nfs
[root@mail ~]# cd /mnt/nfs

[root@mail nfs]# ll  //看到服务器上的共享文件
total 4
-rw-r--r-- 1 root root 11 Aug  3 17:07 gjp

[root@mail nfs]# mount   
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.10.99:/public on /mnt/nfs type nfs (rw,addr=192.168.10.99)

如何做到开机自动挂载?

[root@mail nfs]# pwd  查看当前目录
/mnt/nfs
[root@mail nfs]# cd  离开要卸载的目录
[root@mail ~]# umount /mnt/nfs/  卸载光盘
[root@mail ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

[root@mail ~]# vim /etc/fstab

192.168.10.99:/public  /mnt/nfs                nfs    ro,soft,intr    0 0

[root@mail ~]# mount -a
[root@mail ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.10.99:/public on /mnt/nfs type nfs (ro,soft,intr,addr=192.168.10.99)

自动挂载:

[root@mail ~]# rpm -qa |grep auto
automake14-1.4p6-13
autoconf-2.59-12
automake-1.9.6-2.1
autofs-5.0.1-0.rc2.131.el5
automake17-1.7.9-7
automake15-1.5-16
automake16-1.6.3-8
[root@mail ~]# chkconfig --list |grep auto
autofs            0:off    1:off    2:off    3:on    4:on    5:on    6:off

[root@mail ~]# vim /etc/auto.master

10 /mnt/nfs  /etc/auto.nfs  --timeout=60    //1分钟之内如果没有操作,则自动挂断

[root@mail ~]# ll /etc/auto*
-rw------- 1 root root 2726 Jul 29  2009 /etc/autofs_ldap_auth.conf
-rw-r--r-- 1 root root  756 Sep  5 14:17 /etc/auto.master
-rw-r--r-- 1 root root  581 Jul 29  2009 /etc/auto.misc
-rwxr-xr-x 1 root root 1292 Jul 29  2009 /etc/auto.net
-rwxr-xr-x 1 root root  715 Jul 29  2009 /etc/auto.smb
[root@mail ~]# cp -p /etc/auto.misc /etc/auto.nfs

[root@mail ~]# vim /etc/auto.nfs

server1        -ro,soft,intr          192.168.10.99:/public

[root@mail ~]# service autofs restart    启动服务
Stopping automount:                                        [  OK  ]
Starting automount:                                        [  OK  ]
[root@mail ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
[root@mail ~]# cd /mnt/nfs
[root@mail nfs]# ll
total 0
[root@mail nfs]# cd server1  进入此目录,才可以挂载!
[root@mail server1]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.10.99:/public on /mnt/nfs/server1 type nfs (ro,soft,intr,addr=192.168.10.99)

[root@mail ~]# mount    //1分钟过后,查看挂载点消失
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

linux
相关资讯       NFS  Linux NFS配置  Linux NFS安装  Linux NFS服务 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款