使用本地光盘安装 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 # Sample configuration file for ISC dhcpd # option definitions common to all supported networks... # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # A slightly different configuration for an internal subnet. subnet 192.167.1.0 netmask 255.255.255.0 { range 192.167.1.122 192.167.1.129; option domain-name-servers 202.106.0.20,192.167.1.104; # option domain-name "internal.example.org"; option routers 192.167.1.1; # option broadcast-address 10.5.5.31; default-lease-time 600; max-lease-time 7200; next-server 192.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
default linux #prompt 1 timeout 600 display boot.msg menu title Welcome to CentOS 6.5! label linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img ks=nfs:192.167.1.121:/ks/ks.cfg label rescue menu label ^Rescue installed system kernel vmlinuz append initrd=initrd.img rescue
[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/
选择--> 保存文件到 /ks 目录 名称为ks.cfg
至此kickstart 安装完毕,如果需要减轻服务器压力 可将NFS单独装一台机器分离出去
=====================================================
我生成的ks文件
vim /ks/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Firewall configuration firewall --enabled --http --ssh # Install OS instead of upgrade install # Use NFS installation media nfs --server=192.167.1.121 --dir=/media # Root password rootpw --iscrypted $1$ZmGYyI0Q$MdJasSrD999guxiZq62mM. # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --enforcing # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone Asia/Shanghai # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /home --fstype="ext4" --size=10240 part / --fstype="ext4" --grow --size=80000 %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 %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%end
====
%post---->%end 此处是安装完成执行的脚本 (要直接把脚本写在这里,不要先编辑脚本再用sh 命令执行脚本) 红色部分是配置yum源 蓝色部分是截取自动获取的IP写到网卡配置文件里,即把服务器改成固定IP (可以加上ntpdate命令同步时间)
备注:如果不确定需要安装的软件包 可以查看你其他机器上的 /root/anaconda-ks.cfg 文件中末尾@打头的报名复制到ks文件 @packages--->@end 之间
===============
至此客户端就可以开机自动安装系统了(保证客户机可以获取到dhcp地址)
一直在学习。。。。
本文出自 “坚持。。。” 博客,请务必保留此出处http://qchanblog.blog.51cto.com/9686614/1911674
原文地址:http://qchanblog.blog.51cto.com/9686614/1911674