737-740.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 127 行

HTML
127
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:NFS</TITLE>

<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=43//-->

<!--PAGES=737-740//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch42/735-736.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="740-744.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 43<BR>NFS

</FONT></H2>

<P><I>by Tim Parker</I></P>

<DL>

<DT><B>In This Chapter</B>

<DT>&#149;&nbsp;&nbsp; Configuring Linux for NFS

</DL>

<P>The Network File System (NFS) was created by Sun Microsystems to share files and directories among UNIX operating systems. With NFS, when a file or directory is shared, it appears to be part of your system instead of on some remote machine. For example, if you had a Linux machine in your basement that had a filesystem full of games, NFS would let you set that games filesystem so that it appeared on your own machine as part of the standard directory structure. Every time you access the games area, you&#146;re going over the network to the other machine, but that&#146;s all transparent to you (except for time delays), thanks to NFS.

</P>

<P>NFS can be used with different types of networks, but it was really designed to work with TCP/IP. NFS is still most often used over TCP/IP networks. Because of its popularity, implementations of NFS have been created on other operating systems so that directories can be shared across heterogeneous networks.</P>

<P>Under UNIX and Linux, NFS operates in peer-to-peer mode. This really means that your computer can act as a client of NFS services on another machine as well as a server to other machines on the network, or both simultaneously.</P>

<P>Many people love using the Network File System service at their business, but are scared to configure it themselves at home on their Linux system. They reason that the process must be convoluted, complex, and require a lot of knowledge about the operating systems. For this reason, many people don&#146;t bother with NFS, which is a shame because it is one of the most useful services TCP/IP has to offer. As you will see in this chapter, it is not difficult to implement an NFS network, either. All it takes is a little time. Of course, you should have more than one machine on your network to take advantage of the service, too.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B><BR>Some newer products such as VisionFS make setting up and using network-mounted drives much easier. Ports of these products are available for Linux, although they are commercial.<HR></FONT>

</BLOCKQUOTE>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Configuring Linux for NFS</FONT></H3>

<P>The NFS service makes extensive use of the Remote Procedure Call service. For this reason, the RPC server daemon must be running for NFS to be implemented. On some Linux systems you can check whether RPC is active by issuing this command at the shell prompt:

</P>

<!-- CODE SNIP //-->

<PRE>

rpcinfo -p

</PRE>

<!-- END CODE SNIP //-->

<P>When you do, you should see a list of all the RPC servers currently running on your machine, such as these:

</P>

<!-- CODE //-->

<PRE>

[root&#64;linux tparker]# rpcinfo -p

   program vers proto  port

    100000    2   tcp   111  portmapper

    100000    2   udp   111  portmapper

    300019    1   udp   737

    100001   13   udp   791  rstatd

    100001    3   udp   791  rstatd

    100001    2   udp   791  rstatd

    100001    1   udp   791  rstatd

    100001   13   tcp   796  rstatd

    100001    3   tcp   796  rstatd

    100001    2   tcp   796  rstatd

    100001    1   tcp   796  rstatd

</PRE>

<!-- END CODE //-->

<P>If RPC is running properly, you will see at least four <TT>rpcbind</TT> listings (two for UDP and two for TCP) and an entry for <TT>pcnfsd</TT>, the NFS daemon. In the example above, there is no <TT>pcnfsd</TT> entry, so we know the NFS daemon is not active yet.</P>

<P>You must have loaded the NFS routines when Linux was installed to be able to run NFS on your system (Linux often prompts you whether you want NFS active when you run the installation script). If you didn&#146;t load it during your initial program load, add it when you need it through whatever Disk Set installation routine is supplied with your version of Linux. Some systems, such as Caldera&#146;s OpenLinux and many Slackware releases, load NFS automatically when the system boots, whether you use it or not.</P>

<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">Configuring Linux Servers</FONT></H4>

<P>With most versions of Linux, NFS is started and stopped by a script called <TT>/etc/nfs</TT>. This can be linked into the startup routines to automatically load NFS when the system boots by linking the <TT>/etc/nfs</TT> file to the file <TT>/etc/rc2.d/Sname</TT>. To shut down NFS properly, you need to also link <TT>/etc/nfs</TT> to the file <TT>/etc/rc0.d/Kname</TT>. If you want to manually start and stop the NFS daemon, you can do this with the following commands:</P>

<!-- CODE SNIP //-->

<PRE>

/etc/nfs start



/etc/nfs stop

</PRE>

<!-- END CODE SNIP //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B><BR>Some versions of Linux use different files and directories for NFS scripts and configuration information. If the files mentioned in this chapter don&#146;t seem to exist, try using <TT>/etc/rc.d/init.d/nfs</TT> or <TT>/etc/init.d/nfs</TT> for the startup script file.<HR></FONT>

</BLOCKQUOTE>

<P>The <TT>/etc/nfs</TT> command starts up and shuts down the NFS server daemon when the appropriate command is issued. When you issue the <TT>start</TT> command, the daemons that are activated are echoed to the screen:</P>

<!-- CODE SNIP //-->

<PRE>

&#36; /etc/nfs start

Starting NFS services: exportfs mountd nfsd pcnfsd biod(x4)

Starting NLM services: statd lockd

</PRE>

<!-- END CODE SNIP //-->

<P>With a <TT>stop</TT> command, you see a message that the daemons and server are shut down:</P>

<!-- CODE SNIP //-->

<PRE>

&#36; /etc/nfs stop

NFS shutdown: [NFS Shutdown Complete]

</PRE>

<!-- END CODE SNIP //-->

<P>For a filesystem on a Linux machine to be available to NFS clients on other systems, the filesystem must be listed in the file <TT>/etc/exports</TT>. With some versions of Linux, the NFS daemons starts automatically if the <TT>/etc/exports</TT> file exists during boot time. This invokes a program called <TT>exportfs</TT>, which sets the filesystem as available for NFS use. If any changes are made to the <TT>/etc/exports</TT> file while the system is running, you can issue another <TT>exportfs</TT> command or simply reboot the machine to make the changes effective.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch42/735-736.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="740-744.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?