最近公司里要搞自动安装,我就研究了pxe,也从网上参考了不少资料,这里做了一些简单的整理,文字表达功底比较有限,大家别拍砖啊,呵呵
准备:
1,在VMware中安装了一个CentOS63(CentOS6.4系统,IP : 192.168.202.131)
2,在VMware中创建了一个CentOS65(空机器,未装操作系统)
3,CentOS镜像文件挂载在CentOS63的/media/CentOS_6.4_Final位置
操作步骤:
一,配置DHCP
1,安装dhcpd
yum install dhcp
2,修改dhcp配置文件/etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.202.0 netmask 255.255.255.0 {
range 192.168.202.200 192.168.202.220;
option routers 192.168.202.131;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.202.131;
filename “pxelinux.0”;
}
3,启动dhcpd
chkconfig –add dhcpd
service dhcpd start
使用命令可以看到dhcpd绑定了多个端口
[root@localhost init.d]# netstat -anp | grep dhcpd
udp 0 0 0.0.0.0:67 0.0.0.0:* 3266/dhcpd
raw 0 0 0.0.0.0:1 0.0.0.0:* 7 3266/dhcpd
unix 2 [ ] DGRAM 18034 3266/dhcpd
注意:第2行raw表示绑定在ICMP协议上,协议号为1
二,配置TFTP
4,安装TFTP
yum install tftp-server
5,修改tftpd配置文件/etc/xinetd.d/tftp,ftp根目录为/var/lib/tftpboot
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
6,启动tftp服务(端口69)
/etc/init.d/xinetd restart
三,配置引导内核
7,下载pxe引导配置文件
yum install syslinux
cp `rpm -ql syslinux | grep ‘/pxelinux.0’` /var/lib/tftpboot
8,拷贝网络启动的内核文件
cp /media/CentOS_6.4_Final/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /media/CentOS_6.4_Final/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
修改default文件:
default linux
prompt 1
timeout 60
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.4!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append ks=http://192.168.202.131/ks.cfg initrd=initrd.img
四,配置kickstart
9,安装nginx,根目录/usr/local/nginx/html
yum install nginx
chkconfig –add nginx
service nginx start
10,拷贝操作系统源文件
mkdir /usr/local/nginx/html/dvd
cp -R /media/CentOS_6.4_Final/* /usr/local/nginx/html/dvd/
11,下载kickstart
yum install system-config-kickstart
cp /root/anaconda-ks.cfg /usr/local/nginx/html/ks.cfg
chmod 755 /usr/local/nginx/html/ks.cfg (不分配权限,外部无法通过http访问,会报403)
修改ks.cfg:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall –disabled
# Install OS instead of upgrade
install
# Use text install
text
# Use network installation
url –url=”http://192.168.202.131/dvd”
# Root password
rootpw –iscrypted $1$.IvWB.Gl$E4fI4Ez4Z8HyHRCZW5Btr0
# System authorization information
auth –useshadow –passalgo=sha512
# Run the Setup Agent on first boot
firstboot –reconfig
# System keyboard
keyboard us
# System language
lang zh_CN.UTF-8
# SELinux configuration
selinux –enforcing
# Installation logging level
logging –level=info
# System timezone
timezone Asia/Shanghai
# Network information
network –bootproto=dhcp –device=eth0 –onboot=yes
# System bootloader configuration
bootloader –location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart –all
# Disk partitioning information
part /boot –fstype=”ext4″ –size=200
part swap –fstype=”swap” –size=1000
part / –fstype=”ext4″ –grow –size=1
# Reboot after installation
reboot
%packages
@base
@core
gcc
%end
五,验证
12,修改CentOS65虚拟配置文件CentOS65.vmx,增加一行bios.bootDelay= “10000”,即表示在启动bios的时候停留10秒(否则你根本来不及按任何键的)
给CentOS65加电(打开Power),按Esc选择从Network启动
Good luck!!!!