基于pxe+dhcp+ks实现自动安装系统

一、准备工作
1.添加一个网卡
2 .给这个新网卡配置IP 192.168.100.85/24
3. 修改新网卡的网络连接方式为vmnet3

[[email protected] ~]# mount /dev/cdrom /mnt/
[[email protected] ~]# service iptables stop
[[email protected] ~]# setenforce 0

说明:本机第一个网卡地址为10.220.5.116

二、安装配置dhcp
1.安装dhcp

[[email protected] ~]# yum install dhcp dhcp-common

2.配置DHCP(虚拟网络vmnet)

[[email protected] ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[[email protected] ~]# cd /etc/dhcp/
[[email protected] dhcp]# cp dhcpd.conf{,.bak}
[[email protected] dhcp]# vim dhcpd.conf
			【只需要如下内容,其他的都可以删除】
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.200 192.168.100.220;
    option routers 192.168.100.85;
    option domain-name-servers 8.8.8.8;
	}

3.启动dhcp

[[email protected] ~]# service dhcpd restart
[[email protected] dhcp]# service dhcpd status
[[email protected] dhcp]# ss -unl

4.测试dhcp功能
新开一台虚拟机网络连接模式设置为vmnet3,网卡配置文件如下图
基于pxe+dhcp+ks实现自动安装系统
重启网络,执行 ifconfig

# service network restart
#ifconfig

基于pxe+dhcp+ks实现自动安装系统
这里看到这个主机的地址是 dhcp服务器从地址池中拿到的地址分配给了这台客户端的,说明dhcp配置成功。

三、配置tftp功能
1.安装tftp服务

[[email protected] ~]# yum install tftp tftp-server xinetd -y

2.启动

[[email protected] ~]# service xinetd restart
[[email protected] ~]# chkconfig xinetd on
[[email protected] ~]# chkconfig tftp on
[[email protected] ~]# chkconfig --list | grep tftp
		tftp:          	on

3.测试
基于pxe+dhcp+ks实现自动安装系统
这里我们可以看到能够通过tftp将/var/lib/tftpboot/ 的文件下载到/tmp下说明tftp配置成功。

四、准备pxe需要的相关文件
1.准备内核文件

[[email protected] ~]# cp /mnt/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

2.准备界面相关文件

[[email protected] ~]# cp /mnt/isolinux/{boot.msg,splash.jpg,vesamenu.c32} /var/lib/tftpboot/

3.准备bootloader

[[email protected] ~]# yum install syslinux -y
[[email protected] ~]# ls /usr/share/syslinux/pxelinux.0 
[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

4.准备配置文件

[[email protected] ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[[email protected] ~]# cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

五、修改dhcp配置文件,实现告知客户端tftp的地址信息

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.200 192.168.100.220;
    option routers 192.168.100.85;
    option domain-name-servers 8.8.8.8;
    next-server 192.168.100.85;
    filename "pxelinux.0";
        }

六、重启所有服务

[[email protected] ~]# service xinetd restart
[[email protected] ~]# service dhcpd restart

七、准备安装树

[[email protected] ~]# yum install httpd -y
[[email protected] ~]# mkdir /var/www/html/installtree/	
[[email protected] ~]# mount /dev/cdrom /var/www/html/installtree/
[[email protected] ~]# service httpd restart

通过浏览器测试一下,如下图显示说明安装树配置成功
基于pxe+dhcp+ks实现自动安装系统

八、准备kickstart文件

[[email protected] ~]# cd /var/www/html
[[email protected] ~]# mkdir ks

ks1.cfg文件放在/var/www/html/ks 下

[[email protected] html]# chmod -R +r ks
[[email protected] html]# chmod +x ks

九、修改/var/lib/tftpboot/pxelinux.cfg/default文件

[[email protected] ~]# vim /var/lib/tftpboot/pxelinux.cfg/default

基于pxe+dhcp+ks实现自动安装系统
十、启动一个虚拟机,来测试pxe是否正常