利用PXE Server大量部署Linux(3)

接着修改/etc/dhcpd.conf,为了避免网段上其它的主机索取到DHCP IP,请将「range dynamic-bootp 192.168.0.128 192.168.0.254;」删除。本篇文章假设真实环境的网段为192.168.0.0/24,所以只需在档桉最后}结尾上面加下TFTP Server及MAC Address的相关设定即可。

ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
#range dynamic-bootp 192.168.0.128 192.168.0.254;删除
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.RedHat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254; }
next-server 192.168.0.254; TFTP Server是192.168.0.254
filename "pxelinux.0"; PXE Linux boot loader pxelinux.0
include "/etc/dhcpd.mac.lst"; Include MAC Address相关内容
}
只需在档桉最后结尾}上加入以上三行设定

然后重新启动dhcp service #service dhcpd restart

3.5 建立/tftpboot/pxelinux.cfg/default

# mkdir pxelinux.cfg
# cd pxelinux.cfg/
# chmod o+w /tftpboot/pxelinux.cfg
# cat > default << EOF
default 0
label 0
localboot 0
EOF

3.6 建立产生PXE设定档的shell script (mkpxe.sh)

利用下列的script (mkpex.sh)来产生个别的PXE设定档
#!/bin/bash
OUTDIR="/tftpboot/pxelinux.cfg"
KSFILE=$(printf '%02X' ${1//./ })
cat > $OUTDIR/$KSFILE << EOF
DEFAULT 0
LABEL 0
kernel vmlinuz
append initrd=initrd.img noipv6 ks=http://192.168.0.254/cgi-bin/rhel-5.5.sh
EOF
ln -s $OUTDIR/$KSFILE $OUTDIR/$1

3.7 产生个别IP所对应的PXE档桉

#chmod 755 mkpxe.sh
#./mkpxe.sh 192.168.0.101
# cat /tftpboot/pxelinux.cfg/C0A80065
DEFAULT 0
LABEL 0
kernel vmlinuz
append initrd=initrd.img noipv6 ks=http://192.168.0.254/cgi-bin/rhel-5.5.sh

3.8 建立kickstart cgi shell script (rhel-5.5.sh)

下面是笔者针对RHEL 5.5 Full Installation所撰写的CGI shell script(要置于/var/www/cgi-bin/目录)。
#vi /var/www/cgi-bin/rhel-5.5.sh
#!/bin/bash
HOSTNAME=`grep -B 2 $REMOTE_ADDR /etc/dhcpd.include.mtk | grep host | awk '{print $2}'`
echo "Content-Type: text/html; charset=ISO-8859-1"
echo
echo "text"
echo "key --skip"
echo "keyboard us"
echo "lang en_US"
echo "langsupport --default en_US en_US"
echo "network --device=eth0 --bootproto=static --ip=$REMOTE_ADDR --netmask=255.255.255.0 --gateway=192.168.0.254 --hostname=$HOSTNAME"
echo "url --url "
echo "bootloader --location=mbr --driveorder=sda"
echo "clearpart --all"
echo "part /boot --fstype ext3 --size=256"
echo "part pv.3 --size=61440 --grow"
echo "volgroup rootvg --pesize=32768 pv.3"
echo "logvol / --fstype ext3 --name=rootlv --vgname=rootvg --size=30720"
echo "logvol swap --fstype swap --name=swaplv --vgname=rootvg --size=2048"
echo "logvol /home --fstype ext3 --name=homelv --vgname=rootvg --size=1024"
echo "logvol /var/ftp/pub --fstype ext3 --name=publv --vgname=rootvg --size=10240"
echo "mouse genericps/2 --emulthree"
echo "timezone Asia/Taipei --utc"
echo "skipx"
echo "rootpw redhat"
echo "authconfig --useshadow --enablemd5"
echo "firewall --disabled"
echo "selinux --disabled"
echo "bootloader"
echo "reboot"
echo "%packages"
echo "'@Everything'"
echo "'-@Conflicts'"  RHEL 5.5 Full Installation时要额外加上此参数,不可以只写@Everything。
echo "%post"
echo "links --dump "

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wygfdp.html