网络文件系统(NFS)是一种在网络上的机器间共享文件的方法,文件就如同位于客户的本地硬盘驱动器上一样。Red Hat Linux 既可以是 NFS 服务器也可以是 NFS 客户,这意味着它可以把文件系统导出给其它系统,也可以挂载从其它机器上导入的文件系统。
RedHad默认已经安装了NFS,如果没装需手动安装如下5个rpm包:
setup-*:  共享NFS目录在/etc/exports中定义
initscripts-*: 包括引导过程中装载网络目录的基本脚本
nfs-utils-*:  包括基本的NFS命令与监控程序
portmap-*:  支持安全NFS RPC服务的连接
quota-*:    网络上共享的目录配额,包括rpc.rquotad (这个包不是必须的)
以下是本机上的配置(因为这样的攻略太多了,我就不做详细解释啦,此处只是自己对配置的一个简单记录^_^)
[root@homeserver ~]# rpm -qa | grep nfs
nfs-utils-1.0.9-33.el5
nfs-utils-lib-1.0.8-7.2.z2
[root@homeserver ~]# mkdir /shares
[root@homeserver ~]# cd /shares/
[root@homeserver shares]# vi /etc/exports
/shares 192.168.1.0/24(rw,sync)
[root@homeserver shares]# exportfs -rv
exporting 192.168.1.0/24:/shares
[root@homeserver shares]# chkconfig --list | grep nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@homeserver shares]# chkconfig nfs on
[root@homeserver shares]# chkconfig --list | grep nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@homeserver shares]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@homeserver shares]# netstat -ntupol
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name Timer
7775/rpc.mountd off (0.00/0/0)
udp 0 0 0.0.0.0:5353 0.0.0.0:* 6757/avahi-daemon: off (0.00/0/0)
udp 0 0 0.0.0.0:111 0.0.0.0:* 6236/portmap off (0.00/0/0)
udp 0 0 0.0.0.0:631 0.0.0.0:* 6571/cupsd off (0.00/0/0)
udp 0 0 :::32769 :::* 6757/avahi-daemon: off (0.00/0/0)
udp 0 0 :::5353 :::* 6757/avahi-daemon: off (0.00/0/0)
[root@homeserver shares]# cp /etc/shadow /shares/
[root@homeserver shares]# ll /shares/
total 8
-r-------- 1 root root 996 Feb 3 11:00 shadow
[root@laba ~]# showmount -e 192.168.1.222
Export list for 192.168.1.222:
/shares 192.168.1.0/24
[root@laba ~]# mkdir /mnt/shares
[root@laba ~]# mount 192.168.1.222:/shares /mnt/shares/
[root@laba ~]# 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)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
//192.168.1.222/rhecpkg on /mnt type cifs (rw,mand)
192.168.1.222:/shares on /mnt/shares type nfs (rw,addr=192.168.1.222)
[root@laba ~]# ll /mnt/shares/
total 8
-r-------- 1 root root 996 Feb 3 11:00 shadow