天天看點

實作NIS身份驗證及自動挂載

基礎知識:

一、NIS簡介:

NIS是Sun Microsystem于1985年釋出的一項目錄服務技術(Diretory Service),用來集中控制幾個系統管理資料庫的網絡用品。

二、NIS的作用:

NIS簡化了UNIX和LINUX桌面客戶的管理工作,用戶端利用它可以使用中心伺服器的管理檔案。桌面系統的使用者無需建立他們自己的/etc/passwd,他們隻簡單的使用維護在NIS伺服器的檔案即可。

三、NIS的架構:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050179BIJh.png"></a>

一個不是很龐大的網絡中,大約會有一部NIS Server ,并且同時有很多部的 NIS Client 。

四、NIS的工作流程:

1 、NIS Server 将自己系統内的 /etc/passwd, /etc/group,/etc/hosts 等制作成為 DBM 的資料庫格式檔案,每次更動 NIS Server 上面的使用者資料時,則 NIS Server需要重新制作 DBM 資料庫檔案!

2 、NIS Client 若有使用者登入的要求時,會前往 NIS Server搜尋資料庫裡面資料做為驗證用。

案例:

一、實驗說明:

通過NIS實作帳号集中管理和身份驗證,并通過NFS系統,實作使用者登入後,能夠自動挂載存放在NFS伺服器上家目錄;

二、實驗步驟:

NIS伺服器搭建:

1、挂載CD光牒:

# mkdir /mnt/cdrom

# mount /dev/cdrom /mnt/cdrom

2、安裝nis相關軟體包:

# cd /mnt/cdrom/Server/

# rpm -ivh ypserv-2.19-5.el5.i386.rpm

3、啟動nis相關服務:

# service ypserv start

# chkconfig ypserv on

# service yppasswdd start

# chkconfig yppasswdd on

4、設定NIS伺服器的域環境:

# vim /etc/sysconfig/network

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050180mXdS.png"></a>

5、重新開機系統:

# init 6

6、建立NIS帳号庫,設定将要導入什麼資訊:

# cd /var/yp/

# vim Makefile

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050180RFZW.png"></a>

//隻需要導入帳号、組和host資訊:

7、在NIS使用者庫中導入使用者資料:

# /usr/lib/yp/ypinit -m    //第一次導入時使用

-m 表示master伺服器;

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050181Glqw.png"></a>

//由于沒有其他的NIS伺服器了,是以,ctrl + d 來結束

8、自動産生了帳号資料庫檔案:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050181r4z1.png"></a>

9、添加一個測試帳号test:

# useradd test

# passwd test

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050182iDi9.png"></a>

10、重新整理NIS帳号庫,将新使用者導入NIS帳号庫:

# cd /var/yp

# make

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050183z3vS.png"></a>

11、在NIS伺服器通過NFS檔案系統設定一個共享清單,将家目錄進行共享:

# vim /etc/exports

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050184BXFF.png"></a>

//隻允許192.168.10.0/24網段的使用者通路被共享的目錄;

12、啟動nfs服務:

# service nfs start

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050184FL6M.png"></a>

13、導出NFS的共享清單:

# exportfs -rv

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_13480501851i7q.png"></a>

NIS用戶端配置:

1、開啟NIS的驗證配置:

# setup

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050186iYMO.png"></a>

選擇使用者驗證方式:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050187Dw5p.png"></a>

寫出用戶端的域名和NIS伺服器的位址:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050188si4z.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050189sY4V.png"></a>

2、在用戶端測試NIS使用者登入:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050189CB9T.png"></a>

//NIS伺服器可以正常使用;

3、從用戶端檢視伺服器共享的檔案:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_134805019014Gj.png"></a>

//NFS伺服器可以正常使用;

4、在用戶端上實作使用者家目錄在登入時自動挂載到NFS伺服器上:

建立NIS使用者家目錄挂載點:

# mkdir /nishome

5、設定使用者家目錄自動挂載:

# vim /etc/auto.master

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050190YMFK.png"></a>

//通過auto.nismout監聽/nishome目錄

6、建立監控檔案:

# cp -p /etc/auto.misc /etc/auto.nis

7、編輯監控檔案:

# vim /etc/auto.nis

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050191YHrP.png"></a>

//其中,*表示所用使用者,&amp;表示對應使用者挂在的檔案;

8、重新開機autofs服務:

# service autofs restart

三、驗證測試:

從用戶端登入test帳号:

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050191YCWg.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050192vIy7.png"></a>

<a href="http://cexpert.blog.51cto.com/attachment/201209/19/5251990_1348050193D03G.png"></a>

測試通過!!

本文轉自 cexpert 51CTO部落格,原文連結:http://blog.51cto.com/cexpert/998830