Linux下部署PXE结合DHCP、tftp、http服务完成全自动安装centos7

DHCP配置文件

/etc/dhcp/dhcpd.conf

其它配置选项

  • filename: 指明引导文件名称
  • next-server:提供引导文件的服务器IP地址

示例:

  • filename "pxelinux.0"; 引导系统启动文件
  • next-server 192.168.100.100;

检查语法

  • service dhcpd configtest centos6系统

使用DHCP配合网络完成自动安装系统

————————————————————————————————

host passacaglia {

hardware ethernet 0:0:c0:5d:bd:95;

filename "vmunix.passacaglia";

server-name "toccata.fugue.com";

}原配置文件

————————————————————————————————

host passacaglia {

hardware ethernet 0:0:c0:5d:bd:95;

filename "pxelinux.0";

server-name "tftp服务器中的地址";

} #####修改后的文件

————————————————————————————————

PXE介绍

Preboot Excution Environment 预启动执行环境

Intel公司研发

基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统

PXE可以引导和安装Windows,linux等多种操作系统

DHCP工作原理

PXE工作原理

1、Client向PXE Server上的DHCP发送IP地址请求消息, DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client

2、Client向PXE Server上的TFTP发送获取pxelinux.0请求消息, TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0

3、Client执行接收到的pxelinux.0文件

4、Client向TFTP Server发送针对本机的配置信息文件(在TFTP 服务的pxelinux.cfg目录下),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。

5、Client向TFTP发送Linux内核请求信息, TFTP接收到消息之后将内核文件发送给Client

6、Client向TFTP发送根文件请求信息, TFTP接收到消息之后返回Linux根文件系统

7、Client启动Linux内核

8、Client下载安装源文件,读取自动化安装脚本

PXE自动化安装CentOS 6

1、安装前准备:关闭防火墙和SELINUX, DHCP服务器静态IP

[root@localhost ~]# service iptables stop
[root@localhost ~]# vim /etc/selinux/config | disabled

2、安装软件包

yum install httpd tftp-server dhcp  syslinux

3、配置文件共享服务:

systemctl enable httpd
systemctl start httpd
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7

4、准备kickstart文件

/var/www/html/ks/centos7.cfg         注意:权限

5、配置tftp服务

systemctl enable tftp.socket
systemctl start tftp.socket

6、配置DHCP服务

vim /etc/dhcp/dhcpd.conf
option domain-name "example.com";
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.1 192.168.100.200;
filename "pxelinux.0";
next-server 192.168.100.100;
}
systemctl enable dhcpd
systemctl start dhcpd

PXE自动化安装CentOS 6

1、安装前准备:关闭防火墙和SELINUX, DHCP服务器静态IP

[root@localhost ~]# service iptables stop
[root@localhost ~]# vim /etc/selinux/config | disabled


第二步:

[root@localhost ~]# yum install dhcp tfrp-server httpd syslinux

第三步:

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# mkdir centos/6-pv

第四步:

[root@localhost html]# mount /dev/sr0 /var/www/html/centos/6/

第五步:

[root@localhost html]#mkdir ks

cp之前做好的应答文件 ks_centos6.cfg

注意:如果应答文件使用是在本机作为服务,需要写本机的url路径;

url --url=http://192.168.161.128/centos/6

第六步:配置dhcp服务

[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf   ###拷贝dhcp中的配置文件



subnet 192.168.161.0 netmask 255.255.255.0 {
range 192.168.161.10 192.168.161.100;
next-server 192.168.161.128;		
filename "pxelinux.0"			tftp服务器工作目录中需要的pxelinux.0是引导系统启动用的文件
option routers 192.168.161.253;
}

第七步:启动dhcp服服务器

[root@localhost dhcp]# service dhcpd start
Starting dhcpd:                                            [  OK  ]
[root@localhost cd]# service dhcpd status
dhcpd (pid  3822) is running...

第八步:准备tftp服务器列表中的启动引导文件

[root@localhost ~]# cd /var/lib/tftpboot/

第九步:安装syslinux 包

[root@localhost ~]# yum install syslinux
[root@localhost ~]# yum install syslinux-nonlinux
[root@localhost ~]#cd /var/lib/tftpboot
[root@localhost tftpboot]# rpm -ql syslinux-nonlinux	
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot	###引导文件
[root@localhost tftpboot]# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot	###引导菜单
[root@localhost tftpboot]# cp  /misc/cd/isolinux/{initrd.img,vmlinuz} .        	###拷贝光盘中的内核文件
[root@localhost tftpboot]# vim pxelinux.cfg/default 			                ###修改引导菜单文件
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 Auto Install ^Mini centos 6 system
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.161.128/ks/ks_centos6.cfg
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu default
  menu label Boot from ^local drive
  localboot 0xffff

第九步:重启客户机选择网络引导启动

*************************************安装完成*******************************

猜你喜欢

转载自blog.csdn.net/weixin_42741132/article/details/82953709
今日推荐