Linux下,All deviceis file,全部的设备都是文件。当咱们须要把某些文件夹就或者文件共享给其余用户,就能够使用网络文件系统。html
本文介绍Redhat Linux下的NFS配置。数据库
在使用NFS以前,确保安装如下rpm包:nfs-utils-xxx.i686.rpm、nfs4-acl-tools-xxx.i686.rpm、nfs-utils-xxx.i686.rpm(xxx表示版本)。能够使用rpm-qa进行查询:服务器
[root@localhost nfs]# rpm -qa|grep nfs nfs-utils-lib-1.1.5-1.el6.i686 nfs4-acl-tools-0.3.3-5.el6.i686 nfs-utils-1.2.2-7.el6.i686
若是查询结果为空,则须要手动安装,能够在安装Linux系统的ISO包里查找,先挂载:mount -o loop /home/Wentasy/software/RHEL_6.2.iso /mnt,而后find,把nfs开头的3个rpm依次安装。微信
[root@larrywen mnt]# find . -name "*nfs*" ./Packages/nfs-utils-1.2.3-15.el6.i686.rpm ./Packages/nfs-utils-lib-1.1.5-4.el6.i686.rpm ./Packages/nfs4-acl-tools-0.3.3-5.el6.i686.rpm ./Packages/sblim-cmpi-nfsv3-1.1.1-1.el6.i686.rpm ./Packages/sblim-cmpi-nfsv4-1.1.0-1.el6.i686.rpm
如今对NFS进行配置,配置文件为/etc/exports,配置文件格式以下:网络
<输出目录> [客户端1 选项(访问权限,用户映射,其余)] [客户端2 选项(访问权限,用户映射,其余)]oracle
NFS主要有3类选项:app
访问权限选项微信公众平台
设置输出目录只读:roasync
设置输出目录读写:rwtcp
用户映射选项
all_squash:将远程访问的全部普通用户及所属组都映射为匿名用户或用户组(nfsnobody);
no_all_squash:与all_squash取反(默认设置);
root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);
no_root_squash:与rootsquash取反;
anonuid=xxx:将远程访问的全部用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);
anongid=xxx:将远程访问的全部用户组都映射为匿名用户组帐户,并指定该匿名用户组帐户为本地用户组帐户(GID=xxx);
其它选项
secure:限制客户端只能从小于1024的tcp/ip端口链接nfs服务器(默认设置);
insecure:容许客户端从大于1024的tcp/ip端口链接服务器;
sync:将数据同步写入内存缓冲区与磁盘中,效率低,但能够保证数据的一致性;
async:将数据先保存在内存缓冲区中,必要时才写入磁盘;
wdelay:检查是否有相关的写操做,若是有则将这些写操做一块儿执行,这样能够提升效率(默认设置);
no_wdelay:如有写操做则当即执行,应与sync配合使用;
subtree:若输出目录是一个子目录,则nfs服务器将检查其父目录的权限(默认设置);
no_subtree:即便输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样能够提升效率;
个人配置文件以下:
/home/nfs */24(rw,sync)
* :容许全部的网段访问
rw :读写权限
sync:资料同步写入内在和硬盘
查看/home/nfs权限及在此目录建立文件,在file1里输入内容“hello”
[root@localhost ~]# vi /etc/exports [root@localhost ~]# ll /home/nfs -d drwxr-xr-x. 2 root root 4096 Jul 21 09:58 /home/nfs [root@localhost ~]# ll /home/nfs -d drwxr-xr-x. 2 root root 4096 Jul 21 09:58 /home/nfs [root@localhost ~]# cd /home/nfs [root@localhost nfs]# touch file1 [root@localhost nfs]# echo "hello" file1 hello file1 [root@localhost nfs]# echo "hello" > file1 [root@localhost nfs]# cat file1 hello [root@localhost nfs]# cat /etc/exports /home/nfs *(rw,sync) [Wentasy@localhost test]$ ll /home/nfs -d drwxrwxrwx. 2 root root 4096 Jul 21 10:07 /home/nfs
如今启动NFS服务。
[root@localhost ~]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ]
另外一个客户端以其余用户登陆,而后挂载共享的文件夹到/home/Wentasy/test,编辑file1,加入“world”。
[Wentasy@localhost ~]$ sudo mount -t nfs 169.254.140.100:/home/nfs /home/Wentasy/test/ [Wentasy@localhost ~]$ cd /home/Wentasy/test/ [Wentasy@localhost test]$ ll total 4 -rw-r--r--. 1 root root 6 Jul 21 10:08 file1 [Wentasy@localhost test]$ cat file1 hello world
执行mount命令,能够看到169.254.140.100:/home/nfs挂载到
/home/Wentasy/test [Wentasy@localhost test]$ mount /dev/mapper/VolGroup-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) nfsd on /proc/fs/nfsd type nfsd (rw) 169.254.140.100:/home/nfs on /home/Wentasy/test type nfs (rw,vers=4,addr=169.254.140.100,clientaddr=169.254.140.100)
切换到root用户或者先前的客户端,查看file1文件,能够看到Wentasy用户修改的文件内容已经同步了。
[root@localhost nfs]# cat file1 hello world
更精彩的文章:http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html
个人邮箱:wgbno27@163.com 新浪微博:@Wentasy27 微信公众平台:JustOracle(微信号:justoracle) 数据库技术交流群:336882565(加群时验证 From CSDN XXX) Oracle交流讨论组:https://groups.google.com/d/forum/justoracle By Larry Wen
![]() |
![]() ![]() |
@Wentasy 博文仅供参考,欢迎你们来访。若有错误之处,但愿批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |