ºìÁªLinuxÃÅ»§
Linux°ïÖú

Ò»¸ölinuxϵÄÈä³æ

·¢²¼Ê±¼ä:2006-02-27 01:01:54À´Ô´:ºìÁª×÷Õß:artiomgy
unixϵͳµÄNFS·þÎñÏ൱ÓÚMSϵͳÉϵÄÎļþ¹²Ïí·þÎñ.Ò²ÐíÓÐÈËÈÏΪÕâÊÇÒ»¸ö²»Ç¡µ±µÄ±ÈÓ÷,µ«¶þÕßÔÚ°²È«ÎÊÌâÉÏÓоªÈ˵ÄÀàËÆ,ÕýÈçNT/Windows»úÆ÷ÉϵݲȫÎÊÌâºÜ¶àÀ´×Ô¹²Ïí×ÊÔ´Ò»Ñù,NFS·þÎñµÄ´íÎóÅäÖÃ,Ò²¿ÉÒÔÈÃÄãµÄϵͳ±»ÈëÇÖÕß½Ó¹Ü.NFS½¨Á¢ÔÚRPC(Ô¶³Ì¹ý³Ìµ÷ÓÃ)»úÖÆÉÏ,ͬÑùµØ,»ùÓÚRPC»úÖÆÉϵÄNTµÄ·þÎñÒ²²»°²È«;Õë¶ÔMS¹²Ïí×ÊÔ´µÄ¹¥»÷Êǵ±Ç°InternetÉÏ×îÁ÷ÐеĹ¥»÷NT·½Ê½,¶ÔNFSµÄ¹¥»÷Ò²¶ÔUNixƽ̨»úÆ÷µÄ×î³£ÓÃÊÖ¶Î.

NFSµÄ²»°²È«ÐÔÖ÷ÒªÌåÏÖÓÚÒÔÏÂ4¸ö·½Ãæ:

1¡¢ÐÂÊÖ¶ÔNFSµÄ·ÃÎÊ¿ØÖÆ»úÖÆÄÑÓÚ×öµ½µÃÐÄÓ¦ÊÖ,¿ØÖÆÄ¿±êµÄ¾«È·ÐÔÄÑÒÔʵÏÖ

2¡¢NFSûÓÐÕæÕýµÄÓû§ÑéÖ¤»úÖÆ,¶øÖ»ÓжÔRPC/MountÇëÇóµÄ¹ý³ÌÑéÖ¤»úÖÆ

3¡¢½ÏÔçµÄNFS¿ÉÒÔʹδÊÚȨÓû§»ñµÃÓÐЧµÄÎļþ¾ä±ú

4¡¢ÔÚRPCÔ¶³Ìµ÷ÓÃÖÐ,Ò»¸öSUIDµÄ³ÌÐò¾Í¾ßÓг¬¼¶Óû§È¨ÏÞ.

ÎÒÃÇ·Ö±ð´ÓÕ⼸¸ö·½Ãæ¼ÓÒÔÂÛÊö:

1¡¢ÔÚ´ó¶àÊýUnixϵͳµÄȱʡµÄÇé¿öÏÂ,ExportĿ¼ʱ,Èç¹û²»Ö¸¶¨Ö»¶Á,¸ÃĿ¼Ϊ¿Éд;NFSµÄ·ÃÎÊ¿ØÖÆÎļþºÜÈÝÒ׳öÏÖ´íÎóÅäÖÃ,ºÜ¶àÇé¿öÏÂÅäÖÃΪ¿ÉÒÔ±»ÍøÉÏÈκÎһ̨»úÆ÷·ÃÎÊ,Ô¶³ÌÓû§¿ÉÒÔÓÃÕâÌõÃüÁîÀ´²éµ½ÊÇ·ñÓÐNFSµÄÅäÖ鶴,Õâ¸öÃüÁîÊǼ¸ºõËùÓеÄNFS¹¥»÷µÄ±Ø¾­²½Öè:

# showmount -e www.xxx.com
¿ÉÄܽá¹ûÈçÏÂ:
/usr (everyone)
/export/target1 -access=target2
/export/target2 -access=target1
¿ÉÒÔ°ÑÕâ¸öNFS serverÉϵÄ/usrĿ¼mount³É±¾µØĿ¼:
# mount www.xxx.com:/usr /tmp

Õâ±íÃ÷,/usrĿ¼¿ÉÒÔ±»ÈκÎһ̨»úÆ÷mount,ÉõÖÁ¿ÉÄÜÓÐдµÄȨÏÞ;¶ø/export/target1Ŀ¼ָ¶¨ÁËÖ÷»ú·ÃÎÊÏÞÖÆ,±ØÐëÊÇtarget2.xxx.comÕâ¸ö»úÆ÷»òÕßtarget2Õâ¸öNetgroupµÄ³ÉÔ±²ÅÄÜmount.ÈëÇÖÕß´ó¶à¶¼ÏÈÓÃÕâ¸öÃüÁîÀ´²éѯĿ±êÉϵÄNFS©¶´,ÕýÈç¶ÔNTµÄNetviewÃüÁîÒ»Ñù.ÖµµÃÌáÐѵÄÊÇ,ÏÖÔÚÁ÷ÐеÄÈëÇÖ·½Ê½ÒѾ­´ÓÒÔÇ°µÄ¶ÔÈ·¶¨Ä¿±êµÄ¹¥»÷·½Ê½×ªÎª²»¹Ü¶Ô·½ÊÇË­,Ö»ÒªÓлú¿É³Ë¾ÍÈëÇֵķ½Ê½.ÈëÇÖÕß¿ÉÄÜ»áдһ¸ö½Å±¾»òÕßÒ»¸ö³ÌÐò,ÓÃÀ´¶ÔÒ»´ó¶ÎµØÖ·½øÐÐɨÃè,Áгö½á¹û±¨¸æ¸ø×Ô¼º.ËùÒÔ,ÕýÈ·µÄÅäÖÃÊǷdz£ÖØÒªµÄ.ÔÚInternetÉÏ,NFSÉèÖôíÎóµÄ»úÆ÷±È±È½ÔÊÇ.Õâ¸öÅäÖÃÒ»°ã´æ·ÅÓÚ/etc/exportsÎļþ»ò/etc/dfs/dfstabÖÐ.

2¡¢À´×Ô¿Í»§¶ËµÄNFSÇëÇóµÄÓû§ÈÏÖ¤,ÓÉÓû§µÄUIDºÍËùÊô×éµÄGID×é³É,ÕâÖÖÎļþ·ÃÎʵݲȫÑéÖ¤¶ÔÓÚûÓпªNFSµÄϵͳµ±È»ÊÇ°²È«µÄ;µ«ÊÇÔÚÍøÉÏ,ÆäËü»úÆ÷µÄrootÍêÈ«ÓÐȨÔÚ×Ô¼ºµÄ»úÆ÷ÉÏÉèÖÃÕâÑùÒ»¸öUID,¶øNFS·þÎñÆ÷²»¹ÜÕâ¸öUIDÊDz»ÊÇ×Ô¼º»úÆ÷ÉϵÄ,Ö»ÒªUID·ûºÏ,¾Í¸³ÓèÕâ¸öÓû§¶ÔÕâ¸öÎļþµÄ²Ù×÷Ȩ.±ÈÈç,Ŀ¼/home/frankÖ»ÄÜÓÉUIDΪ501µÄÓû§´ò¿ª¶Áд,¶øÕâ¸öĿ¼¿ÉÒÔ±»Ô¶³Ì»úÆ÷mount,ÄÇô,Õą̂»úÆ÷µÄrootÓû§ÐÂÔöÒ»¸öUIDΪ501µÄÓû§,È»ºóÓÃÕâ¸öÓû§µÇ¼²¢mount¸ÃĿ¼,¾Í¿ÉÒÔ»ñµÃÏ൱ÓÚNFS serverÉϵÄUIDΪ501Óû§²Ù×÷ȨÏÞ,´Ó¶ø¶Áд/home/frank.Òª½â¾öÕâ¸öÎÊÌâ±ØÐëÕýÈ·ÅäÖÃexports,ÏÞÖÆ¿Í»§µÄÖ÷»úµØÖ·,Ã÷È·ÉèÖÃrw=hostµÄÑ¡Ïî,ro(Ö»¶Á)µÄÑ¡ÏîºÍaccess=hostµÄÑ¡Ïî.

ÁíÍâ,»¹ÓÐÒ»ÖÖUIDÆÛÆ­,ÊǹØÓÚ16λUIDºÍ32λUIDµÄÎÊÌâ.´ó¶àNFS·þÎñ½ÓÊܵÄÀ´×Ô¿Í»§¶ÔNFSÇëÇóËù·¢Ë͵ÄUID±êÖ¾¶¼ÊÇ16λµÄ(SolarisÊÇÒ»¸öÀýÍâ),ÕâÊDz»°²È«µÄ.ÔÚÕâÖÖÇé¿öÏÂ,Èç¹ûÓÃÒ»¸ö32λUID,²¢°ÑÕâ¸öUID×î×ó±ßµÄλÖÃÉèÖÃΪ0,ÄÇô,ÌåÏÖÔÚNFS serverÉÏ,½âÊÍΪ16λµÄUID,Õâ¸öUID¾ÍÏ൱ÓÚroot;ÈκÎÓû§ÒýÓÃ32λUID²¢ÇÒÕâ¸öUID×î×ó±ßµÄÊý×ÖÊÇ0,ÄÇô¾Í¿ÉÒÔ¶Á/дÊôÓÚrootµÄÈκÎÎļþ.Òª½â¾öÕâ¸öÎÊÌâ,¿ÉÒÔ´ÓSunµÄÕýʽվµã»ñÈ¡#1095935 ²¹¶¡.

3¡¢ÒÔÇ°µÄÎļþ¾ä±úÎÞÐëmountÊØ»¤½ø³ÌµÄ°ïÖú¾Í¿ÉÒÔ¹¹Ôì,ʹ¿Í»§Ö±½Ó¿ÉÒÔºÍNFSͨÐÅ.¶øÏÖÔÚµÄUnixϵͳ´ó¶à½øÐÐÁ˸Ľø.µ«BSDϵͳ»¹ÓÐÎÊÌâ.¹ØÓÚBSDÎļþ¾ä±úµÄÎÊÌâÉæ¼°BSD OS2.0,2.1,3.0;FreeBSD2.1.5~2.1.7,openBSD2.0ºÍ2.0ÒÔÇ°.ÆäËüһЩBSDÒ²¿ÉÄÜÓÐÀàËƵÄÎÊÌâ. ÀýÈçÔÚ4.4BSDÖÐ,ÓëÆäËüµÄUNixÎļþϵͳ²»Í¬µÄÊÇ,Ò»¸öÎļþµÄÐÅÏ¢,³ýÁË´´½¨Ê±¼ä¡¢Îļþ´óС¡¢Á¬½Ó¸öÊýºÍ¸üÐÂʱ¼äµÈÐÅÏ¢Íâ,»¹ÓÐÒ»¸öst_genÐÅÏ¢,st_genÊÇÒ»¸ö4λµÄÖµ,Ä¿µÄÊÇʹNFSÎļþ¾ä±úÄÑÓڲµ½.Õâ¸öÐÅÏ¢ÊÇstat(2)ϵͳµ÷ÓÃÉú³ÉµÄ.²»ÐÒµÄÊÇ,Õâ¸öµ÷ÓÃÓõ½µÄÒ»¸öº¯Êývn_stat()ÓÐÎÊÌâ:

...
sb->st_gen = vap->va_gen;
sb->st_blocks = vap->va_bytes / S_BLKSIZE;
return (0); }

ÉÏÃæÕâ¶Î³ÌÐòÂ뱩¶ÁËÓÃÀ´Éú³Ést_genÕâ¸öÊýµÄËùÓÐÐÅÏ¢,ÀûÓÃÕâЩÐÅÏ¢,δÊÚȨÓû§¿ÉÒԵõ½ÎļþµÄ¾ä±ú.ÕýÈ·µÄ³ÌÐòÓ¦¸ÃÖ»ÔÊÐíÕâЩÐÅÏ¢±©Â¶¸øroot:

ÒýÓÃ:
...
sb->st_flags = vap->va_flags;
if (suser(p->p_ucred, &p->p_acflag)) {
sb->st_gen = 0;
} else {
sb->st_gen = vap->va_gen;
}
sb->st_blocks = vap->va_bytes / S_BLKSIZE;
return (0);
}


ÕâÑù,Èç¹û²»ÊÇroot,ËûÖ»Äܵõ½0Õâ¸öÐÅÏ¢.

4¡¢×îΣÏյĴíÎóÊǰѺ¬ÓÐSUID³ÌÐòµÄĿ¼export,²¢ÇÒ¸ÃÎļþÓÐÖ´ÐÐȨ.SUID³ÌÐòÏ൱ÓÚ³¬¼¶Óû§±¾Éí.

½â¾ö·½°¸:

1¡¢ºÍ´ÓNTÖÐɾ³ýÈκι²ÏíµÄ½â¾ö·½°¸Ò»Ñù,×îºÃµÄ½â¾ö·½°¸ÊǽûÖ¹NFS·þÎñ,»òÒÔAFS·þÎñÈ¡¶ø´úÖ®(Andrew File System).

2¡¢Èç¹ûÒ»¶¨Òª¿ªNFS,²»ÒªÈÃÒ»¸öµ¥»ú¿ÉÒÔ¼ÈÊÇclient,Ò²ÊÇserver;

3¡¢export³öµÄÎļþϵͳֻÉèÖÃΪֻ¶Á

4¡¢½ûÖ¹ÄÇЩÓÐSUIDÌØÐԵijÌÐòµÄÖ´ÐÐ

5¡¢²»Òªexport home Ŀ¼

6¡¢²»Òªexport¿ÉÖ´ÐÐÌØÐÔ

7¡¢Ê¹ÓÃһЩ°²È«NFSʵÏÖ·½°¸(ËäȻδ±ØÕæµÄºÜ°²È«)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ