http://lp.wiki.ptt2.cc/-Diskless+FreeBSD+5.2.1+release+++PXE+++DHCP+++NFS+++NI
S
=== 環境 ===
* 只有在 VMware Workstation 4.5.2 build-8848 裡面試過
* server
o freebsd 5.2.1 release
o domainname: server.example.com
o ip: 192.168.1.10
o /usr, /home 為獨立的 partition
o DHCP、NFS、NIS、TFTP server 都在這台上
o 網路部分,是用 VMware 裡的 NAT(VMnat8),並停用 VMnat8 的 DHCP,並
改為使用 192.168.1.0/24(不改也可以啦,只是這樣對我來說比較好記 ^^")
* 二台 client:32MB memory 和 NIC
o node1
+ domainname: node1.example.com
+ ip: 192.168.1.20
+ MAC address: 00:0c:29:3d:f4:94 (MAC address在網路開機的時候
可以看到)
o node2
+ domainname: node2.example.com
+ ip: 192.168.1.23
+ MAC address: 00:0c:29:e9:08:de
=== 設定 TFTP ===
PXE 會透過 tftp 抓 third stage loader (/boot/pxeboot)
編輯 /etc/inetd.conf,去掉 tftp 前的 # ,並設定 tftp 的 root 為 /boot
tftp dgram udp wait root /usr/libexec/tftpd tftpd -s /boot
編輯 /etc/rc.conf,開機時啟用 inetd
inetd_enable="YES"
手動啟用 inetd
# inetd -wW -C 60
=== 設定 NFS ===
所有 diskless workstation 唯讀分享 server 的 / 和 /usr,/home 用可讀寫的方式分
享
編輯 /etc/exports
/usr -ro -maproot=root -alldirs -network=192.168.1.0 -mask=255.255.255.0
/home -maproot=root -alldirs -network=192.168.1.0 -mask=255.255.255.0
/ -ro -maproot=root -alldirs -network=192.168.1.0 -mask=255.255.255.0
編輯 /etc/rc.conf,開機時啟用 nfsd 和 rpcbind
nfs_server_enable="YES"
rpcbind_enable="YES"
手動啟用 nfsd 和 rpcbind
# nfsd -u -t -n 4
# rpcbind
=== 安裝設定 DHCP ===
用 ports 安裝好 net/isc-dhcp3-server
編輯 /usr/local/etc/dhcpd.conf
(裝完 dhcp3 server 並不會有這個檔案,只有一個 sample檔)。
next-server 是告訴 PXE tftp server 在哪,如果 tftp 和 DHCP server 在同一台的話
,可以省略這項設定;filename 是告訴 PXE 要從 tftp 那抓哪個檔案。其它設定說明請
自行參考[ handbook];root-path 就是告訴 diskless client 它的 / 在哪裡
option domain-name "example.com";
default-lease-time 60;
max-lease-time 7200;
authoritative;
ddns-update-style ad-hoc;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.129 192.168.1.254;
option domain-name-servers 192.168.1.2;
option routers 192.168.1.2;
use-host-decl-names on;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
filename "pxeboot";
# next-server 192.168.1.10;
option root-path "192.168.1.10:/";
host node1 {
hardware ethernet 00:0c:29:3d:f4:94;
fixed-address 192.168.1.20;
}
host node2 {
hardware ethernet 00:0c:29:e9:08:de;
fixed-address 192.168.1.30;
}
}
編輯 /etc/rc.conf ,開機時啟用 dhcpd
dhcpd_enable="YES"
手動啟用 dhcpd
# /usr/local/etc/rc.d/isc-dhcpd.sh start
設定 NIS/YP
我選 "diskless-domain" 當做我的 NIS domainname,並且 server 和所有的 client 都
用 NIS/YP,NIS/YP 使用的 master.passwd 放在 /var/yp
把 /etc/master.passwd 複製到 /var/yp
# cp /etc/master.passwd /var/yp
執行 vipw 並移除所有一般 user 的 account,
在最後一行加上 +::::::::: (一個 +,9個 :)
修改 /etc/group,移除所有一般 user 的 group,在最後一行加上 +:*::
修改 /var/yp/master.passwd 移除所有系統帳號,只留下一般使用者的帳號
初始化 NIS/YP 相關檔案,他會問一些問題
# ypinit -m diskless-domain
[略]
修改 /etc/hosts 多加入 server、node1、node2 的資訊
192.168.1.10 server.example.com server
192.168.1.20 node1.example.com node1
192.168.1.30 node2.example.com node2
編輯 /etc/rc.conf,開機時啟用 NIS/YP 服務
nisdomainname="diskless-domain"
nis_server_enable="YES"
nis_client_enable="YES"
nis_yppasswdd_enable="YES"
手動啟動
# domainname diskless-domain
# /usr/sbin/ypserv
# /usr/sbin/ypbind
# /usr/sbin/rpc.yppasswdd
如果要新增或修改 NIS/YP 使用者帳號的話,可以用 pw 搭配 -V -Y 的參數
-V 指定 password 相關檔案、pwd.conf、group 放在哪
-Y pw 有修改檔案的話,到 /var/yp 執行 make
在這之前先在製造 pwd.db 和 spwd.db,使用 pw 才不會有錯誤
# pwd_mkdb -d /var/yp master.passwd
例如要新增一個叫 test 的使用者
# pw useradd test -h0 -s /bin/tcsh -V /var/yp -Y
Password for user test:
NIS Map update started on Thu Aug 5 17:46:29 CST 2004 for domain diskless-dom
ain
Updating passwd.byname...
Updating passwd.byuid...
Updating netid.byname...
Updating master.passwd.byname...
Updating master.passwd.byuid...
NIS Map update completed.
#
=== 設定 diskless client ===
diskless client 開機順序如下:
PXE 載入 server 端的 /boot/pxeboot,pxeboot 再去載入 kernel,kernel 控制權交給
/sbin/init,首先執行 /etc/rc (檔案在 server 端),/etc/rc 會先執行
/etc/rc.d/initdiskless (檔案在 server 端),接下來會去執行 /etc/rc.d (檔案在
client 端了)下的 shell script/etc/rc.d/initdiskless 會自動 create 三個
memory filesystems: /etc, /var, /tmp,並且會把 server 的
/conf/base/etc 複製到 client 的 /etc
建立 /conf/base 目錄,並複製 server 的 /etc 到 /conf/base:
# mkdir -p /conf/base
# cp -r /etc /conf/base
修改 /conf/base/fstab (這個檔案就是 client 端的 /etc/fstab)
192.168.1.10:/usr /usr nfs ro 0 0
192.168.1.10:/home /home nfs rw 0 0
修改 /conf/base/rc.conf,去掉一些 server 端的東西,例如剛剛加的 dhcpd_enable
等,並且啟用 nfs client,我的 /conf/base/rc.conf 長這樣:
usbd_enable="NO"
sendmail_enable="NONE"
syslogd_flag="-ss"
sshd_enable="YES"
nfs_client_enable="YES"
rpcbind_enable="YES"
#ifconfig_lnc0="DHCP"
nisdomainname="diskless-domain"
nis_client_enable="YES"
VMWare 的網路卡在 freebsd 下的名稱是 lnc0,本來想用 DHCP 的方式取得 ip 並設定
hostname,可是 client 開機的時候會停在
Starting dhclient.
nfs send error 65 for server 192.168.1.10:/
如果有人知道怎麼解決,請告訴我,謝謝 :)
即使沒有 ifconfig_lnc0="DHCP" diskless client 開完機會是會自動設好 ip,只是
hostname 沒有設,所以要在 rc.conf 多加 hosname 的設定,/conf/${ip}/rc.conf
會覆蓋過 /conf/base/rc.conf 的設定
把 /conf/base/etc/rc.d 複製到 /conf/${ip}/etc 下,並分別增加 hostname 的設定
# mkdir -p /conf/192.168.1.20/etc
# cp /conf/base/etc/rc.conf /conf/192.168.1.20/etc
# echo hostname="node1" >> /conf/192.168.1.20/etc/rc.conf
# mkdir -p /conf/192.168.1.30/etc
# cp /conf/base/etc/rc.conf /conf/192.168.1.30/etc
# echo hostname="node2" >> /conf/192.168.1.30/etc/rc.conf
設定到此,diskless client 就可以開機了,並可以 ssh 連進去,
打 mount 的結果:
> mount
192.168.1.10:/ on / (nfs, read-only)
devfs on /dev (devfs, local)
/dev/md0 on /etc (ufs, local, soft-updates)
/dev/md1 on /var (ufs, local, soft-updates)
192.168.1.10:/usr on /usr (nfs, read-only)
192.168.1.10:/home on /home (nfs)
/dev/md2 on /tmp (ufs, local, soft-updates)
=== REF ===
freebsd handbook
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/
Diskless FreeBSD?-5.2.1
http://www.opennet.ru/docs/RUS/diskless-FreeBSD/
Google ^^"
http://www.google.com.tw
=== Appendix 1 ===
如果不想使用 server 的 / 當 diskless client 的 root filesystem,也可以用其它資
料夾,不過要複製一些開機要用的檔案到該資料夾。
例如我想用 /diskless 當 diskless client 的 root filesystem,複製需要的檔案
# cp -r /boot /bin /lib /libexec /sbin /diskless/
然修改 dhcpd.conf 中的 root-path 指到 192.168.1.10:/diskless 就可以了
=== Apendix 2 ===
嫌每次登入到不同機器都要再打一次密碼很麻煩的話,可以利用 ssh-agent,
相關設定請參考:
http://www.openfoundry.org/OSSF-TECH/9.ActivityLog/f.Suponsor-TR/sso.html
http://mah.everybody.org/docs/ssh
http://www.wlug.org.nz/SSHKeys
--
夫兵者不祥之器物或惡之故有道者不處君子居則貴左用兵則貴右兵者不祥之器非君子
之器不得已BBS telnet://wretch.twbbs.org 開個人板 超快 不用連署得志於天下
矣吉事尚左凶事尚右偏將軍居左上將軍居右言以喪禮處之殺人之眾以哀悲泣之戰勝以
喪禮處之道常無名樸雖小天下莫能臣侯王若能守之萬物將自賓天地相合以降甘露民莫
之令而自均始制有名名亦既有夫亦將知止知止可以不殆譬道vesta.ee.nthu.edu.tw海
作者在 04/08/05 18:18:13 從 vesta.ee.nthu.edu.tw 修改這篇文章
如果有任何謬誤,請給我指正,謝謝 :)