现在的位置: 首页 > 综合 > 正文

通过NFS服务共享访问

2013年10月18日 ⁄ 综合 ⁄ 共 5378字 ⁄ 字号 评论关闭


<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
p
{mso-style-noshow:yes;
mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:宋体;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:21.0pt;
mso-char-indent-count:2.0;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:1350183042;
mso-list-type:hybrid;
mso-list-template-ids:838747970 2096528748 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-number-format:alpha-upper;
mso-level-text:"%1/)";
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:39.0pt;
text-indent:-18.0pt;}
@list l1
{mso-list-id:2120485736;
mso-list-type:hybrid;
mso-list-template-ids:-1013284096 -2129602268 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
{mso-level-text:%1);
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:18.0pt;
text-indent:-18.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
-->

1) 


招聘网站系统应用环境图如下:

2) 


设计
Tomcat
服务器
172.21.96.108

NFS
服务器,配置如下:

A)     



新建目录:
mkdir /home/share

B)     



增加到
root
组:
chown root /home/share

注:如果需要共享的目录已经存在,则不需要上述步骤;

C)     



启动
NFS
服务,运行
setup
命令,在“系统服务”中,找到“
NFS
”选中;

D)     



修改
NFS
配置文件
vim 

/etc/

exports,
在其中加入以下内容:

/home/share 172.21.96.105(rw,sync) 172.21.96.106(rw,sync)
172.21.96.107(rw,sync) 172.21.96.106(r,sync)

wq
保存

以上参数表明,支持客户端
172.21.96.105-107
对共享目录进行读写,103
对共享目录具有只读权限。

E)      



重启服务

#
/etc/rc.d/init.d/portmap start

(
第一次刚用NFS
,
这一步一定要,
不然会出现这样的错误:root_nfs failed, reason given by
server:

权限不够)

/etc/rc.d/init.d/nfs
start

F)      



验证:在
172.21.96.105
上执行以下命令,验证共享服务是否正常

showmount -e 172.21.96.108

如果显示以下信息说明共享服务配置正常

        
Export
list for 192.168.102.47:

       

/home/share

3) 



在客户端加载共享目录

分别在每个需要加载共享目录的机器上执行以下命令:

mount -t nfs172.21.96.108:/home/share
/mnt

这条指令表明将目标服务器
172.21.96.108
上的共享目录
/home/share
加载到客户端本地
/mnt
下。

4) 



卸载共享目录

Umount /mnt

这条指令表明,将挂在在本地
/mnt
目录下的共享卸载掉。

5) 



开机自动挂载

写一个
Shell

Vim mount_nfs

写入以下内容:

mount -t nfs172.21.96.108:/home/share
/mnt

wq
保存

chmod 777 mount_nfs
设置可执行权限

cp mount_nfs /usr/sbin/

shell
文件
copy
到可执行目录下

Vim /etc/rc.d/rc.local

增加一行
mount_nfs

Wq
保存

6) 



Exports
文件配置参数语法

这个文件的内容非常简单,每一行由抛出路径,客户名列表以及每个客户名后紧跟的访问选项构成:
共享的目录] [
主机名或IP(
参数,
参数)]

其中参数是可选的,当不指定参数时,nfs
将使用默认选项。默认的共享选项是
sync,ro,root_squash,no_delay

当主机名或IP
地址为空时,则代表共享给任意客户机提供服务。

当将同一目录共享给多个客户机,但对每个客户机提供的权限不同时,可以这样:

     
[

共享的目录] [
主机名1
IP1(
参数1,
参数2)] [
主机名2
IP2(
参数3,
参数4)]

下面是一些NFS
共享的常用参数:

   
ro                     

只读访问

 
rw                     

读写访问

 
sync                   

所有数据在请求时写入共享

 
async                  
NFS

在写入数据前可以相应请求

  
secure                 
NFS

通过1024
以下的安全TCP/IP
端口发送

 
insecure               
NFS

通过1024
以上的端口发送

 
wdelay                 

如果多个用户要写入NFS
目录,则归组写入(默认)

    

no_wdelay          
    

如果多个用户要写入NFS
目录,则立即写入,当使用async
时,无需此设置。

    
hide                   

NFS
共享目录中不共享其子目录

    

no_hide                

共享NFS
目录的子目录

      

subtree_check          

如果共享/usr/bin
之类的子目录时,强制NFS
检查父目录的权限(默认)

     

no_subtree_check       

和上面相对,不检查父目录权限

    
all_squash             

共享文件的UID
GID
映射匿名用户anonymous
,适合公用目录。

   

no_all_squash          

保留共享文件的UID
GID
(默认)

   

root_squash            
root

用户的所有请求映射成如anonymous
用户一样的权限(默认)

    

no_root_squas          
root

用户具有根目录的完全管理访问权限

      

anonuid=xxx            

指定NFS
服务器/etc/passwd
文件中匿名用户的UID

   

anongid=xxx            

指定NFS
服务器/etc/passwd
文件中匿名用户的GID

抱歉!评论已关闭.