740-744.html

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

HTML
151
字号
<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=740-744//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="737-740.html">Previous</A></TD>

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

<TD><A HREF="../ch44/745-746.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P>The format of the <TT>/etc/exports</TT> file follows:</P>

<!-- CODE SNIP //-->

<PRE>

directory [ -option, option &#133; ]

</PRE>

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

<P><TT>directory</TT> is the pathname of the directory or file to be shared (<I>exported</I>, in NFS terminology) by NFS, and options can be chosen from the following:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>ro</TT> Export the directory as read-only. (The default value is to export as read-write.)

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>rw=hostnames</TT> Export the directory as read-mostly, which means read-only to most machines but read-write to specifically identified machines.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>anon=uid</TT> If an NFS request comes from an unknown user, use <TT>uid</TT> as the effective user ID for ownership and permissions.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>root=hostnames</TT> Give root access to the root users from a specified machine.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>access=client</TT> Give mount access to each client listed. A client can be a host name or a net group.

</DL>

<P>An example of an <TT>/etc/exports</TT> file helps to show the use of these options. A pound sign on a line means a comment. Here&#146;s a sample <TT>/etc/exports</TT> file:</P>

<!-- CODE SNIP //-->

<PRE>

/usr/stuff -ro         # export as read-only to anyone

/usr  -access=clients  # export to the group called clients

/usr/public            # export as read-write to anyone

</PRE>

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

<P>If you make changes to the <TT>/etc/exports</TT> file, shut down the NFS server daemons and start them up again. Issue an exportfs command and the system should display the names of all exported filesystems. NFS is now ready for use on your server.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>WARNING:&nbsp;&nbsp;</B><BR>You may notice that some versions of Linux create a new file called <TT>/etc/xtab</TT>, which contains the filesystem information. Do not edit this file! You should not modify the contents, or the NFS server will not function properly. The <TT>/etc/xtab</TT> file is generated by the <TT>exportfs</TT> command.<HR></FONT>

</BLOCKQUOTE>

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

<P>Some versions of Linux use the <TT>share</TT> command to set up a directory for export. (Many versions of Linux do not support the <TT>share</TT> command because the functions are duplicated in the <TT>/etc/exports</TT> file.) The syntax of the <TT>share</TT> command follows:</P>

<!-- CODE SNIP //-->

<PRE>

share -F nfs -o options -d description path

</PRE>

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

<P>Where the <TT>-F</TT> option indicates that the directory or files given in <TT>path</TT> are to be set as NFS filesystems. The options following <TT>-o</TT> set the type of access in the same way as the <TT>/etc/exports</TT> file shown above. The <TT>-d</TT> option can be followed by a descriptive statement used by clients to describe the export filesystem. For example, to share the direc-tory <TT>/usr/public</TT> as read-write (the default), you could issue the following command:</P>

<!-- CODE SNIP //-->

<PRE>

share -F nfs -d &#147;Server public directory&#148; /usr/public

</PRE>

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

<P>You can combine options, as shown in this example:

</P>

<!-- CODE SNIP //-->

<PRE>

share -F nfs -o ro=artemis,anon=200 -d &#147;Book material&#148; /usr/tparker/book

</PRE>

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

<P>This command shares the directory <TT>/usr/tparker/book</TT>, which is tagged with the description <TT>&#147;Book material&#148;</TT>, with everyone as read-write except for a machine called <TT>artemis</TT>, for which it is read-only. Any anonymous users accessing the system use UID 200.</P>

<P>The <TT>share</TT> command by itself usually shows you a list of all filesystems that are exported.</P>

<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">Setting Up a Linux Client</FONT></H4>

<P>Linux can mount an NFS-exported filesystem from another machine with the <TT>mount</TT> command. The syntax for mounting an NFS filesystem follows:</P>

<!-- CODE SNIP //-->

<PRE>

mount -F nfs -o options machine:filesystem mount-point

</PRE>

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

<P>The <TT>-F</TT> option tells the <TT>mount</TT> command the filesystem is an NFS filesystem, <TT>machine:filesystem</TT> is the name of the remote machine and the filesystem to be mounted, and <TT>mount-point</TT> is the location in the current filesystem that the remote filesystem is to be mounted. Some versions of Linux change the syntax a little. For example, some versions use a lowercase <I>f</I> and uppercase <I>NFS</I> to indicate the type. Check the man pages for exact syntax on your version.</P>

<P>In use, <TT>mount</TT> is easy to work with. For example, the following command mounts the filesystem <TT>/usr/public</TT> on the remote machine called <TT>artemis</TT> on the local machine in the directory called <TT>/usr/artemis</TT>:</P>

<!-- CODE SNIP //-->

<PRE>

mount -F nfs artemis:usr/public /usr/artemis

</PRE>

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

<P>The mount point (in this case <TT>/usr/artemis</TT>) must exist for the mount to succeed.</P>

<P>The <TT>-o</TT> optional component of the <TT>mount</TT> command can be used to set options from the following list:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>rw</TT> Sets the mount read-write (the default value).

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>ro</TT> Sets the mount read-only.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>timeo=x</TT> Gives a timeout value in tenths of a second to attempt the mount before giving up.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>retry=x</TT> Retries <I>x</I> times before giving up.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>soft</TT> Forces the client to give up the mount attempt if an acknowledgment is not received from the remote.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>hard</TT> The client continues trying to mount the filesystem until successful.

<DD><B>&#149;</B>&nbsp;&nbsp;<TT>intr</TT> Allows the keyboard to interrupt the mount request; otherwise, the attempts go on indefinitely.

</DL>

<P>Any of these options can be combined in one <TT>mount</TT> command, as they could be for the <TT>share</TT> command. For example, the following command line tries to mount the <TT>/usr/public</TT> directory on <TT>artemis</TT> as read-only, but gives up if the mount attempt is not acknowledged by <TT>artemis</TT>:</P>

<!-- CODE SNIP //-->

<PRE>

mount -F nfs -o soft,ro artemis:usr/public /usr/artemis

</PRE>

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

<P>The <TT>mount</TT> command by itself usually shows all mounted filesystems.</P>

<P>There is a simpler way to mount commonly used directories. Put the names of the directories and their mount points in the <TT>/etc/fstab</TT> or <TT>/etc/vfstab</TT> file (the file to use depends on the version of Linux). Then you can mount the files by simply issuing the mount point name. For example, this command mounts the proper filesystem as <TT>/skunk</TT>:</P>

<!-- CODE SNIP //-->

<PRE>

mount /skunk

</PRE>

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

<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Summary</FONT></H3>

<P>As you have seen in this chapter, NFS is not very complex to set up, either as a client or server. With a few minutes work you can start sharing your directories and accessing directories on other machines. NFS is a very fast and easy way to access applications and copy files on remote machines. Although the configuration is dependent on the operating system version, a quick check of help screens or man pages will show you the proper format of the commands used in this chapter.

</P>

<P>From here you can find related information:</P>

<DL>

<DD>NIS and YP, which let you manage passwords network-wide, are discussed in Chapter 44, &#147;NIS and YP.&#148;

<DD>Automating processes on your system using the <TT>cron</TT> utility, very handy for system administrators, is discussed in Chapter 46, &#147;<TT>cron</TT> and <TT>at</TT>.&#148;

<DD>Setting up an Internet server is discussed in Chapter 47, &#147;Setting up an Internet Site.&#148;

</DL>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="737-740.html">Previous</A></TD>

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

<TD><A HREF="../ch44/745-746.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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