747-751.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 127 行
HTML
127 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:NIS and YP</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=44//-->
<!--PAGES=747-751//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="745-746.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="751-752.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Setting Up the NIS Master</FONT></H3>
<P>Setting up an NIS master is usually straightforward. Begin by verifying the existing files on the master machine, such as <TT>/etc/passwd</TT> and <TT>/etc/group</TT>, to ensure the information is accurate and current. You should remove any expired or unwanted accounts, for example, and verify that all the login directories and commands are correct. While you are examining the <TT>/etc/passwd</TT> file, check to make sure that all accounts have passwords. If they don’t, either assign a password or remove the account. With a network-wide NIS system in place, anyone can exploit these security holes to gain access to any machine on the network, including the NIS master and gateways machines.</P>
<P>After the files are ready for NIS map generation, make sure you are logged in as root, in order to set the proper ownerships and ensure full access to the filesystem. The NIS maps are generated from the standard UNIX files using the <TT>ypinit</TT> command with the <TT>-m</TT> option. The <TT>-m</TT> option indicates that this machine will be the NIS master. From the <TT>root</TT> prompt, issue the following command:</P>
<!-- CODE SNIP //-->
<PRE>
/usr/sbin/ypinit -m
</PRE>
<!-- END CODE SNIP //-->
<P>The path to the <TT>ypinit</TT> program may be different on your UNIX system. Check the path if the command produces an error message when trying to execute.</P>
<P>When the <TT>ypinit</TT> command executes, it scans all the NIS files named in the file <TT>/var/yp</TT> and produces the NIS maps that are used by the client processes. The <TT>/var/yp</TT> file may have a different directory name on some systems, such as SCO UNIX, which uses <TT>/etc/yp</TT> as a directory for all NIS files. Check your UNIX system documentation or man pages for proper file locations. The <TT>/var/yp</TT> file contains a list of all the maps to be generated, and you will usually not have to make any changes at all to this file.</P>
<P>A new directory (usually called <TT>/var/yp/<I>domainname</I>,</TT> where <I>domainname</I> is the NIS domain name) is created. The maps are placed in this new domain name. If you are setting up more than one domain all handled by the same NIS master machine, the maps for each domain will be beneath the domain name’s subdirectory.</P>
<P>As the last step in <TT>ypinit</TT>, you are asked which machines are NIS slave servers, at which point you should enter their names. The slave names are saved in a file in the domain directory.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>On some versions of Linux, the NIS utilities are not in the same directories mentioned throughout this chapter. A few versions move them to other locations. To verify the proper locations, use the <TT>find</TT> command with the program name.<HR></FONT>
</BLOCKQUOTE>
<P>After the maps have been generated properly, you can start the <TT>ypserv</TT> daemon. It is best to automate the startup by editing the startup <TT>rc</TT> files to do this for you when the machine boots. There is a section in an <TT>rc</TT> file (usually the one that starts RPC) that looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
if [ -f /etc/yp/ypserv -a -d /var/yp/‘domainname‘ ]
then
/etc/yp/ypserv
fi
</PRE>
<!-- END CODE SNIP //-->
<P>This script checks for the existence of the directory <TT>/var/yp/<I>domainname</I>,</TT> where <I>domainname</I> is the domain name for your NIS domain. The entry on the first line where <I>domainname</I> is located must be in single back quotes, which means the shell should execute the <TT>domainname</TT> command and use the results. If the directory exists, the <TT>ypserv</TT> daemon is started. You should replace the directory paths with those used by your UNIX system.</P>
<P>To manually start the <TT>ypserv</TT> daemon, log in as root and issue the following command, or whatever the path to your <TT>ypserv</TT> daemon is</P>
<!-- CODE SNIP //-->
<PRE>
/etc/yp/ypserv
</PRE>
<!-- END CODE SNIP //-->
<P>Next, you need to start the <TT>ypbind</TT> daemon on the server too (otherwise <TT>ypserv</TT> can’t find the maps). Again, this is usually done through the <TT>rc</TT> startup scripts with an entry like this:</P>
<!-- CODE SNIP //-->
<PRE>
if [ -d /var/yp ]
then
/etc/yp/ypbind
fi
</PRE>
<!-- END CODE SNIP //-->
<P>Again, you should check that the directory path is correct. You can start the <TT>ypbind</TT> daemon manually by issuing it on the command line when logged in as root. Make sure the directory path is correct when you do so.</P>
<P>If you want to perform a quick test of the NIS daemons, issue a command like this one at the command line:</P>
<!-- CODE SNIP //-->
<PRE>
ypmatch tparker passwd
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>ypmatch</TT> command asks NIS to use the maps to match up the next argument with the map of the third argument’s name. In this example, <TT>ypmatch</TT> is instructed to look in the <TT>passwd</TT> file (<TT>passwd</TT> is the alias to <TT>passwd.byname</TT>) for the entry for <TT>tparker</TT>. You should get back the line that matches. Use any combination of map alias and entry you know exists in order to test the NIS server daemon.</P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">Setting Up NIS Slaves</FONT></H3>
<P>In order to set up an NIS slave, the NIS master must be configured and running. When you are sure the master is operational, log in as root to the machine to be set up as the NIS slave. The domain name of the slave must be properly set before the configuration can proceed, so check the startup <TT>rc</TT> commands for the entry that sets the <TT>domainname</TT> variable or use the <TT>domainname</TT> command to set the domain name.</P>
<P>To set up the NIS slave and propagate the NIS files from the master to the slave, issue the following command, substituting for whatever path is correct on your system:</P>
<!-- CODE SNIP //-->
<PRE>
/etc/yp/ypbind
</PRE>
<!-- END CODE SNIP //-->
<P>Check that the binding to the master is correct by issuing the <TT>ypwhich</TT> command. It should return the NIS master name.</P>
<P>Finally, issue this command, where the path is correct and <TT>servername</TT> is the name of your NIS master:</P>
<!-- CODE SNIP //-->
<PRE>
/etc/yp/ypinit -s servername
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>ypbind -s</TT> option sets the local machine up as a slave. The <TT>ypbind</TT> command sets up directories on the local machine and transfers all the maps from the master to the slave.</P>
<P>After the setup is complete, you can test the slave setup with the <TT>ypmatch</TT> command as shown in the previous section.</P>
<P>To update the maps on the slaves at regular intervals, the <TT>ypxfer</TT> command is used on the slave, followed by the name of the map to be transferred. For example, this command transfers the <TT>passwd.byname</TT> file from the master to the slave:</P>
<!-- CODE SNIP //-->
<PRE>
ypxfer passwd.byname
</PRE>
<!-- END CODE SNIP //-->
<P>Most administrators either create a set of <TT>cron</TT> entries for transferring all the NIS files at regular intervals (such as nightly) or use a script file executed by a network adminis-trator.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="745-746.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="751-752.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?