Redhat Linux NFS配置

        Linux下,All deviceis file,所有的设备都是文件。当我们需要把某些文件夹就或者文件共享给其他用户,就可以使用网络文件系统。

 

        本文介绍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 选项(访问权限,用户映射,其他)]

 

        NFS主要有3类选项:

        访问权限选项

 

        设置输出目录只读:ro

        设置输出目录读写:rw


        用户映射选项

 

        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


katoon Sina CSDN
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客]
原文地址:https://www.cnblogs.com/xinyuyuanm/p/3206390.html