歡迎您光臨本站 註冊首頁

Linux無盤工作站架設實例

←手機掃碼閱讀     火星人 @ 2014-03-05 , reply:0

Linux無盤工作站架設實例

客戶端是支持PXE方式啟動的刀片,用Linux作為伺服器,伺服器配置如下:


1) 安裝DHCP伺服器dhcpd


2) 配置/etc/dhcpd.conf文件,下面是我機器上的文件


max-lease-time -1;
default-lease-time -1; #注:IP地址永不過期
option subnet-mask 255.0.0.0;
option routers 10.0.0.1;
option domain-name-servers 10.10.10.10;
# option netbios-name-servers 10.10.10.10;
option broadcast-address 10.255.255.255;
# option dhcp-class-identifier "PXEClient";
# option vendor-encapsulated-options 01:04:00:00:00:00:ff;
# option option-135 "start";

subnet 10.0.0.0 netmask 255.0.0.0 {
range 10.10.12.131 10.10.12.150;

host blade01 {
hardware ethernet 00:e0:43:00:02:00;
fixed-address 10.10.12.131;
filename "/tftpboot/pxelinux.0"; #注:啟動映象文件
}

host blade02 {
hardware ethernet 00:e0:43:00:02:02;
fixed-address 10.10.12.132;
filename "/tftpboot/pxelinux.0";
}

host blade03 {
hardware ethernet 00:e0:43:00:02:04;
fixed-address 10.10.12.133;
filename "/tftpboot/pxelinux.0";
}

host blade04 {
hardware ethernet 00:e0:43:00:02:06;
fixed-address 10.10.12.134;
filename "/tftpboot/pxelinux.0";
}

host blade05 {
hardware ethernet 00:e0:43:00:02:08;
fixed-address 10.10.12.135;
filename "/tftpboot/pxelinux.0";
}
}



  說明:dhcp客戶得到IP地址後用TFTP協議從伺服器上下載啟動映象文件。我用syslinux

  工具包裡邊的pxelinux來作為遠程啟動的loder.

3) 配置tftp server

  使用pxelinux作引導工具需要支持TSIZE參數的tftp server。可從http://www.kernel.org/pub/software/network/tftp/下載。

  通過xinetd來使用tftp服務,我的/etc/xinetd.conf文件如下


......
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
}



4) 配置PXELINUX

  先安裝syslinux軟體包。可從http://www.kernel.org/pub/linux/utils/boot/syslinux/下載。

  將pxelinux.0拷貝到/tftpboot/目錄下,然後建立/tftpboot/syslinux.cfg/目錄。該目錄下存放配置文件。

  pxelinux使用ip地址的十六進位表示來作為該ip地址的配置文件的文件名。如blade01的

  ip地址為10.10.12.131,配置文件名為0A0A0C83,內容為:


default linux

label linux
kernel vmlinuz
append ip=dhcp root=/dev/nfsroot nfsroot=10.10.11.120:/remote/blade01 vga=normal



5) 配置nfs

  為每個刀片建立一個根目錄,在該刀片的pxelinux配置文件里指定了從這個nfs export的目錄啟動。

  該根目錄里應把標準的目錄都建好,另外需要重新mount的usr, home, public等目錄也要export。

  我的 /etc/exports文件:


# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).

/remote/blade01 blade01(rw,async,no_root_squash)
/remote/blade02 blade02(rw,async,no_root_squash)
/remote/blade03 blade03(rw,async,no_root_squash)
/remote/blade04 blade04(rw,async,no_root_squash)
/remote/blade05 blade05(rw,async,no_root_squash)
/remote/root *(rw,async,no_root_squash)
/remote/home *(rw,async,no_root_squash)
/usr *(ro,async,no_root_squash)
/sbin *(ro,async,no_root_squash)
/bin *(ro,async,no_root_squash)
/lib *(ro,async,no_root_squash)
/home *(ro,async,no_root_squash)


6)為每個刀片修改它的/etc/fstab文件,以blade01為例,它的nfs root是/remote/blade01
/remote/blade01/etc/fstab文件如下:
# /etc/fstab: static file system information.
#
#
10.10.11.120:/remote/blade01 / nfs defaults,intr 0 1
10.10.11.120:/remote/root /root nfs defaults,intr 0 1
10.10.11.120:/remote/home /home nfs defaults,intr 0 1
10.10.11.120:/bin /bin nfs defaults,intr 0 1
10.10.11.120:/usr /usr nfs defaults,intr 0 1
10.10.11.120:/sbin /sbin nfs defaults,intr 0 1
10.10.11.120:/lib /lib nfs defaults,intr 0 1
none /proc proc defaults,intr 0 1



  同時還要為每個刀片修改它的網路配置文件,配置ip地址,啟動兩塊網卡等等。。

7) 編譯內核

  刀片用的內核,應該支持Kernel Level Auto Configuration的DHCP協議,支持NFS,支持NFS ROOT,

  假設編譯好的內核為vmlinuz,將它拷貝到/tftpboot/目錄下。

參考文檔:

http://syslinux.zytor.com/pxe.php
http://syslinux.zytor.com/faq.php
http://www.cn-cio.org/xx/show.php?article_id=1680
http://www-900.ibm.com/developerWorks/cn/linux/l-tip-prompt/l-pex/index.shtml
《解決方案》

如何遠程安裝Linux  
級別: 初級
湯凱 (tangk73@hotmail.com),
2002 年 12 月 09 日
本文介紹了在不需要光碟機和軟碟機的情況下,如何通過PXE協議快速安裝Linux的原理和步驟,這對於提高安裝Linux的效率非常有幫助;同時,PXE協議也可以作為無盤linux技術,用於引導遠程的Linux啟動。1. 引言
一般情況下,我們都是利用軟碟機或光碟機引導Linux后,再通過本地的光碟機安裝Linux。但是,這種安裝方法在以下的幾種情況下就不能適用:
[*]無軟碟機和光碟機:很多公司為了節省成本,計算機一般都不帶光碟機或軟碟機,這樣就無法通過本地安裝Linux;[*]非標準的軟碟機和光碟機:雖然筆記本都會配置光碟機,但是並不一定都是標準的IDE設備,有些是通過USB介面,有些是通過1394介面(例如Samsung的Q10)。在Linux安裝時所引導的Linux內核一般都不會帶這些介面的驅動,所以也無法通過本地安裝Linux;[*]另外,在一些場合,如機房中,有大量的計算機需要同時安裝Linux,如果通過光碟機的方式一個個安裝,不僅效率低,也不利於維護。筆者在工作過程中,就遇到過第二種情況。一台Samsung的Q10筆記本需要安裝Redhat Linux 8.0,但是通過光碟機引導后發現,安裝程序無法訪問光碟。針對這個問題,筆者經過查閱資料和摸索,找到了在Q10上安裝Linux的方法。在下面的討論中,如不做特別聲明,都將以Q10為例,介紹如何通過PXE Bootrom來遠程安裝Linux。

http://www.ibm.com/i/v14/rules/blue_rule.gif
http://www.ibm.com/i/c.gifhttp://www.ibm.com/i/c.gif
http://www.ibm.com/i/v14/icons/u_bold.gif
回頁首


2. 基本原理
1) 什麼是PXE
PXE(Pre-boot Execution Environment)是由Intel設計的協議,它可以使計算機通過網路啟動。協議分為client和server兩端,PXE client在網卡的ROM中,當計算機引導時,BIOS把PXE client調入內存執行,並顯示出命令菜單,經用戶選擇后,PXE client將放置在遠端的操作系統通過網路下載到本地運行。
PXE協議的成功運行需要解決以下兩個問題:
[*]既然是通過網路傳輸,那麼計算機在啟動時,它的IP地址由誰來配置;[*]通過什麼協議下載Linux內核和根文件系統對於第一個問題,可以通過DHCP Server解決,由DHCP server來給PXE client分配一個IP地址,DHCP Server是用來給DHCP Client動態分配IP地址的協議,不過由於這裡是給PXE Client分配IP地址,所以在配置DHCP Server時,需要增加相應的PXE特有配置。
至於第二個問題,在PXE client所在的ROM中,已經存在了TFTP Client。PXE Client使用TFTP Client,通過TFTP協議到TFTP Server上下載所需的文件。
這樣,PXE協議運行的條件就具備了,下面我們就來看看PXE協議的工作過程。
2) 工作過程


http://www-128.ibm.com/developerworks/cn/linux/l-tip-prompt/l-pex/1.gif

在上圖中,PXE client是需要安裝Linux的計算機,TFTP Server和DHCP Server運行在另外一台Linux Server上。Bootstrap文件、配置文件、Linux內核以及Linux根文件系統都放置在Linux Server上TFTP伺服器的根目錄下。
PXE client在工作過程中,需要三個二進位文件:bootstrap、Linux 內核和Linux根文件系統。Bootstrap文件是可執行程序,它向用戶提供簡單的控制界面,並根據用戶的選擇,下載合適的Linux內核以及Linux根文件系統。

http://www.ibm.com/i/v14/rules/blue_rule.gif
http://www.ibm.com/i/c.gifhttp://www.ibm.com/i/c.gif
http://www.ibm.com/i/v14/icons/u_bold.gif
回頁首


3. 步驟
有了前面的背景知識,接下來就可以正式操作了,下面按照順序給出了操作步驟:
1) 配置DHCP Server
選用ISC dhcp-3.0,DHCP Server的配置文件是/etc/dhcpd.conf,配置文件的內容如下:
option space PXE;option PXE.mtftp-ip               code 1 = ip-address;  option PXE.mtftp-cport            code 2 = unsigned integer 16;option PXE.mtftp-sport            code 3 = unsigned integer 16;option PXE.mtftp-tmout            code 4 = unsigned integer 8;option PXE.mtftp-delay            code 5 = unsigned integer 8;option PXE.discovery-control      code 6 = unsigned integer 8;option PXE.discovery-mcast-addr   code 7 = ip-address;class "pxeclients" {    match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";    option vendor-class-identifier "PXEClient";    vendor-option-space PXE;    # At least one of the vendor-specific PXE options must be set in    # order for the client boot ROMs to realize that we are a PXE-compliant    # server.  We set the MCAST IP address to 0.0.0.0 to tell the boot ROM    # that we can't provide multicast TFTP (address 0.0.0.0 means no    # address).    option PXE.mtftp-ip 0.0.0.0;    # This is the name of the file the boot ROMs should download.    filename "pxelinux.0";    # This is the name of the server they should get it from.    next-server 192.168.0.1;}ddns-update-style interim;ignore client-updates;default-lease-time 1200;max-lease-time 9200;option subnet-mask 255.255.255.0;option broadcast-address 192.168.0.255;option routers 192.168.0.254;option domain-name-servers 192.168.0.1,192.168.0.2;option domain-name "mydomain.org";subnet 192.168.0.0 netmask 255.255.255.0 {range 192.168.0.10 192.168.0.100;} host q10 {hardware ethernet 00:00:F0:6B:38:5B;        fixed-address 192.168.0.22;}
dhcpd.conf配置文件中幾個關鍵部分說明如下:host q10{…}定義了筆記本Q10網卡的MAC地址與IP地址的對應關係,表明DHCP Server為Q10分配一個固定的IP:192.168.0.22;filename ""指定bootstrap的文件名;netx-server指定TFTP Server的地址。其它的配置請讀者參考DHCP Server的手冊。
2) 配置TFTP server
選用tftp-hpa,TFTP Server的配置文件是/etc/xinetd.d/tftp,配置文件的內容如下:
        service tftp{        socket_type             = dgram        protocol                = udp        wait                    = yes        user                    = root        server                  = /usr/sbin/in.tftpd        server_args             = -u nobody -s /tftpboot        disable                 = no        per_source              = 11        cps                     = 100 2        }       
這裡制定了/tftpboot為TFTP Server的根目錄位置。
3) 配置bootstrap
bootstrap文件在dhcpd.conf中被指定為pxelinux.0文件,放置在/tftpboot。Linux內核以及Linux根文件系統也放置在/tftpboot。pxelinux.0在執行過程中,要讀配置文件,所有的配置文件都放在/tftpboot/pxelinux.cfg/目錄下。由於PXElinux具有為不同的PXE Client提供不同的Linux內核以及根文件系統的功能,所以要通過不同的配置文件名來區分出不同的PXE Client的需求。比如一個PXE Client由DHCP Server分配的IP地址為192.168.0.22,那麼相對應的配置文件名為/tftpboot/pxelinux.cfg/C0A80016(註:C0A80016為IP地址192.168.0.22的十六進位表示)。如果找不到,就按照順序C0A80016-> C0A8001-> C0A800-> C0A80-> C0A8-> C0A-> C0-> C->default查找配置文件。
/tftpboot/pxelinux.cft/C0A80001配置文件的具體內容如下:
DEFAULT install
PROMPT 1
LABEL install
KERNEL vmlinuz
APPEND initrd=initrd.img devfs=nomount ramdisk_size=16384
此配置文件指定了Linux內核以及根文件系統的名稱,並給內核傳遞了一些參數,其中ramdisk_size參數要非常注意,它指定Linux內核啟動后建立ramdisk的大小,如果設置太小,Linux的安裝過程就可能無法進行。
4) 製作Linux內核/根文件系統
因為需要通過網路安裝,所有選擇Redhat Linux 8.0安裝盤(disk #1)中E:\images\bootnet.img(光碟機的盤符為E:)。bootnet.img包括Linux內核、Linux根文件系統(有安裝程序在內)。用bootnet.img製作一張引導軟盤,方法在DOS命令行運行E:\dosutils\rawrite E:\images\bootnet.img,根據提示製作。製作完畢后,將引導軟盤中的vmlinuz(Linux內核)和initrd.img(Linux根文件系統)拷貝到Linux Server的/tftpboot下。
5) 啟動DHCP Server/TFTP Server
在Linux Server上,運行service dhcpd start和service xinetd restart。
6) 啟動Q10
Q10加電后,在出現Samsung公司徽標時,在左下角會提示用戶按F12進入網路引導。按F12后,Q10進入網路引導過程。首先通過DHCP Server獲得了IP地址,然後下載並執行bootstrap文件pxelinux.0;在執行中,讀入配置文件/tftpboot/pxelinux.cfg/C0A80016。此時屏幕上出現boot:,敲入install,就進入了Redhat Linux 8.0的網路安裝界面,一切OK!

http://www.ibm.com/i/v14/rules/blue_rule.gif
http://www.ibm.com/i/c.gifhttp://www.ibm.com/i/c.gif
http://www.ibm.com/i/v14/icons/u_bold.gif
回頁首


4. 結束語
雖然以上的討論是針對Samsung Q10筆記本,但是工作原理和安裝方法對於其它類型的計算機也是適用的,不過要記住,計算機的網卡中必須要有BootROM--PXE Client。同時,PXE協議也可作為無盤Linux技術,用於引導放置在遠程的Linux。實際上,只要根據需要,在Pxelinux的配置文件的APPEND選項中,為Linux內核傳進需要mount的文件系統的位置參數即可。



參考資料
[*]PXELINUX, http://syslinux.zytor.com/pxe.php[*]Net booting with DHCP, PXE-Linux and TFTP, http://logout.sh/computers/linux/netboot/[*]Different kinds of PXE, http://clic.mandrakesoft.com/documentation/pxe/ch02.html
《解決方案》

高手!
收藏了!
謝謝!

[火星人 ] Linux無盤工作站架設實例已經有398次圍觀

http://coctec.com/docs/service/show-post-41170.html