pxe 配合kickstart安装centos

1.简介

1.1 pxe简介

严格的说,PXE并不是一种安装方式,而是一种引导方式,。进行PXE安装的必要条件是要安装的计算机中包含一个PXE支持的网卡(NIC)。
PXE(Pre-boot Execution Environment)协议使计算机可以通过网络启动。
协议分为client和server端,PXE client在网卡的ROM中,当计算机引导时,BIOS把PXE client调入内存执行,由PXE client将放置在远端的文件通过网络下载到本地运行。
运行PXE协议需要设置DHCP服务器和TFTP服务器。
DHCP服务器用来给PXE client(将要安装系统的主机)分配一个IP地址,由于是给PXE client分配IP地址,所以在配置DHCP服务器时需要增加相应的PXE设置。
在PXE client的ROM中,已经存在了TFTP Client。PXE Client通过TFTP协议到Server上下载所需要的文件。
故要配置kickstart需要先配置DHCP服务 、TFTP服务和web服务。

1.2 kickstart

kickstart是一种无人值守安装方式。
Kickstart的工作原理是通过记录典型的安装过程中所需要人工干预填写的各种参数,并生成一个名为ks.cfg的文件;当出现要求填写参数的情况时,安装程序会首先查找Kickstart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。

2 安装前确认环境

  • 确认linux的版本
  • 关闭selinux,否则报错
  • 关闭防火墙,确保三个服务都能访问通
cat /etc/redhat-release  
setenforce 0
service iptables stop 
#确认系统版本
cat /etc/redhat-release  
#临时关闭selinux
setenforce 0
#关闭防火墙
service iptables stop 

3 安装并且配置服务器

3.1配置web服务器提供镜像盘信息

将光盘文件挂载到指定目录,软连接到httpd的网络根目录

ll /dev/cdrom
mkdir /mnt/cdrom #创建挂载目录
mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom/ #挂载
ll /mnt/cdrom/  查看挂载效果
yum install httpd -y;#安装httpd服务
service httpd start;#启动httpd服务
#进入httpd目录创建挂载点的软连接
cd /var/www/html/ 
ln -s /mnt/cdrom centos

3.2配置TFTP服务器

 yum -y install tftp-server
  cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
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
}
/etc/init.d/xinetd start
#安装tftp服务器
 yum -y install tftp-server
#修改tftp配置 
cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no  #将yes改为no,表示开启tftp服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
#启动tftp服务
/etc/init.d/xinetd start

3.3配置支持PXE的启动程序

syslinux是一个功能强大的引导加载程序,而且兼容各种介质。目的是简化首次安装Linux的时间并建立修护或其它特殊用途的启动盘。

yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
#安装引导程序
yum -y install syslinux
#将预装文件拷贝到tftp中。
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
#复制启动菜单,其中centos是你自己软连的挂载目录
cp -a /var/www/html/centos/isolinux/* /var/lib/tftpboot/
# 新建一个pxelinux.cfg目录,存放客户端的配置文件。
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
# 查看默认配置
cat /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.10!
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 initrd=initrd.img
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img nomodeset
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel memtest
  append -

3.4安装配置DHCP服务器

确保每一个需要通过预执行环境安装系统的机器能够获取局域网内独立ip地址

yum -y install dhcp
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet 192.168.1.0 netmask 255.255.255.0 {
        range 192.168.1.200 192.168.1.250;
        option subnet-mask 255.255.255.0;
        default-lease-time 21600;
        max-lease-time 43200;
        next-server 192.168.1.159; 
        filename "/pxelinux.0";
}
EOF
/etc/init.d/dhcpd start

cat /etc/sysconfig/dhcpd
# 指定监听网卡
DHCPDARGS=eth0

/etc/init.d/dhcpd restart
#按装dhcp
yum -y install dhcp
#配置dhcp分配的ip地址,并且设置tftp服务器
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet 192.168.1.0 netmask 255.255.255.0 {
        range 192.168.1.230 192.168.1.250; #ip地址的网段
        option subnet-mask 255.255.255.0; 
        default-lease-time 21600;
        max-lease-time 43200;
        next-server 192.168.1.159;#配置TFTP服务器地址
        filename "/pxelinux.0";
}
EOF
#启动dhcp服务
/etc/init.d/dhcpd start
#查看网卡信息
cat /etc/sysconfig/dhcpd
# 指定监听网卡
DHCPDARGS=eth0
#重启dhcp服务
/etc/init.d/dhcpd restart

到目前为止已经可以完成pxe,进行系统安装了。安装的时候需要注意的几个点。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.5 根据首次安装文件完成无人值守安装

简化后的default文件指明无人值守的配置文件和监听的端口

cat /var/lib/tftpboot/pxelinux.cfg/default
default ks
prompt 0
label ks
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.1.159/ks_config/ks.cfg ksdevice=eth1

自动值守的配置文件

cat /var/www/html/ks_config/ks.cfg
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url=http://192.168.1.159/centos
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$Y0Aw2t2J.jVi615h$wIPES1UeIqvgiy/C5pa5P9pnu3Gwp7LMjqn.bf.cdvnixATD0JY79bQyu5JRoAq4YQfnH33llO2DZoIjHGnO..
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
reboot
timezone --utc 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
#volgroup VolGroup --pesize=4096 pv.008002
#logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=VolGroup --grow --size=1984 --maxsize=1984
zerombr yes 
clearpart --all --initlabel
autopart 
ignoredisk --only-use=sda 
#part /boot --fstype=ext4 --size=500
#part pv.008002 --grow --size=1
repo --name="CentOS"  --baseurl=http://192.168.1.159/centos --cost=100
%packages
@core
@server-policy
@workstation-policy
%end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值