实现PXE自动安装系统

PXE:

PrebootExcutionEnvironment 预启动执行环境
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下载安装源文件,读取自动化安装脚本

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

安装软件包
httpd tftp-server dhcp syslinux system-config-kickstart
搭建dhcp环境:
1:添加一块网卡,使服务主机和次要主机(要被装系统的机器)在一个网段中

image

2:设置固定Ip

image

3:搭建dhcp服务器

image

[ root@localhost ~ ]# yum -y install dhcp
[ root@localhost ~ ]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
subnet 192.168.11.0 netmask 255.255.255.0 {
#192.168.11.0是网段,后面255.255.255.0是网关
                range 192.168.11.40 192.168.11.200;
                #允许同网段机器使用dhcp获取的Ip范围
                filename "pxelinux.0";
                #引导文件名称
                next-server 192.168.11.12;
                #引导文件的服务器地址Ip
}
[ root@localhost ~ ]#service  dhcpd start
#开启dhcp服务
[ root@localhost ~ ]#chkconfig dhcpd on
#设置dhcp开机启动
4:安装tftp

image

[ root@localhost ~ ]#yum -y install tftp
[ root@localhost ~ ]#vim /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
}
//修改上内容中的disable的yes改为No,表示开机启动
[ root@localhost ~ ]# sservice xinetd start
//启动xinetd
xinetd小介绍:
xinetd是超级守护进程,管理众多的进程,比如telnet服务。xinetd自己是一个sysv,它就像老板一样,自己常驻于内存,管理其它的进程,其它进程就相当于它的员工,在其它进程没有用时会睡眠,并不占用系统资源,当有工作时候老板xinetd会通知它的员工,唤醒某个进程来执行作业。这种方式适合于那些不是经常被人使用,不需要常驻内存的程序,但是此方式响应时间长,但是节省系统资源,方便管理。超级守护进程的配置文件是/etc/xinetd.conf,超级守护进程的子进程们存放在/etc/xinetd.d/目录下   
5:安装httpd服务,并搭建yum仓库到dhcp服务器,这里使用挂载光盘,当然也可以拷贝光盘中的数据

image

[ root@localhost ~ ]#yum -y install httpd
#安装httpd服务
[ root@localhost ~ ]#chkconfig httpd on
#开机启动httpd服务
[ root@localhost ~ ]#mount /dev/sr0  /var/www/html/centos6
#挂载光盘到centos6目录下(临时的yum仓库)
6:编写ks6.cfg文件,注意配置文件如果写错会导致系统无法安装的

image

[ root@localhost /var/www/html/ksdir ]#cat ks6.cfg 
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url=http://192.168.11.12/centos6/
#安装源
reboot
#安装后重启
zerombr
#清除mrb表
text
#字符界面安装
lang en_US.UTF-8
#语言
keyboard us
#键盘布局
network --onboot yes --device eth0 --bootproto dhcp --noipv6
#网络设置,默认dhcp获取
rootpw  --iscrypted $6$jxJPuR6OAo4mlJ0k$.L0GK24v5MchJX0c8k.jxIwOb7uDMegnNhYYrGh5Umf0FY.wVVR9f6lAgfokK/eFllDIR/ZTlsYiqN9taAatQ1
#root密码,已经加密
firewall --service=ssh
#防火墙
authconfig --enableshadow --passalgo=sha512
#身份验证
selinux --enforcing
#禁用selinux
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
clearpart --all
#清理分区表

part /boot --fstype=ext4 --size=1000
part / --fstype=ext4 --size=50000
part /software --fstype=ext4 --size=10000
part swap --size=2048
#以上四项磁盘分区



%packages
@core
@server-policy
@workstation-policy
%end
#一些包和软件
7:准备相关文件(内核,菜单。。。等等)复制到tftp目录下(/var/lib/tftpboot)

image

[ root@localhost ~ ]#yum -y install syslinux
#syslinux存放各种系统文件,因为需要用到syslinux包中的pxelinux.0文件
[ root@localhost /var/www/html/centos6/isolinux ]#cp initrd.img  vmlinuz  vesamenu.c32 /var/lib/tftpboot/
#initrd.img=伪文件系统 vmlinuz=内核   vesamenu.c32=菜单文件   
[ root@localhost /var/lib/tftpboot ]#cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/
#引导需要pxelinux.0
[ root@localhost /var/lib/tftpboot ]#mkdir pxelinux.cfg
[ root@localhost /var/lib/tftpboot ]#cp /var/www/html/centos6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
8:修改菜单文件default

image

[ root@localhost /var/lib/tftpboot/pxelinux.cfg ]#vim default 
default vesamenu.c32
#prompt 1
timeout 600


menu title Welcome to CentOS 6.9!

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append initrd=initrd.img  ks=http://192.168.11.12/ksdir/ks6.cfg
label local
  menu label Boot from ^local drive
  localboot 0xffff
  #这里我就简单改下了。
9:效果图

image

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值