Linux下的nfs服务器linux
一.NFS的介绍vim
1. NFS 网络文件系统 Network File System网络文件系统,是一种将远程主机上的分区(目录)经网络挂载到本地系统的一种机制,经过对网络文件系统的支持,用户能够在本地系统上像操做本地分区同样来对远程主机的共享分区(目录)进行操做。在类unix系统之间共享资源,不须要安装软件。端口不固定,须要portmap(端口映射)提供RPC(远程过程调用)一种协议;NFS向RPC注册端口windows
优势:服务器
局域网内共享速度最快网络
缺点:async
不能跨平台共享(windows和linux系统不能共享文件,如今有第三方的软件能够实现,不过效率不高)ide
2.NFS系统守护进程ui
nfsd:它是基本的NFS守护进程,主要功能是管理客户端是否可以登陆服务器;spa
mountd:它是RPC安装守护进程,主要功能是管理NFS的文件系统。当客户端顺利经过nfsd登陆NFS服务器后,在使用NFS服务所提供的文件前,还必须经过文件使用权限的验证。它会读取NFS的配置文件/etc/exports来对比客户端权限。unix
portmap:主要功能是进行端口映射工做。当客户端尝试链接并使用RPC服务器提供的服务时,portmap会将所管理的与服务对应的端口提供给客户端,从而使客户能够经过该端口向服务器请求服务
二.NFS的配置
1.相关文件
/etc/exports NFS服务的主要配置文件,须要手动创建
/usr/sbin/exportfs NFS服务的管理命令
/usr/sbin/showmount 客户端的查看命令
/var/lib/nfs/etab 记录NFS分享出来的目录的完整权限设定值
/var/lib/nfs/xtab 记录曾经登陆过的客户端信息
2.主配置文件
/etc/exports ,格式:
共享目录名称 客户端地址(权限,另外一个权限) 另外一个客户端地址(权限,另外一个权限)
客户端能够为:
192.168.8.70 ip地址
tx.test.com 主机名
192.168.8.0/24 一个网段
*.test.com 全部主机名
权限能够为:
@1.no_root_squash: 表示不对root 的身份进行转换
@2.all_squash: 全部用户身份都转化
@3.all_squash,anonuid=500,anongid=500: 全部新生成文件的全部者、所属组都转换成为500
@4. root_squash 表示对root的身份进行转换,转换成nfsnobody
@5. ro 只读
@6..rw 只写
@7.anonuid 能够自行设定这个UID的值,这个UID必须要存在于你的/etc/passwd当中
@8.anongid 同anonuid,可是变成groupID就是了
@9.sync 资料同步写入到内存与硬盘当中
@10.async 资料会先暂存于内存当中,而非直接写入硬盘
@11.insecure 容许从这台机器过来的非受权访问
[root@tx1 ~]#mkdir /tmp/tx
[root@tx1 ~]#vim /etc/exports
/tmp/tx *(ro,sync)
[root@tx1 ~]# cd /tmp/tx
[root@tx1 tx]# ls
[root@tx1 tx]# touch tt t1 t2
3.启动nfs:
[root@tx1 ~]# service portmap restart
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
[root@tx1 ~]# service nfs restart
Shutting down NFS mountd: [FAILED]
Shutting down NFS daemon: [FAILED]
Shutting down NFS quotas: [FAILED]
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
开机自动启动
[root@tx1 ~]# chkconfig --list portmap
portmap 0:off1:off2:off3:on4:on5:on6:off
[root@tx1 ~]# chkconfig --list nfs
nfs 0:off1:off2:off3:off4:off5:off6:off
[root@tx1 ~]# chkconfig nfs on
[root@tx1 ~]# chkconfig --list nfs
nfs 0:off1:off2:on3:on4:on5:on6:off
4.export
exportfs[-aruv]
a 所有挂载(或卸载)/etc/exports档案内的设定
r 从新挂载/etc/exports 里面的设定,也同步的更新/etc/exports和/var/lib/nfs/xtab里面的内容
u 卸载某一目录
v 在export的时候,将分享的目录显示到荧屏上
三.客户端的挂载
[root@tx2 ~]# showmount -e 192.168.8.70
Export list for 192.168.8.70:
/tmp/tx *
[root@tx2 ~]# mkdir /mnt/nfs
[root@tx2 ~]# mount -t nfs 192.168.8.70:/tmp/tx /mnt/nfs
[root@tx2 ~]# cd /mnt/nfs/
[root@tx2 nfs]# ls
t1 t2 tt
开机自动挂载
[root@tx2 ~]# vim /etc/rc.local
mount -t nfs 192.168.8.70:/tmp/tx /mnt/nfs
[root@tx2 ~]# vim /etc/fstab
192.168.8.70:/tmp/tx /mnt/nfs nfs ro 0 0
自动挂载
[root@tx2 ~]# vim /etc/auto.master
9 /misc /etc/auto.misc
10 /mnt/nfs /etc/auto.nfs --timeout=60
[root@tx2 ~]# cp -p /etc/auto.misc /etc/auto.nfs
[root@tx2 ~]# vim /etc/auto.nfs
server -ro 192.168.8.70:/tmp/tx
[root@tx2 ~]# service autofs restart
Stopping automount: [ OK ]
Starting automount: [ OK ]
[root@tx2 etc]# cd /mnt/nfs/
[root@tx2 nfs]# ls
[root@tx2 nfs]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 20G 2.2G 17G 12% /
/dev/hda5 99M 5.6M 89M 6% /home
/dev/hda1 99M 12M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/hdc 3.3G 3.3G 0 100% /media/RHEL_5.8 i386 DVD
[root@tx2 nfs]# cd server
[root@tx2 server]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 20G 2.2G 17G 12% /
/dev/hda5 99M 5.6M 89M 6% /home
/dev/hda1 99M 12M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/hdc 3.3G 3.3G 0 100% /media/RHEL_5.8 i386 DVD
192.168.8.70:/tmp/tx 20G 2.6G 16G 14% /mnt/nfs/server
[root@tx2 server]# ls
t1 t2 tt