Solaris 8 automount & NIS 實作

因新工作的需要 最近都在研究SUN的Solaris系統
花了一個月時間把官方原廠教材SA-118和SA-288看完一遍
於是在公司裡找了閒置的三台Sun Blade 150 主機 當作實驗用
這次主要針對automount 和 NIS Server 這部份的實作
將個人研究出來的心得寫出來也希望有興趣的網友可以參考看看!

auto mount 它是屬於 dynamic mount, 也就是說,當你有使用這個 mount 的目錄
時, 系統才會自動的幫你把這個目錄mount進來.
它不同於 static mount , 是在於 static mount 是在系統開機時, 便 mount 進來
了,而且除非系統關機,或是 root 把它 unmount 掉, 不然的話,你隨時打 mount,
都可以看到它有 mount 上.
使用 auto mount 的好處是,因為它是在你有用到該目錄時才做  mount 的動作,
所以用它來 mount NFS 的話,可以不必等對方的 server 起來, 你就能開機,而且
auto mount 它有設定說,在一定時間內,如果該目錄沒被使用,則系統會自動將它
unmount 掉. 這樣又可減少因 mount NFS 而影響系統效率.
那麼現在就開始實作吧

實作環境:
使用的OS為Solaris 8 SPARC 02/04
主機名稱 sun1  (NIS Master) IP:192.168.1.101
主機名稱 sun2  (NIS Slave)   IP:192.168.1.102
主機名稱 sun3  (client)          IP:192.168.1.103

nis domainname 為 asus.com.tw
user帳號 為 may  (家目錄要掛在sun1:/export/may)
user帳號 為 john  (家目錄要掛在sun2:/export/john)
user帳號 為 kevin (家目錄要掛在sun3:/export/kevin)
user密碼皆為1234
sun1主機/etc/passwd 的user帳號皆登入到/home/user名稱
indirect map 使用auto_home 來掛載上述三位user
direct map 使用auto_tools point為/data 掛載在sun3:/eda/tools


1. 先將三台主機名稱都加入hosts裡
% vi /etc/hosts
192.168.1.101  sun1
192.168.1.102  sun2
192.168.1.103  sun3

2. 修改sun1,sun2,sun3主機 將要分享的目錄share出來
%  vi /etc/dfs/dfstab
share -F nfs -o rw,root=sun1:sun2:sun3  /export (sun1,sun2,sun3增加此行)
share -F nfs -o rw,root=sun1:sun2  /eda/tools (sun3請再增加這行)

然後三台主機都要啟動nfs service

% /etc/init.d/nfs.server stop
% /etc/init.d/nfs.server start
% shareall
% dfshares (可以看有沒有確實分享出來)

3. 修改 /etc/auto_master

這個檔是 automount 的主要設定檔,它裡面有定義要 mount 哪些目錄.
另外,它亦可以參考到另一個你自己設定的 automount 設定檔.

% vi /etc/auto_master
# Master map for automounter
#
+auto_master  (yp作完後如果無法掛載direct map 可以把此行註解起來看看)
/net            -hosts          -nosuid,nobrowse
/home        auto_home       -nobrowse
/xfn            -xfn
/-               auto_tools


% vi /etc/auto_home
may    sun1:/export/may
john   sun2:/export/john
kevin  sun3:/export/kevin


% vi /etc/auto_tools
/data  sun3:/eda/tools


在 /etc/auto_home 中, john則是去 mount 一台叫 sun2 它所 share 出來
/export/john 的目錄, 並將它 mount 到自己機器 /home下
所以你在/home 輸入ls 是看不到的任何目錄的 是因為在auto_master 有加入-nobrowse這個參數 也就是得要輸入cd john 才可以mount 上去

另外使用 automount 的話,在你自己的機器上,並不需要自己去建立要 mount 的目錄, 以上面auto_tools為例,你並不需要在 / 下建立 data 這個目錄再做 mount. auto mount 它會自動幫你建立這個目錄,且幫你mount 上去.

2. 改好了 auto mount 的設定檔之後,你必需重跑 autofs 才會使你修改的auto mount 生效. 執行方法如下:

% /etc/init.d/autofs stop
% /etc/init.d/autofs start
% automount -v

執行完之後, 你就可以在sun1主機到你 mount 的目錄下打 ls 看看是否有 mount 進來了.
% ls /home/john

sun1主機的automount這部份就完成了,那麼接下來就要開始做NIS server 以方便帳號整合在其他兩台主機上

% cd /etc
% cp nsswitch.nis nsswitch.conf
% domainname asus.com.tw
% domainname > defaultdomain
% touch ethers netgroup bootparams netmasks timezone locale
% cd /etc/security
% cp audit_user auth_attr exec_attr prof_attr /etc

因為我們在auto_master裡有自行增加auto_tools這個非預設的map file所以得編輯Makefile 不然做yp時會出現找不到的訊息

% vi /var/yp/Makefile

all: passwd group hosts ipnodes ethers networks rpc services protocols \
        netgroup bootparams aliases publickey netid netmasks c2secure \
        timezone auto.master auto.home auto_tools \
        auth.attr exec.attr prof.attr user.attr audit.user

底下請注意前面空格和TAB 鍵的區分(初學者最容易出錯的地方)
auto.tools.time:  $(DIR)/auto_tools
        -@if [ -f $(DIR)/auto_tools ]; then \
                sed -e "/^#/d" -e s/#.*$$// $(DIR)/auto_tools \
                | $(MAKEDBM) - $(YPDBDIR)/$(DOM)/auto.tools; \
                touch auto.tools.time; \
                echo "updated auto.tools"; \
                if [ ! $(NOPUSH) ]; then \
                        $(YPPUSH) auto.tools; \
                        echo "pushed auto.tools"; \
                else \
                : ; \
                fi \
        else \
                echo "couldn't find $(DIR)/auto_tools"; \
        fi

auto.tools: auto.tools.time

$(DIR)/auto_tools:


編輯完後就可以正式做yp master部分了

% ypinit -m
next host to add:  sun1
next host to add:  sun2  (加入slave主機名稱)
然後按<control D> 跳出

Is this correct?  [y/n: y]  y

Do you want this procedure to quit on non-fatal errors? [y/n: n]  n

完成後啟動 yp service

% /usr/lib/netsvc/yp/ypstart
starting NIS (YP server) services: ypserv ypbind ypxfrd rpc.yppasswdd rpc.ypupdated done.

這樣sun1就大功告成了,你可以測試看看使用telnet登入時輸入john 和密碼(一定要設密碼) 就會自動登入在/home/john下啦

往後只要有修改到/etc下的hosts,passwd,shadow,group,auto.home,auto_tools 裡的內容都要執行下列指令來更新NIS資料庫
% cd /var/yp
% /usr/ccs/bin/make

--------------------------------------------
sun2  NIS Slave 設定

% cd /etc
% cp nsswitch.nis nsswitch.conf
% domainname asus.com.tw
% domainname > defaultdomain

先以client方式加入NIS

% ypinit -c
next host to add:  sun1
next host to add:  sun2

然後按<control D> 跳出
Is this correct?  [y/n: y]  y

啟動 yp service
/usr/lib/netsvc/yp/ypstart
starting NIS (YP server) services: ypbind done.


設定為slave
% ypinit -s sun1
Do you want this procedure to quit on non-fatal errors? [y/n: n]  n

重新啟動 yp service
/usr/lib/netsvc/yp/ypstop
/usr/lib/netsvc/yp/ypstart

完成後一樣再做telnet 登入sun2,看看是否帳號有整合成功

---------------------------------------------------------
sun3 client 設定

% cd /etc
% cp nsswitch.nis nsswitch.conf
% domainname asus.com.tw
% domainname > defaultdomain

先以client方式加入NIS

% ypinit -c
next host to add:  sun1
next host to add:  sun2

然後按<control D> 跳出
Is this correct?  [y/n: y]  y

啟動 yp service
/usr/lib/netsvc/yp/ypstart
starting NIS (YP server) services: ypbind done.

這樣client端設定就完成了!


client端如果要檢驗NIS是否有連線成功 可以執行底下兩種指令:
% ypwhich -m 檢查NIS Client與server之間溝通的資料庫名稱
% ypcat auto.home 檢查是否已經從master主機取回資料庫內容

留言

這個網誌中的熱門文章

VMware ESXi OVF Tool 指令模式 匯出、匯入 OVA

軛瓣蘭 (Zygopetalum) 種植日記

ETF 月月配息組合