配置NIS+NFS環(huán)境,實現(xiàn)autoFS自動掛接home目錄
關(guān)于此實例中環(huán)境的說明:
    系統(tǒng)環(huán)境為Solaris 9,三臺主機nisa、nisb、nisc,nisa做master server,nisb做slave,nisc做client。配置NIS時,選擇新建/nis目錄,將資源文件與/etc目錄中的文件分隔開來,passwd文件可設(shè)置到獨立的目錄以增加安全性,這里不另外設(shè)置,也一起放到/nis目錄下。配置NFS時,使用的是master主機上掛載的存儲資源,掛載點為/netstore。
一、配置master
    1)新建/nis目錄,用于存放NIS需要的資源文件
            # mkdir /nis
    2)準備NIS需要的資源文件
    NIS需要的資源文件如下,可從/etc目錄拷貝到/nis目錄下,部分文件/etc目錄中沒有,需要手動用# touch創(chuàng)建,passwd、group、shadow文件因涉及安全性,不用原/etc目錄下的文件:
            auto_home
            auto_master
            bootparams(需要新建)
            ethers(需要新建)
            group(新建一個group文件,不用原/etc目錄下的)
            hosts
            netgroup(需要新建)
            netmasks
            networks
            passwd(新建一個passwd文件,不用原/etc目錄下的)
            protocols
            publickey
            rpc
            services
            shadow(新建一個shadow文件,不用原/etc目錄下的)
            timezone(需要新建)
            user_attr
    3)設(shè)置NIS域名為nistest.com
            # domainname nistest.com
    4)創(chuàng)建/etc目錄中的defaultdomain文件,內(nèi)容為nistest.com
            # domainname > /etc/defaultdomain
    5)編輯/nis/hosts文件,添加NIS域中的所有主機,再編輯/etc/hosts文件,添加NIS域中提供NIS服務(wù)的主機(即master和slave)
            # vi /nis/hosts
            修改內(nèi)容如下
            192.168.0.10   nisa      nisa.nistest.com
            192.168.0.11   nisb      nisb.nistest.com
192.168.0.12   nisc      nisc.nistest.com
# vi /etc/hosts
修改內(nèi)容如下
            192.168.0.11   nisb      nisb.nistest.com
    6)修改/var/yp/Makefile文件,修改前先備份原文件,以便日后恢復和維護
            # cp /var/yp/Makefile /var/yp/Makefile.orig
            # vi /var/yp/Makefile
            將DIR =/etc改為DIR =/nis;
            將PWDIR =/etc改為PWDIR =/nis
    7)替換/etc/nsswitch.conf文件,把原先的nsswitch.conf文件備份,然后替換為nsswitch.nis文件的內(nèi)容
            # cp /etc/nsswitch.conf /etc/nsswitch.conf.orig
            # cp /etc/nsswitch.nis /etc/nsswitch.conf
            
    8)運行ypinit -m,設(shè)置master,初始化NIS環(huán)境
            # ypinit -m
            ...
                        next host to add:  nisa
                        next host to add:  nisb
                        next host to add:  ^D(如果有多臺slave,繼續(xù)輸入,否則按Ctrl+D結(jié)束)
            The current list of yp servers looks like this:
nisa
nisb
Is this correct?  [y/n: y]  y
...
Do you want this procedure to quit on non-fatal errors? [y/n: n]  y
...
Can we destroy the existing /var/yp/catnistest.com and its contents? [y/n: n]  y
(如果之前設(shè)置過NIS,則會有這個提示,如果是第一次設(shè)置,不會看到此提示)
...
(ypinit自動調(diào)用Makefile,如果沒有錯誤,則會看到如下提示,若有錯誤返回修改)
nisa has been set up as a yp master server without any errors.
...
    9)啟動NIS服務(wù)守護進程
            # /usr/lib/netsvc/yp/ypstart
(停止進程的命令為 # /usr/lib/netsvc/yp/ypsttop)
    10)檢查master配置狀態(tài)
            # ypwhich -m
            (會顯示NIS域中所有map的名字以及提供這些map的主機)
    以上,配置完了NIS中master的設(shè)置,還需要做的是在master上配置NFS資源,實現(xiàn)autoFS自動掛接home目錄,建立一個用戶testuser測試,步驟如下:
    11)編輯/etc/dfs/dfstab文件,將掛載的存儲資源/netstore設(shè)置為共享
            # vi /etc/dfs/dfstab
share -F nfs -o rw -d "home dirs" /netstore
    12)編輯/nis/passwd、/nis/group、/nis/shadow文件,增加用戶testuser
            # vi /nis/passwd
            testuser:x:1001:1001::/home/testuser:/bin/bash
            (home目錄要設(shè)置為/home/loginname的形式)
            # vi group
            testuser::1001:
            # vi shadow
            testuser::::::::
    13)編輯/nis/auto_home文件,設(shè)置testuser的自動掛接home目錄
            # vi /nis/auto_home
            刪除文件中原來的+auto_home一行,添加如下內(nèi)容
            testuser    nisa:/netstore/testuser
    14)make三個文件,passwd、group、auto_home
            # cd /var/yp
            # /usr/ccs/bin/make passwd group auto_home
    15)創(chuàng)建用戶的home目錄,并把權(quán)限賦給testuser
            # cd /netstore
            # mkdir testuser
            # chown testuser:testuser testuser
    16)設(shè)置testuser的密碼
            # passwd testuser
這樣就完成了添加用戶并設(shè)置自動掛載home目錄的操作,以后添加用戶重復12至16步的操作即可。
#p#
二、配置slave
    1)編輯/etc/hosts文件,添加NIS域中提供NIS服務(wù)的主機(即master和slave)
# vi /etc/hosts
添加如下內(nèi)容
            192.168.0.10   nisa      nisa.nistest.com
    2)配置NIS域名為
            # domainname nistest.com
            # domainname > /etc/defaultdomain
    3)替換/etc/nsswitch.conf文件,先備份,后替換
            # cp /etc/nsswitch.conf /etc/nsswitch.conf.orig
            # cp /etc/nsswitch.nis /etc/nsswitch.conf
    4)運行ypinit -c,將nisb先配置成為客戶端機
            # ypinit -c
            ...
next host to add:  nisa
next host to add:  nisb
next host to add:  ^D(Ctrl+D)
The current list of yp servers looks like this:
nisa
nisb
Is this correct?  [y/n: y]  y
    如果配置master時沒有將nisb添加進去,在這里會看不到nisb機器,需要到master上重新運行# ypinit -m,添加nisb后再到nisb上運行# ypinit -c。
    5)啟動NIS服務(wù)守護進程
            # /usr/lib/netsvc/yp/ypstart
    6)檢查是否已綁定到nisa上
            # ypwhich
            nisa
    7)運行ypinit -s,將nisb配置為slave
            # ypinit -s nisa
            ...
            Do you want this procedure to quit on non-fatal errors? [y/n: n]  y
            ...
            (開始傳送map文件)
            nisb's nis data base has been set up
            without any errors.
    8)重啟NIS服務(wù)守護進程
            # /usr/lib/netsvc/yp/ypsttop
            # /usr/lib/netsvc/yp/ypstart
    9)檢查slaver狀態(tài)
            # ypwhich -m
            (會顯示NIS域中所有map的名字以及提供這些map的主機)
            # ypcat -k ypservers
            nisb
            nisa
三、配置client
    1)編輯/etc/hosts文件,添加NIS域中提供NIS服務(wù)的主機(即master和slave)
# vi /etc/hosts
添加如下內(nèi)容
            192.168.0.10   nisa      nisa.nistest.com
            192.168.0.11   nisb      nisb.nistest.com
    2)配置NIS域名為
            # domainname nistest.com
            # domainname > /etc/defaultdomain
    3)替換/etc/nsswitch.conf文件,先備份,后替換
            # cp /etc/nsswitch.conf /etc/nsswitch.conf.orig
            # cp /etc/nsswitch.nis /etc/nsswitch.conf
    4)運行ypinit -c,將nisc配置為client
            # ypinit -c
            ...
next host to add:  nisa
next host to add:  nisb
next host to add:  ^D(Ctrl+D)
The current list of yp servers looks like this:
nisa
nisb
Is this correct?  [y/n: y]  y
    
    5)啟動NIS服務(wù)守護進程
            # /usr/lib/netsvc/yp/ypstart
    6)檢查slaver狀態(tài)
            # ypwhich -m
            (會顯示NIS域中所有map的名字以及提供這些map的主機)
至此,全部配置完畢。這個時候就可以在nisc上用testuser用戶登錄測試配置是否成功,看看能否實現(xiàn)自動掛接home目錄。還可以在nisa(master)上停掉NIS服務(wù)(# /usr/lib/netsvc/yp/ypstop),然后在nisc(client)上用testuser登錄,測試能否自動切換到nisb(slave)提供NIS服務(wù)。
【編輯推薦】















 
 
 

 
 
 
 