NIS服务器介绍


NIS (Network Information System) 的目的是让网络上许多台计算机共享一份使用者数据的设定信息,有点类似 MS Windows NT domain。NIS 最早是由 SUN Microsystems 在其 SUN OS 中所使用,后来被广为应用在各种的 UNIX 平台。以前 NIS 并不叫做 NIS,而是 YP (Yellow Pages),但后来因为商标问题才改为 NIS,但 YP 这个名字还是常被使用。例如,我们可以看到很多 NIS 所用的指令都是以 YP 为名。
当我们的系统中有多台服务器时,若每一台服务器上都要有相同的使用者设定,一种方法就是将每一台机器都维持同样的设定,当我们要在新增一个使用者或使用者要修改密码时,必须进入每一台机器做设定。另一种方式就是使用 NIS,我们只要设定其中一台为 NIS Master Server,其它的机器为 NIS Client,当需要修改设定时,我们只要在 Master server 做修改即可。
NIS 中有所谓 NIS domain 的观念,Client 端可以加入某一个 NIS Domain 以使用该 NIS domain 的账号密码认证。以下我们的设定就以 domain "twbsd" 为范例。
NIS Server 的设定
首先,请修改 /etc/rc.conf 并加入下列设定:
nisdomainname="twbsd"
nis_server_enable="YES"
nis_yppasswdd_enable="YES"
nis_yppasswdd_flags="-t /etc/master.passwd"
 
接下来请将 /var/yp/Makefile.dist 复制一份到 /var/yp/Makefile,并修改 /var/yp/Makefile 加入下列这一行并将 NOPUSH="True" 那一行批注掉:
#NOPUSH="True"
MASTER_PASSWD=/etc/master.passwd  
接下来请执行下列指令:
# ypinit -m twbsd
Creating an YP server will require that you answer a few questions.
Questions will all be asked at the beginning of the procedure.
Do you want this procedure to quit on non-fatal errors? [y/n: n]
Ok, please remember to go back and redo manually whatever fails.
If you don't, something might not work.
Can we destroy the existing /var/yp/twbsd and its contents? [y/n: n] y
At this point, we have to construct a list of this domains YP servers.
alexwang.com is already known as master server.
Please continue to add any slave servers, one per line. When you are
done with the list, type a .
    master server   :  alexwang.com
    next host to add:  ^D  如果还有其它的 slave server 则再加入,否则按 Ctrl+D
The current list of NIS servers looks like this:
alexwang.com
 
重新启动 NIS Server 或请执行下列指令以启动 NIS Server:
# /etc/netstart
NIS Client 的设定
在 Client 方面,请先编辑 /etc/rc.conf 并加入下列几行:
nisdomainname="twbsd"
nis_client_enable="YES"
接下来请执行 vipw 修改 /etc/master.passwd 将非系统本身的使用者移除,并在档案最后加入下列一行:
+:::::::::
接下来再编辑 /etc/group,将非系统本身的使用者移除,并加入这一行:
+:*::
接下来您应该就可以使用 ypcat passwd 来看到 Server 的 passwd map。
FreeBSD Handbook 中 NIS 的部份十份详细,建议您参考该文件以获得最多信息。

  1. 在RHEL 5中配置NIS服务器端及客户端
  2. RHEL上NIS网络信息服务配置实例讲解
  3. RHEL5.1主/从NIS服务器配置及测试 

相关内容