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 挂载目录
参考资料: