whechuan00 2014-07-30
1、安装DHCP TFTP
yum -y install dhcp tftp-server tftp
--------------------------------------------------------------------------------
2、配置DHCP文件
cat > /etc/dhcp/dhcpd.conf << EOF
#
option domain-name "dwhd.org";
#设置DHCP的DNS
option domain-name-servers 172.16.0.1,114.114.114.114;
#设置DHCP 分配出去的IP超时时间 单位秒
default-lease-time 86440;
#设置DHCPlease-time时间 单位秒
max-lease-time 100000;
log-facility local7;
#设置DHCP的 IP 和掩码
subnet 192.168.1.0 netmask 255.255.255.0 {
#设置DHCP对外分配IP段
range 192.168.1.50 192.168.1.70;
#设置路由IP
option routers 192.168.1.1;
#下面的4行是根据mac分配指定IP
host CentOS7 {
hardware ethernet 00:0c:29:ba:3c:76;
fixed-address 192.168.1.65;
}
#如果是PXE网卡来获取到了IP 告诉网卡下一步联系的服务器IP 192.168.1.120
next-server 192.168.1.120;
#PXE网卡联系了服务器之后告诉它应该去获取文件pxelinux.0
filename "pxelinux.0";
}
EOF
--------------------------------------------------------------------------------
3、检测dhcp配置和启动dhcp
[root@localhost pxelinux.cfg]# service dhcpd configtest
Syntax: OK
#检测dhcp配置,如果出现Syntax: OK则说明配置OK了
#启动DHCP服务
service dhcpd start
--------------------------------------------------------------------------------
4、设置TFTP开机启动
chkconfig tftp on[/bash]
[bash highlight="9,10"][root@localhost ~]# netstat -unl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:1005 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 0.0.0.0:776 0.0.0.0:*
udp 0 0 0.0.0.0:48819 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 0.0.0.0:69 0.0.0.0:*
udp 0 0 :::1005 :::*
udp 0 0 :::111 :::*
udp 0 0 :::42066 :::*
##看看 67 69端口是否被监听了,如果是的就说明好了
--------------------------------------------------------------------------------
开始为PXE启动做准备,由于我在当前Windows物理机上架设了FTP服务,所以我这里就直接用FTP服务器做源了
5、下载必要的文件到TFTP目录
ftpurl="ftp://lookback:[email protected]/centos/6/x86_64/base/"
tftpdir="/var/lib/tftpboot/"
for I in vmlinuz initrd.img; do wget -O ${tftpdir}$I ${ftpurl}images/pxeboot/$I;done
for II in splash.jpg vesamenu.c32 boot.msg isolinux.cfg; do
[ "$II" == "isolinux.cfg" ] && wget -O ${tftpdir}default ${ftpurl}/isolinux/$II
wget -O ${tftpdir}$II ${ftpurl}/isolinux/$II
done
#安装syslinux
yum -y install syslinux
#复制pxelinux.0到TFTP目录下
cp $(rpm -ql syslinux | grep '\bpxelinux.0') /var/lib/tftpboot/
#最后核对下文件
tree /var/lib/tftpboot/ #结果和下图一样就对了