使用本地光盘安装 PXE kickstart (自动化无人值守批量安装服务器)
好久没搞这个东西了,最近马上又要用得到,复习一下
完整的步骤记在这里,说明以后再加上
环境 Centos 6.5 ESXI 虚拟机
服务器端 安装dhcp tftp-server nfs 挂载光盘
yum install dhcp -y
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf
修改vim /etc/init.d/dhcpd
vim/etc/dhcp/dhcpd.conf #dhcpd.conf #SampleconfigurationfileforISCdhcpd #optiondefinitionscommontoallsupportednetworks... #Usethistoenble/disabledynamicdnsupdatesglobally. #ddns-update-stylenone; #IfthisDHCPserveristheofficialDHCPserverforthelocal #network,theauthoritativedirectiveshouldbeuncommented. #authoritative; #Usethistosenddhcplogmessagestoadifferentlogfile(youalso #havetohacksyslog.conftocompletetheredirection). log-facilitylocal7; #Aslightlydifferentconfigurationforaninternalsubnet. subnet192.167.1.0netmask255.255.255.0{ range192.167.1.122192.167.1.129; optiondomain-name-servers202.106.0.20,192.167.1.104; #optiondomain-name"internal.example.org"; optionrouters192.167.1.1; #optionbroadcast-address10.5.5.31; default-lease-time600; max-lease-time7200; next-server192.167.1.121; filename"pxelinux.0"; }
报错 &解决办法
=====================================================
yum install tftp-server -y
vim /etc/xinetd.d/tftp
yum install syslinux -y
[root@ccda yum.repos.d]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@ccda yum.repos.d]# cp /mnt/cdrom/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
[root@ccda yum.repos.d]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@ccda yum.repos.d]# cp /mnt/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@ccda yum.repos.d]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
[root@ccda yum.repos.d]# vim /var/lib/tftpboot/pxelinux.cfg/default
修改vim /var/lib/tftpboot/pxelinux.cfg/default
defaultlinux #prompt1 timeout600 displayboot.msg menutitleWelcometoCentOS6.5! labellinux menulabel^Installorupgradeanexistingsystem menudefault kernelvmlinuz appendinitrd=initrd.imgks=nfs:192.167.1.121:/ks/ks.cfg labelrescue menulabel^Rescueinstalledsystem kernelvmlinuz appendinitrd=initrd.imgrescue
[root@ccda yum.repos.d]# service xinetd restart
[root@ccda yum.repos.d]# service iptables stop
[root@ccda yum.repos.d]# yum install system-config-kickstart -y
[root@ccda yum.repos.d]# mkdir /ks
[root@ccda ~]# service nfs start
[root@ccda ~]# chkconfig nfs on
[root@ccda ~]# umount /dev/cdrom
[root@ccda ~]# mount /dev/cdrom /media/
至此kickstart 安装完毕,如果需要减轻服务器压力 可将NFS单独装一台机器分离出去
=====================================================
vim /ks/ks.cfg
#platform=x86,AMD64,或IntelEM64T #version=DEVEL #Firewallconfiguration firewall--enabled--http--ssh #InstallOSinsteadofupgrade install #UseNFSinstallationmedia nfs--server=192.167.1.121--dir=/media #Rootpassword rootpw--iscrypted$1$ZmGYyI0Q$MdJasSrD999guxiZq62mM. #Systemauthorizationinformation auth--useshadow--passalgo=sha512 #Usegraphicalinstall graphical firstboot--disable #Systemkeyboard keyboardus #Systemlanguage langen_US #SELinuxconfiguration selinux--enforcing #Installationlogginglevel logging--level=info #Rebootafterinstallation reboot #Systemtimezone timezoneAsia/Shanghai #Networkinformation network--bootproto=dhcp--device=eth0--onboot=on #Systembootloaderconfiguration bootloader--location=mbr #CleartheMasterBootRecord zerombr #Partitionclearinginformation clearpart--all--initlabel #Diskpartitioninginformation part/home--fstype="ext4"--size=10240 part/--fstype="ext4"--grow--size=80000 %post /sbin/chkconfig--level2345sshdon mkdir-p/etc/yum.repos.d/bak mv/etc/yum.repos.d/*.repo/etc/yum.repos.d/bak cat<<EOF>>/etc/yum.repos.d/work.repo [centos_6] name=sitvs baseurl=http://192.167.1.121/media #baseurl=http://10.10.6.52/yumdown/ enabled=1 gpgcheck=0 EOF FILE=/opt/ifcfg-eth0 IPADDR=`ifconfigeth0|grep"inetaddr"|awk'{print$2}'|awk-F:'{print$2}'` MAC=`grepHWADDR/etc/sysconfig/network-scripts/ifcfg-eth0` DEVICE=`grepDEVICE/etc/sysconfig/network-scripts/ifcfg-eth0` TYPE=`grepTYPE/etc/sysconfig/network-scripts/ifcfg-eth0` NETMASK=`ifconfigeth0|grep"inetaddr"|awk'{print$4}'|awk-F:'{print$2}'` # # echo"${DEVICE}">>${FILE} echo"BOOTPROTO=\"static\"">>${FILE} echo"${MAC}">>${FILE} echo"NM_CONTROLLED=\"yes\"">>${FILE} echo"ONBOOT=\"yes\"">>${FILE} echo"${TYPE}">>${FILE} echo"IPADDR=\"192.167.1.130\"">>${FILE} echo"NETMASK=\"${NETMASK}\"">>${FILE} echo"GATEWAY=\"192.167.1.254\"">>${FILE} echo"DNS1=\"192.167.1.104\"">>${FILE} echo"DNS2=\"202.106.0.20\"">>${FILE} # cat${FILE}>/etc/sysconfig/network-scripts/ifcfg-eth0 # /etc/init.d/networkrestart %end %packages @base @chinese-support @scalable-file-systems %end
说明
%post/sbin/chkconfig --level 2345 sshd on
mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat <<EOF>> /etc/yum.repos.d/work.repo[centos_6]
name=sitvs
baseurl=http://192.167.1.121/media
#baseurl=http://10.10.6.52/yumdown/
enabled=1
gpgcheck=0
EOF
FILE=/opt/ifcfg-eth0
IPADDR=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'`
MAC=`grep HWADDR /etc/sysconfig/network-scripts/ifcfg-eth0`
DEVICE=`grep DEVICE /etc/sysconfig/network-scripts/ifcfg-eth0`
TYPE=`grep TYPE /etc/sysconfig/network-scripts/ifcfg-eth0`
NETMASK=`ifconfig eth0 | grep "inet addr" | awk '{ print $4}' | awk -F: '{print $2}'`
#
#
echo "${DEVICE}" >> ${FILE}
echo "BOOTPROTO=\"static\"" >> ${FILE}
echo "${MAC}" >> ${FILE}
echo "NM_CONTROLLED=\"yes\"" >> ${FILE}
echo "ONBOOT=\"yes\"" >> ${FILE}
echo "${TYPE}" >> ${FILE}
echo "IPADDR=\"192.167.1.130\"" >> ${FILE}
echo "NETMASK=\"${NETMASK}\"" >> ${FILE}
echo "GATEWAY=\"192.167.1.254\"" >> ${FILE}
echo "DNS1=\"192.167.1.104\"" >> ${FILE}
echo "DNS2=\"202.106.0.20\"" >> ${FILE}
#
cat ${FILE} > /etc/sysconfig/network-scripts/ifcfg-eth0
#
/etc/init.d/network restart
%end
====
%post---->%end 此处是安装完成执行的脚本 (要直接把脚本写在这里,不要先编辑脚本再用sh 命令执行脚本) 红色部分是配置yum源 蓝色部分是截取自动获取的IP写到网卡配置文件里,即把服务器改成固定IP (可以加上ntpdate命令同步时间)
备注:如果不确定需要安装的软件包 可以查看你其他机器上的 /root/anaconda-ks.cfg 文件中末尾@打头的报名复制到ks文件 @packages--->@end 之间
===============
至此客户端就可以开机自动安装系统了(保证客户机可以获取到dhcp地址)
一直在学习。。。。
原文链接:https://www.f2er.com/centos/378160.html