查看系统支持的文件系统
[[email protected] ~]# ls /lib/modules/2.6.32-431.el6.i686/kernel/fs/
autofs4 configfs exportfs fat jbd mbcache.ko nls
btrfs cramfs ext2 fscache jbd2 nfs squashfs
cachefiles dlm ext3 fuse jffs2 nfs_common ubifs
cifs ecryptfs ext4 gfs2 lockd nfsd udf
启动NFS之前必须先启动rpcbind服务,然后再启动NFS。
NFS原理:
一、安装NFS服务
需要安装两个包(nfs-utils和rpcbind)
命令:
[[email protected] ~]# yum install nfs-utils rpcbind –y
[[email protected] ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-64.el6.i686
rpcbind-0.2.0-11.el6.i686 ==>此提示说明已经安装好了
或者[[email protected] ~]# yum groupinstall "NFS file server" –y
Centos5.X下的rpc服务程序是portmap,6.X下是rpcbind
二、启动和检测rpcbind服务
[[email protected] ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[[email protected] ~]# rpcinfo -p localhost
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
==>提示启动成功。111这个端口是rpc这个服务器启动默认的端口
三、启动NFS
[[email protected] ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
四、设置开机启动
[[email protected] ~]# chkconfig nfs on
[[email protected] ~]# chkconfig rpcbind on
[[email protected] ~]# chkconfig --list |grep nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on
[[email protected] ~]# chkconfig --list |grep rpcbind
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on
五、配置NFS和检测
配置文件在 /etc/exports
[[email protected] ~]# vim /etc/exports
/data 192.168.3.0/24(rw,sync)
==>创建共享目录data,把buffer的数据写到磁盘的命令是sync
[[email protected] ~]# /etc/init.d/nfs reload ==> 本地检测
[[email protected] ~]# showmount -e localhost
Export list for localhost:
/data 192.168.3.0/24 ==> 共享成功
客户端要想写的权限,需要更改data这个目录的写权限,或者更改所属组服务端
[[email protected] ~]# chown -R nfsnobody.nfsnobody /data
[[email protected] ~]# ls -ld /data
drwxr-xr-x 2 nfsnobody nfsnobody 4096 Nov 10 19:23 /data
查看NFS对应的是哪个用户
[[email protected] ~]# cat /var/lib/nfs/etab
/data192.168.3.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[[email protected] ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
下面是客户端的挂载操作
一、客户端需要安装rpcbind服务
[[email protected] ~]# yum install rpcbind -y
[[email protected] ~]# /etc/init.d/rpcbind start
Startingrpcbind: [ OK ]
二、检测服务端是否有共享的目录
[[email protected] ~]# showmount -e 192.168.3.188
Export list for 192.168.3.188:
/data 192.168.3.0/24
提示:如果没有showmount命令需要yum安装一下
三、客户端挂载NFS
[[email protected] ~]# mount -t nfs 192.168.3.188:/data /mnt
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.7G 16G 10% /
tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 97M 25M 68M 27% /boot
/dev/sda2 2.0G 67M 1.9G 4% /swap
192.168.3.188:/data 20G 1.5G 17G 8% /mnt ==》挂载成功
四、设置客户开机自动挂载
[[email protected] ~]# echo "mount -t nfs 192.168.3.188:/data /mnt" >>/etc/rc.local
至此,NFS服务以及部署完成,客户端可以查看共享的目录啦