免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1377 | 回复: 0
打印 上一主题 下一主题

NIS [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-14 10:58 |只看该作者 |倒序浏览


[/url]
NIS=Network Information System
 


What is NIS

NIS 是一個簡單、通用跨平台的資料庫系統,主要目的在於分享網路上各主機間的共用資訊。

NIS是一種協定,且幾乎每一種版本的UNIX均支援。

在UNIX(Linux)中,NIS主要用來管理使用者名稱、密碼、主機名稱及群組等與系統管理相關訊息。

NIS was part of SunOS and called "Yellow Page"(YP) Before.

Why NIS

簡化網路中電腦群組管理。

符合『集中式管理與分散式處理原則』,所有電腦的重要資訊(例如使用者帳號)都可以在同一台機器中完成管理的工作。

配合NFS,可使使網路中同一群組之電腦中之資料運作所需資訊,隨時保持同步;給予使用者與管理者方便且有效率的電腦使用環境。

在NIS與NFS結合的環境中,使用者可以得到『漫遊使用環境』的維護(Roaming Environment),也就是說,使用者在任何一台電腦中更改本身的使用環境,只要他仍在同一個Domain中,不管換到哪一台電腦,環境(例如:Command alias、PATH、Prompt、Shell….)依然保持不變。

NIS讓帳號管理與使用更加方便。

How NIS Work

NIS係以Domain方式運作,每一個NIS Domain(與DNS Domain無關)中至少存在一個NIS Server。

NIS Server負責管理Domain中的電腦所需的各種資訊(例如passwd、shadow、hosts、groups、service…)。

NIS中的資訊稱之為『Map』,一般而言,Map係以DataBase(DBM)方式存在Server的/var/yp目錄之下。

NIS Client透過RPC(Remote Processure Call),存取Server中的資訊。

NIS Client可以控制哪些資訊使用自己機器本身的檔案,哪些使用Server NIS Map,同時也可以控制以一定的順序,使用本身及Server的資訊。

當NIS Server(Master Server)負載過重,第二台Server(Slave Server)可以自動加入服務行列,以加快Server Response的速度。

NIS MAP

NIS 中供分享的資訊係以DBM的格式存在(Not readable),這些相對應於系統原有檔案(e.x. /etc/passwd、/etc/hosts、/etc/groups、….)的database稱為Map或NIS Map.

透過NIS分享的檔案基本上有兩個不可或缺的條件,一是該檔案中必須至少有一個獨一無二的登錄項目(每一行中);第二則是該檔的原始檔必須以純文字的格式存在。

一般NIS server可以分享以下的檔案:
/etc/passwd、/etc/hosts、/etc/group、/etc/networks、/etc/rpc、/etc/services、/etc/protocols、/etc/netgroup、/etc/shadow…其中又以/etc/passwd、/etc/shadow與/etc/hosts最為重要。

NIS server Map存在於/var/yp/domainname目錄之下。

NIS Domain

NIS domain與DNS (Domain Name Service)無關。

NIS中同一domain的機器share同一組 Maps。

NIS Client與 Server的contact可經由組態檔(/etc/yp.conf)強迫指定,亦可經由domainname的廣播向網路詢問(有安全顧慮)。

NIS Domainname的查詢與設定均可以透過同一個指令『domainname』完成。

Roles of machines in an NIS Domain

Master Server: Network Information的提供者。同一domain所有機器共用的系統資訊,均存在於master server,並由master server管理之。

Slave Server: Slave server是master server的分身。理論上slave serv上的資料必須隨時自動或手動的與master server保持一致。當master serv fail,slave server立即可以取而代之。

Client: Network Information的需求者。一台機器加入某個domain之後(If authorized),立即可以透過RPC向NIS server (Master or Slave)提出Information request。

NIS軟體安裝

Check if your RedHAT Installation include NIS

[root@nmc ~]#
rpm -q -a | grep yp
yp-tools-2.3-2
ypbind-3.3-24
上面例子顯示nmc僅安裝NIS Client,未安裝Server

NIS相關套件的位置在RedHAT光碟片中目錄/cdrom/RedHAT/RPMS中,安裝方式如下:

[root@nmc RPMS]#
ls -l yp*
-rw-r--r-- 1 root root 53760 Sep 28 00:34 yp-tools-2.3-2.i386.rpm
-rw-r--r-- 1 root root 23811 Sep 28 00:34 ypbind-3.3-24.i386.rpm
-rw-r--r-- 1 root root 129800 Sep 28 00:34 ypserv-1.3.7-3.i386.rpm
[root@nmc RPMS]#
rpm -i ypserv-1.3.7-3.i386.rpm
[root@nmc RPMS]#
rpm -i yp-tools-2.3-2.i386.rpm
[root@nmc RPMS]#
rpm -i ypbind-3.3-24.i386.rpm

NIS Master Server Setup

設定Domainname
domainname your_nis_domainname
你可以把NIS Domainname當成是一個domainpassport,必要時他可以是domain成員的簡易保護措施 (Easy password),避免非成員取得Domain Map

Example

[root@nmc ~]# domainname
###No Domainname Set
[root@nmc ~]#
domainname linux.nchucc
[root@nmc ~]#
domainname
linux.nchucc
###Domainname Noew set to "linux.nchucc"


To set Your NIS Domainname automatically when system bootup, put the following line in the file "/etc/sysconfig/network"
NIS_DOMAIN=linux.nchucc



編輯/var/yp/Makefile
/var/yp/Makefile決定你的NIS Server Map 原始文字檔來源及可供分享的Map。NIS Map的原始文件檔可由管理者自行指定。Map 『passwd』預設原始檔為『/etc/passwd』,基於某些安全上的理由,你可以把他改成其他檔案,例如『/etc/passwd.yp』。

/var/yp/Makefile更改原始檔案的區段:
...
PASSWD = $(YPPWDDIR)/passwd
SHADOW = $(YPPWDDIR)/shadow
GSHADOW = $(YPPWDDIR)/gshadow

...
$(YPPWDDIR)在/var/yp/Makefile檔案前頭定義的變數,通常是/etc

/var/yp/Makefile中指定shared Map的區段:
...
all : passwd group hosts rpc services netid protocols netgrp mail \
#shadow publickey # networks ethers bootparams amd.home \
auto.master auto.home passwd.adjunct

...
上面的例子shared Map為passwd,group, hosts, rpc, service, netid, protocols, netgrp, mail等

/var/yp/Makefile決定你NIS Map產生方式,修改時得小心行事,建議先行備份,以備萬一。

啟動NIS Master Server並建立相關Map

Start ypserv 及yppasswd Daemons
[root@nmc yp]# /etc/rc.d/init.d/ypserv start
Starting YP server services: [
OK ]
[root@nmc yp]#
/etc/rc.d/init.d/yppasswdd start
Starting YP passwd service: [
OK ]
ypserv為NIS Server Daemon, yppasswd則是允許NIS User直接修改NIS Passwd的Daemon (By Command "yppasswd")。如果你希望系統啟動實直接啟動NIS Server你可以輸入以下命令:
[root@nmc yp]# cd /etc/rc.d/rc3.d
[root@nmc rc3.d]#
ln -s ../init.d/ypserv S60ypserv
[root@nmc rc3.d]#
ln -s ../init.d/yppasswd S61yppasswd


Build up NIS MAP For a Master Server
[root@nmc yp]# /usr/lib/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. nmc is in the list of NIS server hosts. Please continue to add
the names for the other hosts, one per line. When you are done with the
list, type a .
next host to add: nmc
next host to add:
woody
next host to add:

The current list of NIS servers looks like this:
nmc
woody
Is this correct? [y/n: y]  
y
We need some minutes to build the databases...
Building /var/yp/linux.nchucc/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/linux.nchucc'
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
....
Updating hosts.byname...
Updating hosts.byaddr...
Updating rpc.byname...
Updating rpc.bynumber...
Updating services.byname...
Updating netid.byname...
Updating protocols.bynumber...
Updating protocols.byname...
Updating mail.aliases...
gmake[1]: Leaving directory `/var/yp/linux.nchucc'

Your Machine  Server is Now an NIS Master

NIS  Client Setup


edit /etc/yp.conf (if not there, create it !)
/etc/yp/yp.conf指定你的NIS Server,如果此處未指定,NIS Client將會以Broadcast Domainname的方式自行尋找NIS Server,基本上讓NIS Client 自行尋找Server的做法是不安全的!
/etc/yp.conf的格式如下:
domain domainname  server  nis_server
其中domainserver keyworddomainname是你所屬的NIS Domain名稱,nis_server是你所指定的NIS Server
一個例子:
domain    linux.nchucc   server  nmc.nchu.edu.tw


Setup Domainname For NIS Client
做法同Server

啟動NIS Client Daemon

Start By Hand:
/etc/rc.d/init.d/ypbind  start

Start AutoMatically  When System BootUp
cd e/tc/rc.d/rc3.d
ln  -s  ../init.d/ypbind  S60ypbind


Client Test  

RPC Connection Test
[root@dragon1 /etc]# rpcinfo -p nmc
program vers proto port
100000 2 tcp 111 rpcbind
100000 2 udp 111 rpcbind
100004 2 udp 677 ypserv
100004 1 udp 677 ypserv
100004 2 tcp 680 ypserv
100004 1 tcp 680 ypserv
100009 1 udp 692 yppasswdd


NIS Server Connection Test
[root@dragon1 /etc]#
ypwhich
nmc
###NIS Server is  "nmc"


NIS Map Test

[root@dragon1 /etc]#
ypcat passwd
nickname file /var/yp/nicknames does not exist.
nii8:!VZ6JSXyd6TDlE:1519:101:nii8:/home/nii/nii8:/bin/tcsh
nii13:!h4sAkapPWK4Gk:1524:101:nii13:/home/nii/nii13:/bin/tcsh
nii26:!CCqyfa09bdQbU:1537:101:nii26:/home/nii/nii26:/bin/tcsh
nii31:!us4Yfwtr5v2tE:1542:101:nii31:/home/nii/nii31:/bin/tcsh
nii39:!6oo9n4uLnp8tg:1550:101:nii39:/home/nii/nii39:/bin/tcsh
nii44:!gmONy1fnQA8Vw:1555:101:nii44:/home/nii/nii44:/bin/tcsh
net003:aOUXT/Z/6GfNY:1003:100:,,,:/home/net003:/bin/bash
...
-->這就是nmc上/etc/passwd的內容,如果你得到下錯誤訊息
nickname file /var/yp/nicknames does not exist.
No such map passwd. Reason: No such map in server's domain

你必須在Client端/var/yp/nicknames中加入下面這一行
passwd passwd.byname

關於/etc/nsswitch.conf

本文来自ChinaUnix博客,如果查看原文请点:[url]http://blog.chinaunix.net/u/22239/showart_155158.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP