NFS挂载目录共享(整理版)

nfsserver服务器端的/etc/exports     (建议先man exports

#cat /etc/exports    
/tmp (rw,no_root_squash)
/projects       proj*.local.domain(rw)
/pub            (ro,insecure,all_squash)

目录   域名或地址(参数串)

 

/home/public/sw  *.siyongc.domain(ro,insecure)  
 
/home/public/sw这个目录分享给以 siyongc.domain这个 domain 做结尾的所有机器

/home/public/upload 192.168.0.22(rw,all_squash,anonuid=2043,anongid=2044)   
/home/public/upload这个目录只分享给 192.168.0.22这台机器

  

ro:只读
rw
:读写
insecure
:无需使用 secure port
no_root_squash
:不能以root读写
all squash:
server上写入的档案必须换成 anonymous身份进行
all_squash,anonuid=2043,anongid=2044
:将所有 anonymous换成设定的 UID GID这样的安排是要确定所有写入都按指定身份进行



    
重起nfs
[root@vm test]# /etc/init.d/nfs restart
Shutting down NFS mountd: [  OK  ]
Shutting down NFS daemon: [  OK  ]
Shutting down NFS quotas: [  OK  ]
Shutting down NFS services:  [  OK  ]
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS daemon: [  OK  ]
Starting NFS mountd: [  OK  ]


    nfs
例子

[root@vm test]# mount -t nfs localhost:/etc /mnt
mount: localhost:/etc failed, reason given by server: Permission denied
[root@vm test]# mount -t nfs localhost:/home /mnt
mount: localhost:/home failed, reason given by server: Permission denied
[root@vm test]# tail /var/log/messages
...
Jun  7 13:07:36 vm mountd[13795]: refused mount request from vm.vmmac.com for /etc (/): not exported
Jun  7 13:07:39 vm mountd[13795]: refused mount request from vm.vmmac.com for /home (/): not exported

[root@vm test]# vi /etc/exports
/etc    vm.vmmac.com(ro,insecure,all_squash)
/home   (ro,insecure,all_squash)

[root@vm test]# /etc/init.d/nfs restart
Shutting down NFS mountd: [  OK  ]
Shutting down NFS daemon: [  OK  ]
Shutting down NFS quotas: [  OK  ]
Shutting down NFS services:  [  OK  ]
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS daemon: [  OK  ]
Starting NFS mountd: [  OK  ]

[root@vm test]# mount -t nfs localhost:/home /mnt
[root@vm test]# ls /mnt
bin  mac  macg  test



    
最简单的测试NFS,试着本地往上加载一个本地目录:

[root@vm test]# mount –t nfs localhost:/home /mnt
[root@vm test]# ls /mnt
bin  mac  macg  test

也可不带-t nfs
[root@vm test]# mount localhost:/home /mnt
[root@vm test]# ls /mnt
bin  mac  macg  test




远程nfs(注意远程至少要开两台linux系统,不能开一台并分别在虚拟机上登录和putty登录工具登录,这样其实是登录同一个Ip地址的linux系统,这样的话,设置的ip和客户机的ip一样,所以设置是要注意ip地址就是server机的ip ,因为通过登录工具来登录的做client的系统和通过虚拟机本身来登录这同一台linuxserver它们的ip是样的,但是登录工具在登录后一般会提示loginXXX from ip这个ip 和你用ifconfig查到的不一样,我也不知道这个Ip 是怎么来的,但是不要以为你登录的就是这个ip其实你当前用户的ip还是 server端的那个ip!)

[root@vm macg]# mount -t nfs 10.4.1.105:/mnt/cdrom /mnt/cdrom/

[root@vm macg]# ls /mnt/cdrom
autorun            RELEASE-NOTES-bn.html     RELEASE-NOTES-U1-it.html     
EULA               RELEASE-NOTES-de.html     RELEASE-NOTES-U1-ja.html     
GPL                RELEASE-NOTES-en          RELEASE-NOTES-U1-ko.html     
images             RELEASE-NOTES-en.html     RELEASE-NOTES-U1-pa.html     
isolinux           RELEASE-NOTES-es.html     RELEASE-NOTES-U1-pt_BR.html 



    nfs
mount point,没法umount,必须先nfs stop

[root@mm guan]# umount /mnt/cdrom

umount: /mnt/cdrom: device is busy
umount: /mnt/cdrom: device is busy

[root@mm guan]# /etc/init.d/nfs stop
Shutting down NFS mountd: [  OK  ]
Shutting down NFS daemon: [  OK  ]
Shutting down NFS quotas: [  OK  ]
Shutting down NFS services:  [  OK  ]

[root@mm guan]# umount /mnt/cdrom
 



   
几个nfs错误提示
   RPC: Program not registered
错误,说明NFSSERVER没起
   RPC
portmapservice管的,NFS启动时会自动起portmap

# mount localhost:/etc/ /export/mounttest
nfs mount: localhost: : RPC: Program not registered
nfs mount: retrying: /export/mounttest

  reasongiven by server: Permission denied,说明目录没export

[root@vm test]# mount -t nfs localhost:/etc /mnt
mount: localhost:/etc failed, reason given by server: Permission denied



NFS
访问远程文件,也有权限问题,文件的所属usergroup id在两台主机上必须相同


amd            linux
自动加载器(Automounter
automounter,
是一个daemon.
Linux
常用的automounter称为amd。当前的版本是amd-5.3
它能自动地和透明地加载任何需要的NFS卷,并且在一定时间没有用到时自动卸载它们
automounter
的一个聪明之处是它可以从另外一个地方加载某个卷。
例如,你可能在两到三台主机上保存有你的程序和拷贝,使用automounter,你可以指定加载所有这三个到/mnt/usr上;此时automounter将尝试加载其中任何一个,直到有一个加载尝试成功。


你可能感兴趣的:(Linux)