网站配套学习视频请点击后方网址直接跳转https://edu.51cto.com/lecturer/14123887.html

我是ken,致力于开源技术

pxe+kickstart自动化批量安装系统详解-技术流ken

 

前言

pxe+kickstart是一款可以实现自动化批量安装系统的服务,比较经典,下面将详细介绍此服务的安装和使用。

 

系统环境准备

系统版本:CentOS release 6.7 (Final)

       内网IP:192.168.232.8/24    #用来对内通信,提供pxe+kickstart服务

       外网IP:10.220.5.166/24      #连接外网

 

关闭安全服务

[root@ken ~]# cat /etc/redhat-release     #检查系统版本
CentOS release 6.7 (Final)
[root@ken ~]# service iptables stop       #关闭防火墙
[root@ken ~]# setenforce 0                #关闭selinux

 

下载所需程序

[root@localhost ~]# yum install syslinux dhcp tftp-server xinetd httpd -y

 

 配置dhcp

[root@ken ~]# vim /etc/dhcp/dhcpd.conf 
subnet 192.168.232.0 netmask 255.255.255.0 {
  range 192.168.232.10 192.168.232.20;
  option domain-name-servers 8.8.8.8;
  option routers 192.168.232.8;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.232.8;
  filename "pxelinux.0";
}
[root@ken ~]# service dhcpd restart                     #重启dhcpd服务,使之配置生效
Starting dhcpd:                     [  OK  ]
 

 

配置tftp

[root@ken ~]# 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                     #把yes修改为no,即启动tftp服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
[root@ken ~]# service xinetd restart                     #重启xinetd,使之配置生效
Stopping xinetd:                                  [FAILED]
Starting xinetd:                                  [  OK  ]

[root@ken ~]# chkconfig xinetd on                        #把xinetd加入系统启动项,实现开机自动启动
[root@ken ~]# chkconfig --list | grep tftp               #检查确认tftp是否已经成功开启
    tftp:              on

 

复制开机文件到/var/lib/tftpboot

挂载光盘

[root@localhost ~]# mount /dev/cdrom /mnt

       进入到tftp的主目录下

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

复制images下的虚根文件及内核文件

[root@localhost tftpboot]# cp /mnt/images/pxeboot/vmlinuz ./
[root@localhost tftpboot]# cp /mnt/images/pxeboot/initrd.img ./

       复制isolinux下面开机所需的文件

[root@localhost tftpboot]# cp /mnt/isolinux/boot.msg ./
[root@localhost tftpboot]# cp /mnt/isolinux/vesamenu.c32 ./
[root@localhost tftpboot]# cp /mnt/isolinux/splash.jpg ./

       创建目录pxelinux.cfg

[root@localhost tftpboot]# mkdir pxelinux.cfg

       复制pxelinux.cfg到刚创建的目录之下并改名为default

[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# cp /mnt/isolinux/isolinux.cfg ./default

     配置default文件

default linux                                     #更改为linux
#prompt 1
timeout 10                                        #时间改短

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.7!
default linux
#prompt 1
timeout 10

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.7!
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 ks=http://192.168.232.8/ks/ks6.cfg   #指定ks文件位置
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 -

 

     复制syslinux提供的pxelinux.0文件到该目录下

[root@localhost pxelinux.cfg]# cd ..
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./

    查看该目录下文件,总共有7个文件和目录

[root@localhost tftpboot]# ls
boot.msg  initrd.img  pxelinux.0  pxelinux.cfg  splash.jpg  vesamenu.c32  vmlinuz
[root@localhost tftpboot]# ls |wc -l
7

 

把光盘挂载到httpd的网站根目录之下

[root@localhost tftpboot]# cd /var/www/html/
[root@localhost html]# mkdir installtree
[root@localhost html]# mount /dev/cdrom /var/www/html/installtree/

 

把ks文件复制到网站根目录之下

[root@localhost html]# mkdir ks
[root@localhost ks]# ls
 ks6.cfg
[root@localhost ks]# chmod +r ks6.cfg   #对ks文件添加读权限

 

 

配置ks文件


# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
url --url=http://192.168.232.8/installtree
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw  o                    #新装机密码为o
reboot
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
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
clearpart --all
zerombr
part /boot --fstype=ext4 --size=500
part pv.008002 --grow --size=1
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=2016 --maxsize=2016



repo --name="CentOS"  --baseurl=http://192.168.232.8/installtree  --cost=100

%packages
@core
@server-policy
@workstation-policy
%end

 

重启各项服务

[root@localhost ks]# service httpd restart
[root@localhost ks]# service xinetd restart
[root@localhost ks]# service dhcpd restart

 

开启新的虚拟机进行测试

    新的虚拟机需要和服务器在同一个虚拟网络。

 

   开始安装软件包  

安装完成

 

posted @ 2018-09-27 20:45  技术流ken  阅读(423)  评论(0编辑  收藏  举报