PXE之Centos系统安装

PXE

PXE介绍
Preboot Excution Environment 预启动执行环境
Intel 公司研发
基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统
PXE可以引导和安装Windows,linux等多种操作系统
PXE工作原理
Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC地址),如果合法则返回Client的IP地址,同时将启动文件pxelinux.0的位置信息一并传送给Client
Client向PXE Server上的TFTP发送获取pxelinux.0请求消息,TFTP接收到消息之后再向Client发送pxelinux.0大小信息,试探Client是否满意,当TFTP收到Client发回的同意大小信息之后,正式向Client发送pxelinux.0
Client执行接收到的pxelinux.0文件
Client向TFTP Server发送针对本机的配置信息文件(在TFTP 服务的pxelinux.cfg目录下),TFTP将配置文件发回Client,继而Client根据配置文件执行后续操作。
Client向TFTP发送Linux内核请求信息,TFTP接收到消息之后将内核文件发送给Client
Client向TFTP发送根文件请求信息,TFTP接收到消息之后返回Linux根文件系统
Client启动Linux内核
Client下载安装源文件,读取自动化安装脚本
PXE自动化安装CentOS 7
1.关闭防火墙和SElinux
# systemctl stop firewalld.service
# setenforce 0
SELinux 配置文件:
vim /etc/sysconfig/selinux
SELINUX=disabled
2.安装程序包(tftp-server,http,dhcp,syslinux),启动服务并设置为开机自启动
# yum install dhcp tftp-server syslinux http
# systemctl enable dhcpd tftp httpd
# systemctl start httpd tftp.socket
# rpm -ql dhcp 查看配置文件: /etc/dhcp/dhcpd.conf
# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
# vim /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.254; #指定网关
option domain-name-servers 223.5.5.5, 114.114.114.114; #指定域名服务器
next-server 192.168.1.5; #指定获取系统引导文件的服务器IP(tftp)
filename “pxelinux.0”; #引导文件名称
}
补充:dhcpd服务需要修改配置文件才可启动
# systemctl start dhcpd
# ss -tunlp 来查看对应的服务端口是否打开(dhcpd:67(dhclient: 68) tftp:69 httpd:80)
3.创建光盘挂载点和ks文件目录
# mkdir /var/www/html/centos/{6,7} -pv
# mkdir /var/www/html/ksdir/{6,7} -pv
# vim /etc/fstab
/dev/sr0 /var/www/html/centos/6/ iso9660 defaults 0 0 (Centos7光盘)
/dev/sr1 /var/www/html/centos/7/ iso9660 defaults 0 0 (Centos6光盘)
# mount -a
# df -h 查看是否挂载成功
# cat /var/www/html/ksdir/6/ks_centos6.cfg(chmod +r ks_centos6.cfg)
ks_centos6.cfg(Mini)
*****************************************************************************************************
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
url –url=http://192.168.1.5/centos/6
lang en_US.UTF-8
keyboard us
network –onboot yes –device eth0 –bootproto dhcp –noipv6 –nameserver 8.8.8.8 –hostname centos6.localdomain
rootpw –iscrypted $6$NjFYm33MgYv/N9I6$wqynBfE5UfImxskNKNSII0jdo/1pp8BxMrO2cwZJxfJUbheSNdvAqgOpaJegzO.SRvACIswIHsWw4FAzD92RY0
firewall –disabled
authconfig –enableshadow –passalgo=sha512
selinux –disabled
timezone Asia/Shanghai
bootloader –location=mbr –driveorder=sda –append=”crashkernel=auto rhgb quiet”
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
zerombr
clearpart –all
part /boot –fstype=ext4 –size=500
part / –fstype=ext4 –size=20000
part /data –fstype=ext4 –size=20000
part swap –size=2048
reboot
%packages
@core
@server-policy
@workstation-policy
%end
******************************************************************************************************
# cat /var/www/html/ksdir/7/ks_centos7.cfg(chmod +r ks_centos7.cfg)
ks_centos7.cfg(Mini)
******************************************************************************************************
#version=DEVEL
# System authorization information
auth –enableshadow –passalgo=sha512
# Use CDROM installation media
url –url=http://192.168.1.5:/centos/7
# Use graphical install
text
# Run the Setup Agent on first boot
firstboot –enable
ignoredisk –only-use=sda
# Keyboard layouts
keyboard –vckeymap=us –xlayouts=’us’
# System language
lang en_US.UTF-8
selinux –disabled
firewall –disabled
# Network information
network –bootproto=dhcp –device=ens33 –onboot=on –ipv6=auto –activate
network –hostname=centos7.localdomain
# Root password
rootpw –iscrypted $6$gBxf9D1qFAeD4TiK$rAZGNzOE3TFWE7x.dPk6zmwGT4QzGko9QdIK4cofzhTvAIAeqxcJYCL7d8JAHWQYkUQ57R/iiJoTIXHugOZYy0
# System services
services –disabled=”chronyd”
# System timezone
timezone Asia/Shanghai –isUtc –nontp
# System bootloader configuration
bootloader –append=” crashkernel=auto” –location=mbr –boot-drive=sda
autopart –type=lvm
# Partition clearing information
zerombr
clearpart –all
reboot
%packages
@^minimal
@core
kexec-tools
%end
%addon com_redhat_kdump –enable –reserve-mb=’auto’
%end
%anaconda
pwpolicy root –minlen=6 –minquality=1 –notstrict –nochanges –notempty
pwpolicy user –minlen=6 –minquality=1 –notstrict –nochanges –emptyok
pwpolicy luks –minlen=6 –minquality=1 –notstrict –nochanges –notempty
%end
******************************************************************************************************
4.tftp服务器分别创建centos6和centos7文件夹,并复制系统引导文件至tftp服务器
# mkdir /var/lib/tftpboot/centos{6,7}
# cp /var/www/html/centos/7/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos7
# cp /var/www/html/centos/6/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/centos6
5.创建pxelinux.cfg文件夹,复制syslinux 软件包中的pxelinux.0 引导文件和菜单背景图片
# mkdir /var/lib/tftpboot/pxelinux.cfg
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
# cp /var/www/html/centos/6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
# cat /var/lib/tftpboot/pxelinux.cfg/default
*************************************************************************************
default menu.c32
#prompt 1
timeout 600
menu title Welcome to Install CentOS System!
label Centos6_mini
menu label ^Install Centos ^6 Mini System
kernel centos6/vmlinuz 注意此处与下处的路径(相对于pxelinux.cfg文件夹所在的路径)
append initrd=centos6/initrd.img ks=http://192.168.1.5/ksdir/6/ks_centos6.cfg
label Centos7_mini
menu label Install Centos ^7 Mini System
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.1.5/ksdir/7/ks_centos7.cfg
label local
menu label Boot from ^local drive
localboot 0xffff
menu end
**************************************************************************************
6.创建新的虚拟机并通过网卡来引导系统

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/99599

发表评论

登录后才能评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1823388528@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班