个人工具

Quick HOWTO : Ch30 : Configuring NIS/zh

来自Ubuntu中文

跳转至: 导航, 搜索


介绍

网络用户信息服务(NIS)使你可以在你的网络中创建账户并在所有的系统共享。这个账户只能在NIS的服务器上创建。NIS客户端从NIS服务器下载需要的用户名和密码数据来验证用户的登录。

NIS的一个优点是用户只需要在NIS服务器上更改他们的密码,而不必在网络上的每个系统上去更改密码。这使得NIS在计算机实验室很流行,使用在一些分布式软件开发项目和组内成员必须共享很多不同的电脑的情况下。


缺点是NIS没有加密登录时发送到客户端的用户名和密码信息,所有用户有访问在存储NIS服务器加密的密码信息的权限。关于NIS安全细节的分析在这本书的前面部分,但是我建议你限制使用NIS在高安全的网络中,或者有权访问非NIS网络是有很高的限制的网络。

轻量级目录访问协议提供了和NIS相似的特性,但是不依靠额外的软件可以支持加密,并且支持客户端可以不依靠从机访问多重网络。因为这个原因,LDAP在这个应用上十分流行。LDAP更所细节的讨论在31章,"Centralized Logins Using LDAP and RADIUS".

方案

为了理解NFS的好处,考虑一个例子。一个学校要为学生建立一个小型计算机实验室。

  • 主要的Linux服务器,bigboy,有很大的磁盘空间,会被同时用作NIS服务器和为实验室的Linux PC提供基于NFS文件系统的服务器。
  • 登录到PC的用户会被分配一个主目录,这个目录在bigboy上而不是在这些PC上。
  • 每个用户的主目录会用NFS自动挂载在用户登录的PC上。
  • 在其它PC实行使用NIS前,实验室的教师会在一个名字为smallfry 的Linux PC 上练习。
  • NIS RPMs 套件会被安装在服务器和客户端;ypserve 和yp-tools 在服务器,ypbind 和 yp-tools 在客户端。

下载安装RPM并不难,将在第六章讨论,"Installing Linux Software". 搜索RPM时,记住文件的名字一般是软件包的名字后面跟着版本号,就像yp-tools-2.8-3.i386.rpm.

实验室教师会做一些研究并且谋划一个实现计划:

  1. 配置bigboy,把它作为一个NFS服务器使它的 /home 目录对Linux工作站是可用的。
  2. 配置smallfry ,把它作为一个可以访问bigbos 的 /home 目录的客户端。
  3. 配置bigboy,把它作为一个NIS服务器。
  4. 在bigboy 上创建一个用户账号(nisuser),这个用户在smallfry 上并不存在。将这个用户转变为NIS用户账号。
  5. 将smallfry 配置为一个NIS客户端。
  6. 测试远程登录,用nisuser 这个用户的账号和密码从bigboy 登录到smallfry 。

你有了方案和计划,该是工作的时候了。

配置NFS 服务器

这里是在这个方案中配置NFS 服务器的步骤

1. 编辑 /etc/exports 文件允许NFS 挂载到 /home 目录,并与读写权限。

/home                   *(rw,sync)

2. 让NFS读取 /etc/exports 文件或的新的入口,用exportfs 命令让/home 在网络上可用。

[[email protected] tmp]# exportfs -a
[[email protected] tmp]#

3.保证 nfs, nfslock, 和 portmap 守护进程都在运行并且下次重启后配置为启动.

[[email protected] tmp]# chkconfig nfslock on
[[email protected] tmp]# chkconfig nfs on
[[email protected] tmp]# chkconfig portmap on
[[email protected] tmp]# service portmap start
Starting portmapper: [  OK  ]
[[email protected] tmp]# service nfslock start
Starting NFS statd: [  OK  ]
[[email protected] tmp]# service nfs start
Starting NFS services:  [  OK  ]
Starting NFS quotas: [  OK  ]
Starting NFS daemon: [  OK  ]
Starting NFS mountd: [  OK  ]
[[email protected] tmp]#

配置完NFS服务器,我们要配置它的客户端,这些会在下面涉及。

配置NFS 客户端

You also need to configure the NFS clients to mount their /home directories on the NFS server. 你需要配置NFS 客户端挂载 /home 目录到NFS 服务器。

These steps archive the /home directory. In a production environment in which the /home directory would be actively used, you'd have to force the users to log off, backup the data, restore it to the NFS server, and then follow the steps below. As this is a lab environment, these prerequisites aren't necessary. 这些步骤会归档 /home 目录。在一个/home目录会经常使用的产品环境中,你不得不强制用户登出,备份数据,并恢复到NFS 服务器,然后按照下面步骤来做。因为这是一个实验室的环境,这些准备并不需要。

1. Make sure the required netfs, nfslock, and portmap daemons are running and configured to start after the next reboot. 1. 保证需要的 netfs, nfslock, 和 portmap守护进程在运行,并且配置为再重启后启动。

[[email protected] tmp]# chkconfig nfslock on
[[email protected] tmp]# chkconfig netfs on
[[email protected] tmp]# chkconfig portmap on
[[email protected] tmp]# service portmap start
Starting portmapper: [  OK  ]
[[email protected] tmp]# service netfs start
Mounting other filesystems:  [  OK  ]
[[email protected] tmp]# service nfslock start
Starting NFS statd: [  OK  ]
[[email protected] tmp]#

2. Keep a copy of the old /home directory, and create a new directory /home on which you'll mount the NFS server's directory. 2. 保留一个以前/home 目录的副本,在你需要挂在的NFS 服务器的目录上创建一个新的/home目录。

[[email protected] tmp]# mv /home /home.save
[[email protected] tmp]# mkdir /home
[[email protected] tmp]# ll /
...
...
drwxr-xr-x    1 root   root     11 Nov 16 20:22 home
drwxr-xr-x    2 root   root   4096 Jan 24  2003 home.save
...
...
[[email protected] tmp]#

3. Make sure you can mount bigboy's /home directory on the new /home directory you just created. Unmount it once everything looks correct. 3. 保证你可以挂载bigboy 的/home 目录在你刚刚创建的目录上。卸载这个目录一次看看是否正常。

[[email protected] tmp]# mount 192.168.1.100:/home /home/
[[email protected] tmp]# ls /home
ftpinstall  nisuser  quotauser  smallfry  www
[[email protected] tmp]# umount /home
[[email protected] tmp]#

4. Start configuring autofs automounting. Edit your /etc/auto.master file to refer to file /etc/auto.home for mounting information whenever the /home directory is accessed. After five minutes, autofs unmounts the directory. 4. 开始配置autofs 来自动挂载。

#/etc/auto.master
/home      /etc/auto.home --timeout 600

5. Edit file /etc/auto.home to do the NFS mount whenever the /home directory is accessed. If the line is too long to view on your screen, you can add a \ character at the end to continue on the next line.

#/etc/auto.home
*   -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp \
   192.168.1.100:/home:&

6. Start autofs and make sure it starts after the next reboot with the chkconfig command.

[[email protected] tmp]# chkconfig autofs on
[[email protected] tmp]# service autofs restart
Stopping automount:[  OK  ]
Starting automount:[  OK  ]
[[email protected] tmp]#

After doing this, you won't be able to see the contents of the /home directory on bigboy as user root. This is because by default NFS activates the root squash feature, which disables this user from having privileged access to directories on remote NFS servers. You'll be able to test this later after NIS is configured.

Note: This automounter feature doesn't appear to function correctly in my preliminary testing of Fedora Core 3. See Chapter 29, "Remote Disk Access with NFS", for details.

All newly added Linux users will now be assigned a home directory under the new remote /home directory. This scheme will make the users feel their home directories are local, when in reality they are automatically mounted and accessed over your network.

配置NIS主服务器(Master)

NFS 只提供网际文件共享。你现在必须在试验室的学生完成工作之前为他们配置好NIS登录验证。NIS服务器的配置并不难,但是需要很多你可能会漏掉的步骤。别担心,我们将深入细致地重温每个环节。 注意: 在早期,NIS被称为黄页。 开发者被迫在一次版权侵害诉讼之后更名。,然而许多与NIS相关的主要程序仍然保持其以yp开头的原始名称。

安装NIS服务器包

NIS客户端需要的所有包是许多Fedora安装的标准部分。服务器的ypserv包不包括在内 。安装该包参考第六章的步骤概述。,"安装Linux软件".

编辑你的/etc/sysconfig/network 文件

你需要在/etc/sysconfig/network文件中增加你想要使用的NIS域。对学校而言,叫做NIS-SCHOOL-NETWORK域。

#/etc/sysconfig/network
NISDOMAIN="NIS-SCHOOL-NETWORK"

编辑你的 /etc/yp.conf 文件

NIS服务器必定也是他自己的客户端, 所以你也需要编辑NIS客户端配置文件/etc/yp.conf 来列出本域的NIS服务器,如服务器本身或本地主机.

# /etc/yp.conf - ypbind 配置文件
   ypserver 127.0.0.1

启动关键NIS服务器相关守护进程

在 /etc/init.d目录中启动必需的NIS守护进程同时使用chkconfig命令确保在下一次重启后启动他们。

[[email protected] tmp]# service portmap start
Starting portmapper: [  OK  ]
[[email protected] tmp]# service yppasswdd start
Starting YP passwd service: [  OK  ]
[[email protected] tmp]# service ypserv start
Setting NIS domain name NIS-SCHOOL-NETWORK:  [  OK  ]
Starting YP server services: [  OK  ]
[[email protected] tmp]# 

[[email protected] tmp]# chkconfig portmap on
[[email protected] tmp]# chkconfig yppasswdd on
[[email protected] tmp]# chkconfig ypserv on

表 30.1 列出了守护进程功能的概要。

表 30-1 依赖的NIS服务器守护进程

Daemon Name Purpose
portmap 基础RPC守护进程,运行NIS.
yppasswdd 用户可以在NIS客户端上更改位于NIS服务端上的密码
ypserv NIS服务器主要的守护进程
ypbind NIS客户端主要的守护进程
ypxfrd Used to speed up the transfer of very large NIS maps用于加快传输庞大的NIS映射

继续下一步之前确保他们都在运行。 可以使用rpcinfo命令来完成。

[[email protected] tmp]# rpcinfo -p localhost
   program vers proto   port
    100000    2   tcp    111  portmapper
    100000    2   udp    111  portmapper
    100009    1   udp    681  yppasswdd
    100004    2   udp    698  ypserv
    100004    1   udp    698  ypserv
    100004    2   tcp    701  ypserv
    100004    1   tcp    701  ypserv
[[email protected] tmp]#
ypbind 和ypxfrd 守护进程将不会正确启动直到你初始化NIS域之后。在初始化完成之后你需要重新启动这些守护进程。

初始化你的NIS域

既已确定NIS域名,你必须使用ypinit命令来为该域创建相关验证文件。你将被提示NIS服务器的名称,本例中为bigboy。 在该过程中,所有非特权账户通过NIS自动获得访问权限。

[[email protected] tmp]# /usr/lib/yp/ypinit -m
在这里,我们不得不建立一个运行NIS服务器的主机列表。 bigboy在NIS服务器的主机列表中 。请继续为其他主机增加名字,每行一个。列表创建完毕,输入<control D>。
        next host to add:  bigboy
        next host to add:

NIS 服务器的当前列表看起来如下:

bigboy
 
Is this correct?  [y/n: y]  y
We need a few minutes to build the databases...
Building /var/yp/NIS-SCHOOL-NETWORK/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
Updating hosts.byname...
Updating hosts.byaddr...
Updating rpc.byname...
Updating rpc.bynumber...
Updating services.byname...
Updating services.byservicename...
Updating netid.byname...
Updating protocols.bynumber...
Updating protocols.byname...
Updating mail.aliases...
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'
 
bigboy 已经被设置成一个NIS主服务器。
 

现在你在所有的从服务器上能执行 ypinit -s bigboy 。

[[email protected] tmp]#

注意:' 确保在该步骤之前端口映射已经开启否则将出错,例如:

failed to send 'clear' to local ypserv: RPC: Port mapper failureUpdating group.bygid...

在成功之前,你将不得不删除 /var/yp/NIS-SCHOOL-NETWORK目录同时重启portmap yppasswd, 和ypserv。

启动ypbind 和ypxfrd 守护进程

你现在能启动 ypbind 和 the ypxfrd 后台,因为NIS域文件已经创建。

[[email protected] tmp]# service ypbind start
Binding to the NIS domain: [  OK  ]
Listening for an NIS domain server.
[[email protected] tmp]# service ypxfrd start
Starting YP map server: [  OK  ]
[[email protected] tmp]# chkconfig ypbind on
[[email protected] tmp]# chkconfig ypxfrd on

确保守护进程运行

所有的NIS 后台使用RPC 端口映射同时,也因而,当他们正确运行时能使用rpcinfo命令被列出。

[[email protected] tmp]# rpcinfo -p localhost
    program vers proto   port
     100000    2   tcp    111  portmapper
     100000    2   udp    111  portmapper
     100003    2   udp   2049  nfs
     100003    3   udp   2049  nfs
     100021    1   udp   1024  nlockmgr
     100021    3   udp   1024  nlockmgr
     100021    4   udp   1024  nlockmgr
     100004    2   udp    784  ypserv
     100004    1   udp    784  ypserv
     100004    2   tcp    787  ypserv
     100004    1   tcp    787  ypserv
     100009    1   udp    798  yppasswdd
  600100069    1   udp    850  fypxfrd
  600100069    1   tcp    852  fypxfrd
     100007    2   udp    924  ypbind
     100007    1   udp    924  ypbind
     100007    2   tcp    927  ypbind
     100007    1   tcp    927  ypbind
[[email protected] tmp]#

添加新NIS 用户

新的NIS 用户能通过登入NIS服务器并新建一个用户账户来完成创建。本例中,将建立一个叫nisuer的用户账户同时为之设置密码。 一旦完成这些,你就必须在/var/yp目录下通过执行make命令来升级NIS 域的验证文件。 该过程使所有的NIS可用,非特权账户开始通过NIS自动获得访问权限,不是仅仅新创建一个用户,他也输出储存在/etc/passwd和/etc/group文件中所有用户的属性,例如登录shell,用户组,和home目录。

[[email protected] tmp]# useradd -g users nisuser
[[email protected] tmp]# passwd nisuser
Changing password for user nisuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] tmp]# cd /var/yp
[[email protected] yp]# make
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating passwd.byname...
Updating passwd.byuid...
Updating netid.byname...
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'
[[email protected] yp]#

可以通过使用ypmatch命令来查看是否用户验证信息已经被升级,这将返回用户加密过的密码字符串。

[[email protected] yp]# ypmatch nisuser passwd
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/::504:100::/home/nisuser:/bin/bash
[[email protected] yp]

也可以使用getent命令,该命令有相同的语法。与ypmatch不同,当运行在NIS服务器上时getent不提供一个加密过的密码,他在/etc/passwd文件中只提供用户的入口,在NIS客户机上,两次显示该加密的密码的结果是相同的。

[[email protected] yp]# getent passwd nisuser
nisuser:x:504:100::/home/nisuser:/bin/bash
[[email protected] yp]#

配置NIS 客户端

既然NIS服务器已配置好,该是配置NIS客户端的时候了。 让客户端工作你需要编辑大量相关的配置文件。看看该过程。

运行authconfig

authconfig或者 authconfig-tui程序在提示你IP 地址和NIS服务器域之后自动配置你的NIS文件。
[[email protected] tmp]# authconfig-tui

一旦完成,除了其他一些动作,将创建一个/etc/yp.conf文件来定义特定域的NIS服务器的IP 地址。以及编辑/etc/sysconfig/network文件来定义NIS客服端所属的NIS域。

# /etc/yp.conf - ypbind configuration file
NIS-SCHOOL-NETWORK 域服务器192.168.1.100

#/etc/sysconfig/network
NISDOMAIN=NIS-SCHOOL-NETWORK

In addition, the authconfig program updates the /etc/nsswitch.conf file that lists the order in which certain data sources should be searched for name lookups, such as those in DNS, LDAP, and NIS. Here you can see where NIS entries were added for the important login files.另外,authconfig程序会更新 /etc/nsswitch.conf文件,其中列出查找某些数据源的查询顺序,例如:DNS,LDAP,NIS。这里你可以看到NIS条目已经加入到重要的登录文件中

#/etc/nsswitch.conf
passwd:     files nis
shadow:     files nis
group:      files nis

注意: You can also locate a sample NIS nsswitch.conf file in the /usr/share/doc/yp-tools* directory.你也可以在/usr/share/doc/yp-tools*目录下去查找NIS nsswitch.conf 示例

启动NIS客户端进程

Start the ypbind NIS client, and portmap daemons in the /etc/init.d directory and use the chkconfig command to ensure they start after the next reboot. Remember to use the rpcinfo command to ensure they are running correctly.在/etc/init.d目录下启动 ypbind NIS 客户端及 portmap 进程,并且使用 chkcongfig 命令确保在下次重启后服务能启动。记得使用 rpcinfo 命令确认服务运行正常。

[[email protected] tmp]# service portmap start
Starting portmapper: [  OK  ]
[[email protected] tmp]# service ypbind start
Binding to the NIS domain:
Listening for an NIS domain server.
[[email protected] tmp]#

[[email protected] tmp]# chkconfig ypbind on
[[email protected] tmp]# chkconfig portmap on

注意: Remember to use the rpcinfo -p localhost command to make sure they all started correctly.记得使用 rpcinfo -p localhost 命令确认服务全部启动正常。

核对名称解析

As the configuration examples refer to the NIS client and server by their hostnames, you'll have to make sure the names resolve correctly to IP addresses. This can be configured either in DNS, when the hosts reside in the same domain, or more simply by editing the /etc/hosts file on both Linux boxes.

#
# File: /etc/hosts (smallfry)
#
192.168.1.100    bigboy

 
#
# File: /etc/hosts (bigboy)
#
192.168.1.102    smallfry

测试NIS访问NIS服务端

You can run the ypcat, ypmatch, and getent commands to make sure communication to the server is correct.你可以运行 ypcat,ypmatch 和getent 命令来确认到服务端的通信是正常的。

[[email protected] tmp]# ypcat passwd
nisuser:$1$Cs2GMe6r$1hohkyG7ALrDLjH1:505:100::/home/nisuser:/bin/bash
quotauser:!!:503:100::/home/quotauser:/bin/bash
ftpinstall:$1$8WjAVtes$SnRh9S1w07sYkFNJwpRKa.:502:100::/:/bin/bash
www:$1$DDCi/OPI$hwiTQ.L0XqYJUk09Bw.pJ/:504:100::/home/www:/bin/bash
smallfry:$1$qHni9dnR$iKDs7gfyt..BS9Lry3DAq.:501:100::/:/bin/bash
[[email protected] tmp]#

[[email protected] tmp]# ypmatch nisuser passwd
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/:504:100::/home/nisuser:/bin/bash
[[email protected] tmp]#

[[email protected] tmp]# getent passwd nisuser
nisuser:$1$d6E2i79Q$wp3Eo0Qw9nFD/:504:100::/home/nisuser:/bin/bash
[[email protected] tmp]#

Possible sources of error would include:

  • Incorrect authconfig setup resulting in errors in the /etc/yp.conf, /etc/sysconfig/network and /etc/nsswitch.conf files
  • Failure to run the ypinit command on the NIS server
  • NIS not being started on the NIS server or client.
  • Poor routing between the server and client, or the existence of a firewall that's blocking traffic

Try to eliminate these areas as sources of error and refer to the syslog /var/log/messages file on the client and server for entries that may provide additional clues.

通过NIS服务端测试登录

Once your basic NIS functionality testing is complete, try to test a remote login. Failures in this area could be due to firewalls blocking TELNET or SSH access and the TELNET and SSH server process not being started on the clients.一旦你的基础 NIS 功能测试完成,试着测试远程登录。这方面的故障可能是因为防火墙阻塞 TELNET 或者 SSH访问 ,又或者客户端的TELNET 和 SSH 服务进程未启动。

通过telnet登录

Try logging into the NIS client via telnet if it is enabled

[[email protected] tmp]# telnet 192.168.1.201
Trying 192.168.1.201...
Connected to 192.168.1.201.
Escape character is '^]'.
Red Hat Linux release 9 (Shrike)
Kernel 2.4.20-6 on an i686
login: nisuser
Password:
Last login: Sun Nov 16 22:03:51 from 192-168-1-100.simiya.com
[[email protected] nisuser]$

通过SSH登录

Try logging into the NIS client via SSH.

[[email protected] tmp]# ssh -l nisuser 192.168.1.102
[email protected]'s password:
[[email protected] nisuser]$

In some versions of Linux, the NIS client's SSH daemon doesn't re-read the /etc/nsswitch.conf file you just modified until SSH is restarted. SSH logins, therefore, won't query the NIS server until this is done. Restart SSH on the NIS client.

[[email protected] root]# service sshd restart
Stopping sshd:[  OK  ]
Starting sshd:[  OK  ]
[[email protected] root]#

配置NIS从服务器(Slave)

NIS relies a lot on broadcast traffic to operate, which prevents you from having an NIS server on a different network from the clients. You can avoid this problem on your local subnet by using slave servers that are configured to automatically synchronize their NIS data with that of the single master server.

You can also consider placing multiple NIS servers on a single subnet for the sake of redundancy. To do this, configure the NIS clients to have multiple NIS servers for the domain in the /etc/yp.conf file.

Configuring NIS Slave Servers

In this scenario, you need to add an NIS slave server named nisslave (IP address 192.168.1.254) to the NIS-SCHOOL-NETWORK NIS domain. You also must configure the NIS master server, bigboy, to push its database map information to the slave whenever there is an update. Here are the steps you need.


1. As you're referring to our servers by their hostnames, you'll have to make sure the names resolve correctly to IP addresses. This can be done either in DNS, when the hosts reside in the same domain, or more simply by editing the /etc/hosts files on both servers as seen in Table 30.2.

Table 30-2 NIS Master / Slave /etc/hosts Files

Master (Bigboy) Slave (Nisslave)
#
# File: /etc/hosts (Bigboy)
#
192.168.1.254    nisslave
#
# File: /etc/hosts (Nisslave)
#
192.168.1.100    bigboy


2. Configure the NIS slave as a NIS client of itself in the /etc/yp.conf file, and configure the NIS domain in the /etc/sysconfig/network file as seen in Table 30.3.

Table 30-3 NIS Master / Slave /etc/yp.conf Files

/etc/yp.conf /etc/sysconfig/network
#
# File: /etc/yp.conf (Bigboy)
#
ypserver 127.0.0.1
#
# File: /etc/sysconfig/network
#
NISDOMAIN="NIS-SCHOOL-NETWORK"


3. On the slave server, run ypbind so the slave can query the master server.

[[email protected] tmp]# service portmap start
Starting portmapper: [  OK  ]
[[email protected] tmp]# service ypbind start
Binding to the NIS domain:
Listening for an NIS domain server.
[[email protected] tmp]#
 
[[email protected] tmp]# chkconfig portmap on
[[email protected] tmp]# chkconfig ypbind on

4. Optimize database map transfers by the NIS map transfer daemon, which should the started on both the master and slave.

[[email protected] tmp]# service ypxfrd start
Starting YP map server: [  OK  ]
[[email protected] tmp]#
[[email protected] tmp]# chkconfig ypxfrd on
 
[[email protected] tmp]# service ypxfrd start
Starting YP map server: [  OK  ]
[[email protected] tmp]#
[[email protected] tmp]# chkconfig ypxfrd on

5. Do a simple database query of the master from the slave using the ypwhich command with the -m (master) switch. You should get a listing of all the tables.

[[email protected] tmp]# ypwhich -m
mail.aliases bigboy
group.bygid bigboy
passwd.byuid bigboy
rpc.bynumber bigboy
...
...
[[email protected] tmp]#

6. Do an initial database download to the slave from the master with the ypinit command using the -s switch for a slave-type operation and specifying server bigboy as the master from which the data is to be obtained. You should see "Trying ypxfrd - success" messages. If the messages say "Trying ypxfrd - not running," then start ypxfrd on both servers.

[[email protected] tmp]# /usr/lib/yp/ypinit -s bigboy
We will need a few minutes to copy the data from bigboy.
Transferring services.byservicename...
Trying ypxfrd ... success
 
Transferring group.byname...
Trying ypxfrd ... success
...
...
 
nisslave's NIS data base has been set up.
If there were warnings, please figure out what went wrong, and fix it.
 
At this point, make sure that /etc/passwd and /etc/group have
been edited so that when the NIS is activated, the data bases you
have just created will be used, instead of the /etc ASCII files.
[[email protected] tmp]#

If your database is corrupt or your /etc/hosts files are incorrect, you'll get map enumeration errors as shown. Use the make command again to rebuild your database on the master when necessary.

[[email protected] tmp]# /usr/lib/yp/ypinit -s bigboy
Can't enumerate maps from bigboy. Please check that it is running.
[[email protected] tmp]#

7. Now that the data has been successfully downloaded, it's time to make the slave server serve NIS clients with ypserv.

[[email protected] tmp]# service ypserv start
Starting YP server services:
[[email protected] tmp]#
[[email protected] tmp]# chkconfig ypxfrd on
 

8. Log on to the master server. Add the slave server to the master server's database map by editing the /var/yp/ypservers file on the master.

[[email protected] yp]# cd /tmp
[[email protected] tmp]# cd /var/yp/
[[email protected] yp]# vi ypservers

Add nisslave to the file.

#
# File: /var/yp/ypservers
#
bigboy
nisslave
 

9. The make file in the /var/yp directory defines how the NIS server will build the database map and how the master will relate to the NIS slave. Make a copy of the master's make file for safekeeping.

[[email protected] yp]# cp Makefile Makefile.old
 

10. Edit the make file to allow the master to push maps to the slave.

#
# File: /var/vp/Makefile
#
 
#
# Allow the master to do database pushes to the slave
#
NOPUSH=false
 

11. Use the make command to rebuild the database. The make command automatically pushes database updates to the servers listed in the /var/yp/servers file.

[[email protected] yp]# make
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating ypservers...
YPPUSH: gethostbyname(): Success
YPPUSH: using not FQDN name
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'
gmake[1]: Entering directory `/var/yp/NIS-SCHOOL-NETWORK'
Updating netid.byname...
YPPUSH: gethostbyname(): Success
YPPUSH: using not FQDN name
gmake[1]: Leaving directory `/var/yp/NIS-SCHOOL-NETWORK'
[[email protected] yp]#

12. On the slave server, create a cron file in the /etc/crond.d directory, in this case named nis_sync, that will run periodic database downloads from the master server. This helps to ensure that the slave servers have current databases even if they miss updates from the master in the event the school goes offline for maintenance. Restart the cron daemon so that the configuration in this file becomes active.

[[email protected] yp]# vi /etc/cron.d/nis_sync
 
#
# File: /etc/cron.d/nis_sync
#
20 *    * * *    /usr/lib/yp/ypxfr_1perhour
40 6    * * *    /usr/lib/yp/ypxfr_1perday
55 6,18 * * *    /usr/lib/yp/ypxfr_2perday
 
[[email protected] yp]# service crond restart

That's a lot of work but it's still not over. There is one final configuration step that needs to be done on the NIS clients before you're finished.

Configuring NIS Clients With Slaves

Edit the /etc/yp.conf file on all the clients to include nisslave, and restart ypbind.

#
# File: /etc/yp.conf (Smallfry)
#
domain NIS-SCHOOL-NETWORK server 192.168.1.100
domain NIS-SCHOOL-NETWORK server 192.168.1.254

 
[[email protected] tmp]# service ypbind restart
Shutting down NIS services: [  OK  ]
Binding to the NIS domain: [  OK  ]
Listening for an NIS domain server..
[[email protected] tmp]#

Changing Your NIS Passwords

You should also test to make sure your users can change their NIS passwords from the NIS clients with the yppasswd command. The process is different whether there is only a single NIS master or a master-slave server relationship.

When There Is Only An NIS Master

When there is only a single NIS server, password changes can be made only on the NIS server using the yppasswd command.

Users Changing Their Own Passwords

Users can change their passwords by logging into the NIS server and issuing the yppasswd command.

[[email protected] nisuser]$ yppasswd
Changing NIS account information for nisuser on bigboy.my-site.com.
Please enter old password:
Changing NIS password for nisuser on bigboy.my-site.com.
Please enter new password:
Please retype new password:
 
The NIS password has been changed on bigboy.my-site.com.
 
[[email protected] nisuser]$

User "Root" Changing Passwords

The root user can change other users' passwords issuing the yppasswd command with the -p switch that specifies the username that needs the change.

[[email protected] tmp]# yppasswd -p nisuser
Changing NIS account information for nisuser on bigboy.my-site.com.
Please enter root password:
Changing NIS password for nisuser on bigboy.my-site.com.
Please enter new password:
Please retype new password:
 
The NIS password has been changed on bigboy.my-site.com.

[[email protected] tmp]#

When There Is A NIS Master / Slave Pair

With an NIS master and slave pair configuration, passwords can be changed on the NIS clients or the NIS slave, but not on the NIS master.

Possible Password Errors

There are a number of unexpected errors you may find when changing passwords - errors that have nothing to do with bad typing.

Segmentation Faults

Running the yppasswd command on the wrong client or server depending on your NIS master and slave configuration can cause segmentation fault errors. (Make sure you follow the chapter's guidelines for password changes!) Here are some sample password change failures on an NIS client with only one NIS master server.

[[email protected] nisuser]$ yppasswd
Segmentation fault
[[email protected] nisuser]$
 
[[email protected] root]# yppasswd -p nisuser
Segmentation fault
[[email protected] root]#

Daemon Errors

The yppasswdd daemon must be running on both the client and server for password changes to work correctly. When they aren't running, you'll get errors.

[[email protected] etc]# yppasswd -p nisuser
yppasswd: yppasswdd not running on NIS master host ("bigboy").
[[email protected] etc]#

You'll also get a similar error if you attempt to change an NIS password on an NIS master server in a master and slave configuration.

非NFS环境的思考

在许多状况下,NFS不适用于创建一个用户的集中home目录,同时也因而,你将不得不在每个NIS客户端创建他而不能在服务器上。

本例为NIS客户机smallfry创建home目录。 完成后,你必须复制进BASH登录提要文件同时修改目录和用户nisuser的所有文件的所属关系。

一旦完成这些,登录将正常进行,紧接着是其他步骤。

[[email protected] tmp]# mkdir /home/nisuser
[[email protected] tmp]# chmod 700 /home/nisuser/
[[email protected] tmp]# ll /home
total 2
drwx------    2 nisuser users        1024 Aug  4 08:05 nisuser
[[email protected] tmp]#
[[email protected] tmp]# cp /etc/skel/.* /home/nisuser/
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.kde'
[[email protected] tmp]# chown -R nisuser:users /home/nisuser
[[email protected] tmp]#

NIS 故障排除

在日常事务的任何一部分都需要进行故障的修复,NIS也不例外。下面是一些使之重新正常工作的简单指导步骤。

1. rpcinfo提供一个NIS客户端或服务器使用的TCP端口列表。确保你能从客户端到服务器TELNET到这些端口,反之亦然。如果失败,确定所有正确的NIS守护进程都在运行中以及服务器自身网络没有发生防火墙拥堵, 这些端口变来变去,所以记住他们没什么太大帮助。

下例是客户端到服务器的测试。

[[email protected] tmp]# rpcinfo -p
    program vers proto   port
     100000    2   tcp    111  portmapper
     100000    2   udp    111  portmapper
     100024    1   udp  32768  status
     100024    1   tcp  32768  status
     391002    2   tcp  32769  sgi_fam
     100009    1   udp   1018  yppasswdd
     100004    2   udp    611  ypserv
     100004    1   udp    611  ypserv
     100004    2   tcp    614  ypserv
     100004    1   tcp    614  ypserv
     100007    2   udp    855  ypbind
     100007    1   udp    855  ypbind
     100007    2   tcp    858  ypbind
     100007    1   tcp    858  ypbind
  600100069    1   udp    874  fypxfrd
  600100069    1   tcp    876  fypxfrd
[[email protected] tmp]#
 
 
[[email protected] tmp]# telnet 192.168.1.100 858
Trying 10.41.32.71...
Connected to 10.41.32.71.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
[[email protected] tmp]#

2. 总是使用ypmatch,getent和ypwhich命令来检查你的NIS连通性。如果出错,再次检查你的步骤你会发现问题的根源所在。

3. 创建用户home目录时不要出错,设置为允许,同时正确拷贝/etc/skel文件。如果你忘记,这是常见错误,你的用户可能在登录时出现错误提示同时在他们的home目录中没有创建文件的权限。

一个并非过份强调的排除故障最好的方式是在/var/log目录中查阅你的错误日志文件。无论何时,如果问题尚未明朗你去查询他们都会省去很多时间和努力。

总结

NIS 是一个非常有用的集中登录管理工具,但他有两个缺点:NIS客户端被严格地限制为Unix 或Linux操作系统,而且密码信息在网络上进行不加密传输。

更新颖的验证方案克服了这些问题。例如,在31章中讨论的LDAP "基于 LDAP 和 RADIUS的集中登录",提供双加密和在各种类型设备上使用的能力。非常不幸,老的操作系统并不支持他,在某些情况下让NIS成为最佳选择。

和往常一样,当决定集中登录方案时,探究你的选择。错误的决定将会困扰你很久。