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

½ÌÄãÓý¨Á¢nfsϵͳ¡«¡«

·¢²¼Ê±¼ä:2012-02-10 08:35:53À´Ô´:ºìÁª×÷Õß:txbest
Ç°ÌᣬÁ½PC or PC-target board£¬±ØÐëÔÚͬһÍø¶Î£¬½»²æÏßÖ±Á¬»ò·ÓÉ»òhub¶¼¿É
Èç¹ûÏëѧϰ½»²æÍøÏßÖ±Á¬ÉèÖã¬Çë¿´
http://www.linuxdiyf.com/bbs/viewthread.php?tid=271395&extra=

ÔÚÓ¦ÓóÌÐò¿ª·¢»·½Ú£¬NFS·½Ê½±Èftp·½Ê½µÄÖ´ÐÐЧÂÊÒª¸ß£¬ÒòΪËü²»ÐèÒª½«linux server¶ËµÄ³ÌÐòÏÂÔص½Ç¶ÈëʽĿ±êϵͳ¾Í¿ÉÒÔµ÷ÊÔ¡£ÏÂÃæÏȽ«NFS½¨Á¢µÄÏêϸ¹ý³ÌдһÏ£¬È»ºó¾ÙÒ»¸ö¼òµ¥µÄÓ¦ÓóÌÐò¿ª·¢ÊµÀýÀ´±È½Ïftp·½Ê½ºÍnfs·½Ê½µÄ²»Í¬¡£
0 ÏÂÔØNFSºÍportmap°²×°
$ sudo apt-get install nfs-kernel-server nfs-common portmap

1 ½¨Á¢NFS¿ª·¢»·¾³
    ǶÈëʽlinuxµÄNFS¿ª·¢»·¾³°üº¬×ÅÁ½¸ö·½Ã棺һÊÇlinux server¶ËµÄNFS ServerÖ§³Ö£»¶þÊÇtarget boardµÄNFS ClientÖ§³Ö¡£
1.1 linux server¶Ë
1.1.1 ÒÔrootµÄÉí·ÝµÇ¼£¬±àÒë¹²ÏíĿ¼µÄÅäÖÃÎļþexports£¬Ö¸¶¨¹²ÏíĿ¼¼°ÆäȨÏÞ¡£
££vi /etc/exports
ÔÚ¸ÃÎļþÖÐÌí¼Ó£º
/home/lqm(¹²ÏíĿ¼£© 192.168.1.*(rw,sync,no_root_squash)
Ìí¼ÓµÄÄÚÈݱíʾÔÊÐíIP·¶Î§ÔÚ192.168.1.*µÄ¼ÆËã»úÒÔ¶ÁдµÄȨÏÞÀ´·ÃÎʹ²ÏíĿ¼/home/lqm¡£
¡¾×¢£º²ÎÊý˵Ã÷ÈçÏ£º
     rw£­£­£­¶Á/дȨÏÞ¡£Èç¹ûÉ趨ֻ¶ÁȨÏÞ£¬ÔòÉèΪro¡£µ«ÊÇÒ»°ãÇé¿öÏ£¬ÎªÁË·½±ã½»»¥£¬ÒªÉèÖÃΪrw¡£
     sync£­£­Êý¾Ýͬ²½Ð´ÈëÄÚ´æºÍÓ²ÅÌ¡£
     no_root_squash£­£­´Ë²ÎÊýÓÃÀ´ÒªÇó·þÎñÆ÷ÔÊÐíÔ¶³ÌϵͳÒÔËü×Ô¼ºµÄrootÌØȨ´æÈ¡¸ÃĿ¼¡£¾ÍÊÇ˵£¬Èç¹ûÓû§ÊÇroot£¬ÄÇôËû¾Í¶ÔÕâ¸ö¹²ÏíĿ¼ÓÐrootµÄȨÏÞ¡£ºÜÃ÷ÏÔ£¬¸Ã²ÎÊýÊÚÓèÁËtarget boardºÜ´óµÄȨÀû¡£°²È«ÐÔÊÇÊ×ÏÈÒª¿¼Âǵģ¬¿ÉÒÔ²ÉÈ¡Ò»¶¨µÄ±£»¤»úÖÆ£¬ÔÚÏÂÃæ»á½²Ò»Ï±£»¤»úÖÆ¡£Èç¹ûʹÓÃĬÈϵÄroot_squash£¬target board×Ô¼ºµÄ¸ùÎļþϵͳ¿ÉÄÜÓкܶàÎÞ·¨Ð´È룬ËùÒÔÔËÐлáÊܵ½¼«´óµÄÏÞÖÆ¡£ÔÚ°²È«ÐÔÓÐËù±£ÕϵÄÇ°ÌáÏ£¬ÍƼöʹÓÃno_root_squash²ÎÊý¡£¡¿
1.1.2 ÆðÓñ£»¤»úÖÆ
¿ÉÒÔͨ¹ýÉ趨/etc/hosts.denyºÍ/etc/hosts.allowÎļþÀ´ÏÞÖÆÍøÂç·þÎñµÄ´æȡȨÏÞ¡£
***/etc/hosts.deny***
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL
***/etc/hosts.allow***
portmap:192.168.1.100
lockd:192.168.1.100
mountd:192.168.1.100
rquotad:192.168.1.100
statd:192.168.1.100
ͬʱʹÓÃÕâÁ½¸öÎļþ¾Í»áʹµÃÖ»ÓÐipΪ192.168.1.100µÄ»úÆ÷ʹÓÃNFS·þÎñ¡£ÄãµÄtarget boardµÄipµØÖ·É趨Ϊ192.168.1.100£¬ÕâÑù¾Í¿ÉÒÔÁË¡£
1.1.3 Æô¶¯
Ê×ÏÈÒªÆô¶¯portmapper£¨¶Ë¿ÚÓ³É䣩·þÎñ£¬ÕâÊÇNFS±¾ÉíÐèÒªµÄ¡£
££/etc/init.d/portmap start
È»ºóÆô¶¯NFS Server¡£´ËʱNFS»á¼¤»îÊØ»¤½ø³Ì£¬È»ºó¿ªÊ¼¼àÌý¿Í»§¶ËµÄÇëÇó¡£
££/etc/init.d/nfs start
NFS ServerÆô¶¯ºó£¬»¹Òª¼ì²éÒ»ÏÂlinux serverµÄiptablesµÈ£¬È·¶¨Ã»ÓÐÆÁ±ÎNFSʹÓõĶ˿ںÍÔÊÐíͨÐŵÄÖ÷»ú¡£
¿ÉÒÔÊ×ÏÈÔÚlinux serverÉÏÃæ½øÐÐNFSµÄ»Ø»·²âÉè¡£ÐÞ¸Ä/etc/hosts.allow£¬°Ñip¸ÄΪlinux serverµÄipµØÖ·£¬È»ºóÔÚlinux serverÉÏÖ´ÐÐÃüÁ
££mount -t nfs :/home/lqm /mnt
££ls /mnt
Èç¹ûNFS ServerÕý³£¹¤×÷£¬Ó¦¸ÃÔÚ/mntÏÂÃæ¿´µ½¹²ÏíĿ¼/home/lqmµÄÄÚÈÝ¡£
1.2 target board¶ËµÄclient
1.2.1 ǶÈëʽlinuxÄÚºËÓ¦¸ÃÖ§³ÖNFS¿Í»§¶Ë¡£
ÄÚºËÅäÖÃʱ£¬Ñ¡ÔñÈçÏ£º
File system--> Network File Systems-->
Ñ¡ÖÐNFS System supportºÍProvide NFSvs client support£¬È»ºó±£´æÍ˳ö£¬ÖØбàÒëÄںˣ¬½«Éú³ÉµÄzImageÖØÐÂÏÂÔص½target board¡£
1.2.2 ÔÚtarget boardµÄlinux shellÏ£¬Ö´ÐÐÏÂÁÐÃüÁîÀ´½øÐÐNFS¹²ÏíĿ¼µÄ¹ÒÔØ¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÓÉÓںܶàǶÈëʽÉ豸µÄ¸ùÎļþϵͳÖв»´øportmap£¬ËùÒÔÒ»°ã¶¼Ê¹ÓÃ-o nolock²ÎÊý£¬¼´²»Ê¹ÓÃNFSÎļþËø£¬ÕâÑù¾Í¿ÉÒÔ±ÜÃâʹÓÃportmap¡£Èç¹û˳Àû£¬ÔÚ/mnt/nfsÏ£¬¾Í¿ÉÒÔ¿´µ½linux serverµÄ¹²ÏíÎļþ¼ÐϵÄÄÚÈÝÁË£¬¶øÇÒÁ½¸öÎļþ¼ÐÄÚµÄÐÞ¸ÄÊÇͬ²½µÄ¡£
2 Ó¦ÓóÌÐòʵÀý
±àдһ¸ö¼òµ¥µÄC³ÌÐòtest.c
-------------------------------------------
/*This is a test program.*/
int main(void)
{
int i;
for(i=0;i<10;i++)
     printf("Hello World %d times.\n",i);
return 0;
}
-------------------------------------------
±àÒë¸Ã³ÌÐò£º
££arm-linux-gcc -o test test.c
2.1 FTP·½Ê½
Ê×ÏȽ«testÏÂÔص½target board¡£Æô¶¯target boardµÄlinux£¬ÔÚ³¬¼¶ÖÕ¶ËÖÐÖ´ÐУº
££cd /var
££ftp
ftp>bin                //ÒÔbinary mode´«ÊäÎļþ
ftp>get test
ftp>exit
È»ºóÐÞ¸ÄÎļþÊôÐÔ£º
££chmod +x test
££./test
Õâʱ¿ÉÒԲ鿴½á¹ûÁË¡£
2.2 NFS·½Ê½
ÔÚtarget board¶Ë¹ÒÔØlinux serverµÄ¹²ÏíÊä³öĿ¼£¬²¢ÇÒÔËÐгÌÐò¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÕâʱӦ¸Ã¿ÉÒÔÏÔʾlinux serverµÄ¹²ÏíĿ¼µÄÄÚÈÝ¡£È»ºóÖ´ÐУº
££./test
3 ×ܽá
    ÕâÁ½ÖÖ·½Ê½ÔÚÓ¦ÓóÌÐò²»ÊÇÌرð¸´ÔÓʱÇø±ð²»ÊǺܴ󣬵«Êǵ±¿ª·¢³ÌÐò±È½Ï¸´ÔÓʱ£¬²ÉÓÃNFS·½Ê½ÏÔȻЧÂÊÒª¸ßµÃ¶à¡£Íê³ÉÓ¦ÓóÌÐòµÃ¿ª·¢£¬µ÷ÊԺúó¾Í¿ÉÒÔÏÂÔØ µ½Ç¶ÈëʽĿ±ê°åµÄflashÎļþϵͳ£¬»òÕßÖ±½Ó±àÒ뵽ǶÈëʽlinuxÄں˲¢ÇÒÉÕдµ½flash£¬´Ó¶ø×îÖÕ³ÉΪһ¸ö¶ÀÁ¢µÄǶÈëʽӦÓóÌÐò¡£
££ls /mnt
Èç¹ûNFS ServerÕý³£¹¤×÷£¬Ó¦¸ÃÔÚ/mntÏÂÃæ¿´µ½¹²ÏíĿ¼/home/lqmµÄÄÚÈÝ¡£
1.2 target board¶ËµÄclient
1.2.1 ǶÈëʽlinuxÄÚºËÓ¦¸ÃÖ§³ÖNFS¿Í»§¶Ë¡£
ÄÚºËÅäÖÃʱ£¬Ñ¡ÔñÈçÏ£º
File system--> Network File Systems-->
Ñ¡ÖÐNFS System supportºÍProvide NFSvs client support£¬È»ºó±£´æÍ˳ö£¬ÖØбàÒëÄںˣ¬½«Éú³ÉµÄzImageÖØÐÂÏÂÔص½target board¡£
1.2.2 ÔÚtarget boardµÄlinux shellÏ£¬Ö´ÐÐÏÂÁÐÃüÁîÀ´½øÐÐNFS¹²ÏíĿ¼µÄ¹ÒÔØ¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÓÉÓںܶàǶÈëʽÉ豸µÄ¸ùÎļþϵͳÖв»´øportmap£¬ËùÒÔÒ»°ã¶¼Ê¹ÓÃ-o nolock²ÎÊý£¬¼´²»Ê¹ÓÃNFSÎļþËø£¬ÕâÑù¾Í¿ÉÒÔ±ÜÃâʹÓÃportmap¡£Èç¹û˳Àû£¬ÔÚ/mnt/nfsÏ£¬¾Í¿ÉÒÔ¿´µ½linux serverµÄ¹²ÏíÎļþ¼ÐϵÄÄÚÈÝÁË£¬¶øÇÒÁ½¸öÎļþ¼ÐÄÚµÄÐÞ¸ÄÊÇͬ²½µÄ¡£
2 Ó¦ÓóÌÐòʵÀý
±àдһ¸ö¼òµ¥µÄC³ÌÐòtest.c
-------------------------------------------
/*This is a test program.*/
int main(void)
{
int i;
for(i=0;i<10;i++)
     printf("Hello World %d times.\n",i);
return 0;
}
-------------------------------------------
±àÒë¸Ã³ÌÐò£º
££arm-linux-gcc -o test test.c
2.1 FTP·½Ê½
Ê×ÏȽ«testÏÂÔص½target board¡£Æô¶¯target boardµÄlinux£¬ÔÚ³¬¼¶ÖÕ¶ËÖÐÖ´ÐУº
££cd /var
££ftp
ftp>bin                //ÒÔbinary mode´«ÊäÎļþ
ftp>get test
ftp>exit
È»ºóÐÞ¸ÄÎļþÊôÐÔ£º
££chmod +x test
££./test
Õâʱ¿ÉÒԲ鿴½á¹ûÁË¡£
2.2 NFS·½Ê½
ÔÚtarget board¶Ë¹ÒÔØlinux serverµÄ¹²ÏíÊä³öĿ¼£¬²¢ÇÒÔËÐгÌÐò¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÕâʱӦ¸Ã¿ÉÒÔÏÔʾlinux serverµÄ¹²ÏíĿ¼µÄÄÚÈÝ¡£È»ºóÖ´ÐУº
££./test
3 ×ܽá
    ÕâÁ½ÖÖ·½Ê½ÔÚÓ¦ÓóÌÐò²»ÊÇÌرð¸´ÔÓʱÇø±ð²»ÊǺܴ󣬵«Êǵ±¿ª·¢³ÌÐò±È½Ï¸´ÔÓʱ£¬²ÉÓÃNFS·½Ê½ÏÔȻЧÂÊÒª¸ßµÃ¶à¡£Íê³ÉÓ¦ÓóÌÐòµÃ¿ª·¢£¬µ÷ÊԺúó¾Í¿ÉÒÔÏÂÔØ µ½Ç¶ÈëʽĿ±ê°åµÄflashÎļþϵͳ£¬»òÕßÖ±½Ó±àÒ뵽ǶÈëʽlinuxÄں˲¢ÇÒÉÕдµ½flash£¬´Ó¶ø×îÖÕ³ÉΪһ¸ö¶ÀÁ¢µÄǶÈëʽӦÓóÌÐò¡£
£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­£­
²Î¿¼ÊéÄ¿£º¡¶building embedded linux systems¡·
                   ¡¶Ç¶Èëʽlinuxϵͳ¿ª·¢Ïê½â£­£­»ùÓÚEP93XXϵÁÐARM¡·
ÕâÁ½±¾ÊéÔÚ¹ý³ÌÉ϶¼±È½ÏϸÖ£¬ºÜÊʺϳõѧÕßѧϰ¡£ÔÚʵ¼ùÊìϤµÄ»ù´¡ÉÏ£¬ÌáÉýÀíÂ۸߶ȣ¬ÕâÊÇÎÒËùÈϿɵÄѧϰ·½·¨¡£








ÏÂÃæÊÇһЩ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
££ls /mnt
Èç¹ûNFS ServerÕý³£¹¤×÷£¬Ó¦¸ÃÔÚ/mntÏÂÃæ¿´µ½¹²ÏíĿ¼/home/lqmµÄÄÚÈÝ¡£
1.2 target board¶ËµÄclient
1.2.1 ǶÈëʽlinuxÄÚºËÓ¦¸ÃÖ§³ÖNFS¿Í»§¶Ë¡£
ÄÚºËÅäÖÃʱ£¬Ñ¡ÔñÈçÏ£º
File system--> Network File Systems-->
Ñ¡ÖÐNFS System supportºÍProvide NFSvs client support£¬È»ºó±£´æÍ˳ö£¬ÖØбàÒëÄںˣ¬½«Éú³ÉµÄzImageÖØÐÂÏÂÔص½target board¡£
1.2.2 ÔÚtarget boardµÄlinux shellÏ£¬Ö´ÐÐÏÂÁÐÃüÁîÀ´½øÐÐNFS¹²ÏíĿ¼µÄ¹ÒÔØ¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÓÉÓںܶàǶÈëʽÉ豸µÄ¸ùÎļþϵͳÖв»´øportmap£¬ËùÒÔÒ»°ã¶¼Ê¹ÓÃ-o nolock²ÎÊý£¬¼´²»Ê¹ÓÃNFSÎļþËø£¬ÕâÑù¾Í¿ÉÒÔ±ÜÃâʹÓÃportmap¡£Èç¹û˳Àû£¬ÔÚ/mnt/nfsÏ£¬¾Í¿ÉÒÔ¿´µ½linux serverµÄ¹²ÏíÎļþ¼ÐϵÄÄÚÈÝÁË£¬¶øÇÒÁ½¸öÎļþ¼ÐÄÚµÄÐÞ¸ÄÊÇͬ²½µÄ¡£
2 Ó¦ÓóÌÐòʵÀý
±àдһ¸ö¼òµ¥µÄC³ÌÐòtest.c
-------------------------------------------
/*This is a test program.*/
int main(void)
{
int i;
for(i=0;i<10;i++)
     printf("Hello World %d times.\n",i);
return 0;
}
-------------------------------------------
±àÒë¸Ã³ÌÐò£º
££arm-linux-gcc -o test test.c
2.1 FTP·½Ê½
Ê×ÏȽ«testÏÂÔص½target board¡£Æô¶¯target boardµÄlinux£¬ÔÚ³¬¼¶ÖÕ¶ËÖÐÖ´ÐУº
££cd /var
££ftp
ftp>bin                //ÒÔbinary mode´«ÊäÎļþ
ftp>get test
ftp>exit
È»ºóÐÞ¸ÄÎļþÊôÐÔ£º
££chmod +x test
££./test
Õâʱ¿ÉÒԲ鿴½á¹ûÁË¡£
2.2 NFS·½Ê½
ÔÚtarget board¶Ë¹ÒÔØlinux serverµÄ¹²ÏíÊä³öĿ¼£¬²¢ÇÒÔËÐгÌÐò¡£
££mkdir /mnt/nfs
££mount -o nolock -t nfs :/home/lqm /mnt/nfs
££ls /mnt/nfs
ÕâʱӦ¸Ã¿ÉÒÔÏÔʾlinux serverµÄ¹²ÏíĿ¼µÄÄÚÈÝ¡£È»ºóÖ´ÐУº
££./test
3 ×ܽá
    ÕâÁ½ÖÖ·½Ê½ÔÚÓ¦ÓóÌÐò²»ÊÇÌرð¸´ÔÓʱÇø±ð²»ÊǺܴ󣬵«Êǵ±¿ª·¢³ÌÐò±È½Ï¸´ÔÓʱ£¬²ÉÓÃNFS·½Ê½ÏÔȻЧÂÊÒª¸ßµÃ¶à¡£Íê³ÉÓ¦ÓóÌÐòµÃ¿ª·¢£¬µ÷ÊԺúó¾Í¿ÉÒÔÏÂÔØ µ½Ç¶ÈëʽĿ±ê°åµÄflashÎļþϵͳ£¬»òÕßÖ±½Ó±àÒ뵽ǶÈëʽlinuxÄں˲¢ÇÒÉÕдµ½flash£¬´Ó¶ø×îÖÕ³ÉΪһ¸ö¶ÀÁ¢µÄǶÈëʽӦÓóÌÐò¡£

Îáת×Ô:http://tensing.blog.sohu.com/77399040.html
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 2 ÌõÆÀÂÛ

  1. txbest ÓÚ 2012-02-10 11:00:01·¢±í:

    ×Ô¼º¶¥¶¥

  2. yzs ÓÚ 2012-02-10 08:57:20·¢±í:

    ѧϰ