1. 簡介linux
本文介紹經過VMware創建Centos無盤系統的測試過程
基本實現原理:在Image Server上創建dhcp,tftp,nfs服務,而後啓動diskless client—>dhcp得到IP—>tftp獲取內核文件vmlinuz(可引導的、壓縮的內核), initrd.img(用來臨時的引導硬件到實際內核vmlinuz可以接管並繼續引導的狀態)--->經過nfsroot(Mounting the root filesystem via NFS)來掛載根分區到Image Server上實現無盤系統
2.
經過Yum 安裝dhcp,tftp,nfs ,busybox-anaconda(用於redhat的安裝管理程序一個單一的binary,包含大量系統指令,包括shell), system-config-netboot-cmd(用於命令行下創建無盤環境)
l
yum –y install dhcp tftp nfs-utils nfs-utils-lib busybox-anaconda system-config-netboot-cmd
|
3.
修改dhcp配置文件並啓動
l
vi /etc/dhcpd.conf
allow bootp;
allow booting;
ddns-update-style interim;
ignore client-updates;
subnet 192.168.159.0 netmask 255.255.255.0 {
range 192.168.159.200 192.168.159.220;
default-lease-time 21600;
max-lease-time 43200;
option routers 192.168.159.2;
option domain-name-servers 192.168.159.2;
option subnet-mask 255.255.255.0;
option domain-name "pwrd.com";
option time-offset -18000;
filename "linux-install/pxelinux.0"; #須要指定pxelinux.0(PXE啓動引導文件)的位置,默認在/tftpboot下
next-server 192.168.159.120; #指定tftp的IP地址
#能夠指定diskless client的IP地址
host test4 {
hardware ethernet 00:0c:29:a3:86:c3;
fixed-address 192.168.159.130;
}
}
#啓動dhcp, 若有報錯能夠查看/var/log/messages 中的log
l
/etc/init.d/dhcpd start
|
4.
修改tftp配置文件並啓動
l
vi /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot #指定tftp下載的主目錄
disable = no #從yes改成no
per_source = 11
cps = 100 2
flags = IPv4
}
#啓動tftp, 若有報錯能夠查看/var/log/messages 中的log
l
/etc/init.d/xinetd start
|
5.
創建diskless client所須要的root目錄,並同步系統文件到diskless root目錄中,在根目錄下排除不須要的目錄便可,好比/proc /sys
l
mkdir -p /diskless/centos/test4/root/
#192.168.159.120爲本機,p_w_picpath server
l
rsync -v -a -e ssh --exclude='/proc/*' --exclude='/sys/*' --exclude='/mnt/*' 192.168.159.120:/ /diskless/centos/test4/root/
|
6.
修改NFS配置文件,指定掛載目錄,並啓動NFS服務
#snapshot 是爲了那些每個diskless client都須要讀寫的部分,例如/var/log/messages等
l
vi /etc/exports
/diskless/centos/test4/root/ *(rw,sync,no_root_squash,no_all_squash)
/diskless/centos/test4/root/snapshot/ *(rw,sync,no_root_squash,no_all_squash)
#啓動portmap 和NFS, 若有報錯能夠查看/var/log/messages 中的log
/etc/init.d/portmap start
/etc/init.d/nfs start
查看rpcinfo和export list
rpcinfo –p
showmount -e 192.168.159.120
|
7.
命令下設置diskless的引導環境
#The 「pxeos」 enables you to create a new operating system under /tftpboot and places the vmlinux and initrd p_w_picpaths there.
Options for 「pxeos」: #生成NFS引導的內核文件
l
pxeos -a -i centoskernel -p NFS -D 1 -s 192.168.159.120 -L /diskless/centos/test4 centoskernel
#查看pxeos是否成功
l
pxeos -l
#查看NFS引導的內核文件是否生成
l
ll /tftpboot/linux-install/centoskernel/
#查看pxeos生成的配置文件
l
more /tftpboot/linux-install/pxelinux.cfg/pxeos.xml
The 「pxeboot」 command adds clients to the diskless environment and creates the HEX file for the host in the /tftpboot directory
Options for 「pxeboot」: #生成diskless client所須要的啓動文件,指定IP爲192.168.159.130
l
pxeboot -a -O centoskernel -r 28753 -S test4 -e eth0 -s console=ttyS0,115200n8r 192.168.159.130
#也能夠不用pxeboot命令,而用01+MAC地址做爲文件名(注意小寫,因爲PXE的尋址規律)
l
cat /tftpboot/linux-install/pxelinux.cfg/01-00-0c-29-a3-86-c3
default centoskernel
label centoskernel
kernel centoskernel/vmlinuz
append console=ttyS0,9600n8 initrd=centoskernel/initrd.img root=/dev/ram0 init=diskle***c NFSROOT=192.168.159.120:/servers_drbd/centos/coreclient/test4 ramdisk_size=28753 ETHERNET=eth0 SNAPSHOT=test4
|
8.
新建一臺Vmware,只需分配內存和CPU,做爲diskless client
如何獲取MAC地址:
diskless client啓動時會廣播DHCP request, 在Image Server中 tail -f /var/log/messages能夠看到,根據step 7中的格式寫入到/tftpboot/linux-install/pxelinux.cfg中,或者寫入到step 3中的dhcpd.conf,並分配固定IP地址,而後用step 7中的pxeboot生成啓動文件
l
tail -f /var/log/messages
Dec 11 00:50:29 test3 dhcpd: DHCPDISCOVER from 00:0c:29:a3:86:c3 via eth0
Dec 11 00:50:29 test3 dhcpd: DHCPOFFER on 192.168.159.130 to 00:0c:29:a3:86:c3 via eth0
Dec 11 00:50:31 test3 dhcpd: DHCPREQUEST for 192.168.159.130 (192.168.159.120) from 00:0c:29:a3:86:c3 via eth0
Dec 11 00:50:31 test3 dhcpd: DHCPACK on 192.168.159.130 to 00:0c:29:a3:86:c3 via eth0
l
ls /tftpboot/linux-install/pxelinux.cfg/01-00-0c-29-a3-86-c3
|
9.
啓動成功後能夠檢查diskless client和p_w_picpath server的同步狀況
因爲NFS設置成了sync模式,則在diskless client上的任何增刪改操做都會實時同步到p_w_picpath server的nfs 掛載目錄
參考資料: