网络文件系统即Network File System。以下将基于Centos6.4与Centos5.8进行配置服务端、客户端。【Centos5.8做服务端,Centos6.4做客户端过程略,过程完全一摸一样。】
环境说明:
0 1 |
Centos 6.4:Linux NFS-Server-X86-64 2.6.32-358.el6.x86_64 #IP:192.168.199.175 Centos 5.8:Linux NFS-Client-X86-64 2.6.18-308.el5 #IP:192.168.199.158 |
假设Centos6.4为server(配置如下):
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@NFS-Server-X86-64 ~]# rpm -aq nfs-utils rpcbind #Centos6.4查看是否安装nfs以及rpcbind [root@NFS-Client-X86-64 ~]# rpm -aq nfs-utils portmap #Centos5.8查看是否安装nfs以及portmap [root@byrd byrd]# yum install nfs-utils #如果未安装,可以yum来安装,会自动安装rpcbind(6.4)或者portmap(5.8) Dependencies Resolved ====================================================================================================================================== Package Arch Version Repository Size ====================================================================================================================================== Installing: nfs-utils x86_64 1:1.2.3-39.el6 base 320 k Installing for dependencies: keyutils x86_64 1.4-4.el6 base 39 k libevent x86_64 1.4.13-4.el6 base 66 k libgssglue x86_64 0.1-11.el6 base 23 k libtirpc x86_64 0.2.1-6.el6_5.1 updates 79 k nfs-utils-lib x86_64 1.1.5-6.el6 base 67 k rpcbind x86_64 0.2.0-11.el6 base 51 k Transaction Summary ====================================================================================================================================== Install 7 Package(s) |
完成安装后,查看下nfs以及rpcbind是否自动启动
0 1 2 3 4 5 |
[root@NFS-Server-X86-64 ~]# /etc/init.d/nfs status rpc.svcgssd is stopped rpc.mountd is stopped nfsd is stopped [root@NFS-Server-X86-64 ~]# /etc/init.d/rpcbind status rpcbind is stopped |
启动相关服务:
0 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 |
[root@NFS-Server-X86-64 ~]# /etc/init.d/rpcbind start #RPC服务,必须启动,且首先启动 Starting rpcbind: [ OK ] [root@NFS-Server-X86-64 ~]# /etc/init.d/nfs start #启动nfs服务,服务端必须启动 Starting NFS services: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ] Starting RPC idmapd: [ OK ] [root@NFS-Server-X86-64 ~]# rpcinfo -p localhost #查看主机rpc状态 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 100005 1 udp 53524 mountd 100005 1 tcp 10006 mountd 100005 2 udp 25736 mountd 100005 2 tcp 44568 mountd 100005 3 udp 33965 mountd 100005 3 tcp 40021 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 58808 nlockmgr 100021 3 udp 58808 nlockmgr 100021 4 udp 58808 nlockmgr 100021 1 tcp 35480 nlockmgr 100021 3 tcp 35480 nlockmgr 100021 4 tcp 35480 nlockmgr |
/etc/exports配置演示
0 1 2 3 4 5 6 7 8 9 |
[root@NFS-Server-X86-64 ~]# man exports # # sample /etc/exports file / master(rw) trusty(rw,no_root_squash) /projects proj*.local.domain(rw) /usr *.local.domain(ro) @trusted(rw) /home/joe pc001(rw,all_squash,anonuid=150,anongid=100) /pub *(ro,insecure,all_squash) /srv/www -sync,rw server @trusted @external(ro) /foo 2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw) /build buildhost[0-9].local.domain(rw) |
配置如下:
0 1 2 3 4 5 |
[root@NFS-Server-X86-64 ~]# vim /etc/exports [root@NFS-Server-X86-64 ~]# tail /etc/exports #config nfs server /data/pic 192.168.199.0/24(rw,sync) #在192.168.199.0的网段的主机可以对/data/pic有读写权限 [root@NFS-Server-X86-64 ~]# mkdir /data/pic -p #创建需要共享的目录 [root@NFS-Server-X86-64 ~]# touch /data/pic/hellonfs.txt #在/data/pic目录下创建一个文件,来用于测试 |
============================server配置完成============================
配置client:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@NFS-Client-X86-64 ~]# rpm -aq portmap #client不需要nfs,只有portmap(5.8)或rpcbind(6.4)即可 portmap-4.0-65.2.2.1 [root@NFS-Client-X86-64 ~]# /etc/init.d/portmap start Starting portmap: [ OK ] [root@NFSCLIENT ~]# showmount -e 192.168.199.175 #如果这里报错,是由于需要安装nfs -bash: showmount: command not found [root@NFS-Client-X86-64 ~]# showmount -e 192.168.199.175 #报错? mount clntudp_create: RPC: Port mapper failure - RPC: Unable to receive [root@NFS-Client-X86-64 ~]# showmount -e 192.168.199.175 #由于server开启防火墙导致的,临时关闭 Export list for 192.168.199.175: /data/pic 192.168.199.0/24 [root@NFS-Client-X86-64 ~]# mount -t nfs 192.168.199.175:/data/pic /www/pic #目录必须存在,才可以挂载 mount.nfs: mount point /www/pic does not exist [root@NFS-Client-X86-64 ~]# mkdir /www/pic -p [root@NFS-Client-X86-64 ~]# mount -t nfs 192.168.199.175:/data/pic /www/pic [root@NFS-Client-X86-64 ~]# ll /www/pic/ total 0 -rw-r--r-- 1 root root 0 Apr 7 2014 hellonfs.txt |
如果这个看懂了,哪么反向推导一下。Centos5.8做server,6.4做client基本类似了吧?SourceByrd's Weblog-https://note.t4x.org/system/network-file-system-config/
关于权限的一些事!~
客户端:
0 1 2 3 |
[root@NFS-Client-X86-64 pic]# mkdir ddd #准备在pic目录下建立一个ddd的目录! mkdir: cannot create directory `ddd': Permission denied [root@NFS-Client-X86-64 pic]# touch ddd #准备在pic目录下建立一个ddd的文件! touch: cannot touch `ddd': Permission denied |
服务端:
0 1 2 |
[root@NFS-Server-X86-64 ~]# chown nfsnobody:nfsnobody /data/pic/ -R [root@NFS-Server-X86-64 ~]# ll -d /data/pic/ drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 7 21:43 /data/pic/ |
客户端:
0 1 2 3 |
[root@NFS-Client-X86-64 pic]# touch ddd [root@NFS-Client-X86-64 pic]# mkdir work [root@NFS-Client-X86-64 pic]# cat /proc/mounts 192.168.199.175:/data/pic /www/pic nfs rw,vers=3,rsize=65536,wsize=65536,hard,proto=tcp,timeo=600,retrans=2,sec=sys,addr=192.168.199.175 0 0 |
服务端:
0 1 2 3 4 |
[root@NFS-Server-X86-64 ~]# ll /data/pic/ total 4 -rw-r--r--. 1 nfsnobody nfsnobody 0 Apr 7 22:03 ddd -rw-r--r--. 1 nfsnobody nfsnobody 0 Apr 7 21:43 hellonfs.txt drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Apr 7 22:03 work |
其他配置:
0 1 |
[root@NFS-Server-X86-64 ~]# vim /etc/sysconfig/nfs [root@NFS-Server-X86-64 ~]# vim /etc/nfsmount.conf |
附加内容:autofs (AT:2014-04-14 BY:BYRD)
0 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 |
[byrd@NFS-Client-X86-64 ~]$ yum install autofs Loaded plugins: fastestmirror You need to be root to perform this command. [root@NFS-Client-X86-64 ~] [byrd@NFS-Client-X86-64 ~]$ sudo bash [root@NFS-Client-X86-64 byrd]# yum install autofs Loaded plugins: fastestmirror Determining fastest mirrors base | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package autofs.x86_64 1:5.0.5-89.el6_5.1 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================================== Package Arch Version Repository Size ====================================================================================================================================== Installing: autofs x86_64 1:5.0.5-89.el6_5.1 updates 496 k Transaction Summary ====================================================================================================================================== Install 1 Package(s) Total download size: 496 k Installed size: 3.1 M Is this ok [y/N]: y Downloading Packages: autofs-5.0.5-89.el6_5.1.x86_64.rpm | 496 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 1:autofs-5.0.5-89.el6_5.1.x86_64 1/1 Verifying : 1:autofs-5.0.5-89.el6_5.1.x86_64 1/1 Installed: autofs.x86_64 1:5.0.5-89.el6_5.1 Complete! [root@NFS-Client-X86-64 ~]# vim /etc/auto.master 第十行增加: /www /etc/auto.misc --timeout 600(挂载10分后失效) [root@NFS-Client-X86-64 ~]# vim /etc/auto.misc 第十七行增加: dddpic(名字随便起) -fstype=nfs(挂载类型nfs) 192.168.199.175:/data/pic(服务端) [root@NFS-Client-X86-64 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/hda2 123G 1.2G 115G 2% / /dev/hda1 99M 12M 82M 13% /boot tmpfs 248M 0 248M 0% /dev/shm [root@NFS-Client-X86-64 ~]# grep dddpic /proc/mounts [root@NFS-Client-X86-64 ~]# cd /www/dddpic [root@NFS-Client-X86-64 dddpic]# grep dddpic /proc/mounts 192.168.199.175:/data/pic /www/dddpic nfs rw,vers=3,rsize=65536,wsize=65536,hard,proto=tcp,timeo=600,retrans=2,sec=sys,addr=192.168.199.175 0 0 [root@NFS-Client-X86-64 ~]# /etc/rc.d/init.d/autofs reload #重新加载配置 |
到此,本篇文章基本算是结束了。这些配置只是临时生效,需要把rpcbind或者portmap、nfs加入系统开机启动。SourceByrd's Weblog-https://note.t4x.org/system/network-file-system-config/
申明:本文由BYRD原创(基于Centos6.4 X64、Centos5.8 X64),未经许可禁止转载!SourceByrd's Weblog-https://note.t4x.org/system/network-file-system-config/ SourceByrd's Weblog-https://note.t4x.org/system/network-file-system-config/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!