PXE自动化安装centos6和centos7

原文链接:https://blog.csdn.net/magerguo/article/details/81267330

PXE自动化安装centos6和centos7

PXE介绍

准备工作

关闭防火墙

关闭SELINUX

将做DHCP服务器的主机设置为静态IP

安装相关软件包

配置文件共享服务和yum源

启动httpd服务

制作centos7和centos6的yum源

制作centos6和centos7的kickstart文件

复制应答文件到共享目录下的ksdir目录下

编辑centos7的应答文件

编辑centos6的应答文件

检查应答文件格式

配置tftp服务

配置DHCP服务

制作PXE相关文件

制作启动菜单

系统安装

PXE介绍

PXE(Preboot Excution Environment): 预启动执行环境,Intel公司研发,基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统。 

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

PXE工作原理:

客户端向PXE服务器上的dhcp服务发送IP地址请求消息,dhcp服务检测客户端请求是否合法,主要是检测客户机的网卡MAC地址,如果合法则分配给客户端IP地址,同时将启动文件名pxelinux.0和启动文件位置信息一并传送给客户端。

客户端向PXE 服务器上的tftp服务发送获取启动文件pxelinux.0请求消息,tftp服务在接收到消息之后向客户端发送pxelinux.0大小信息,询问客户端是否同意使用,当tftp服务收到客户端发回的同意使用信息之后,正式向客户端发送pxelinux.0文件。

客户端执行接收到的pxelinux.0文件。

客户端向tftp服务器发送针对本机的配置信息文件(在tftp 服务器的pxelinux.cfg目录下),tftp服务器将配置文件发回客户端,继而客户端根据配置文件执行后续操作。

客户端向tftp服务器发送Linux内核请求信息,tftp服务器在接收到消息之后将内核文件发送给客户端

客户端向tftp服务器发送根文件请求信息,tftp服务器接收到消息之后返回Linux根文件系统给客户端。

客户端启动Linux内核

客户端下载安装源文件,读取自动化安装脚本

准备工作

准备一台主机作为网络环境内的dhcp服务器、tftp服务器、http服务器,在此主机上配置PXE环境,为网络中的其它主机提供自动化系统安装服务。

关闭防火墙

root&Centos7: ~#systemctl disable firewalld.service

#禁止防火墙开机自启动

root&Centos7: ~#systemctl stop firewalld.service

#关闭防火墙

root&Centos7: ~#iptables -vnL

关闭SELINUX

root&Centos7: ~#sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#禁用SElinux策略

root&Centos7: ~# grep SELINUX=disabled /etc/selinux/config

#确定SELINUX=disabled,已经将SElinux策略禁用

root&Centos7: ~#setenforce 0

#设置SELinux当前状态为Permissive

root&Centos7: ~# getenforce

#获取SELinux当前状态

将做DHCP服务器的主机设置为静态IP

root&Centos7: ~# nmcli connection show

#查看网卡名

NAME   UUID                                     TYPE             DEVICE

ens33  9611391a-9613-45dd-b981-9f1ad2ff05ba  802-3-ethernet  ens33

root&Centos7: ~#nmcli connection modify "ens33" ipv4.addresses 192.168.10.43/24 ipv4.gateway 192.168.10.1

#设置ens32网卡的IP地址为静态地址

安装相关软件包

root&Centos7: ~#yum install -y dhcp tftp-server httpd syslinux

#一次性安装完成dhcp tftp-server httpd syslinux四个软件包

配置文件共享服务和yum源

启动httpd服务

root&Centos7: ~#systemctl enable httpd.service

root&Centos7: ~#systemctl start httpd.service

root&Centos7: ~#ss -ntl |grep 80

制作centos7和centos6的yum源

root&Centos7: ~#mkdir -pv  /var/www/html/centos/{6,7}

root&Centos7: ~#mount /dev/sr0 /var/www/html/centos/6/

root&Centos7: ~#mount /dev/sr1 /var/www/html/centos/7/

root&Centos7: ~#ls /var/www/html/centos/{6,7}

制作centos6和centos7的kickstart文件

   生成kickstart文件的两种方法

1、修改anaconda.cfg文件,此文件会在每次装完系统后生成于/root/目录下.

2、使用system-config-kickstart命令生成.

复制应答文件到共享目录下的/ksdir/目录下

root&Centos7: ~#mkdir /var/www/html/ksdir/

root&Centos7: ~#cp -p /root/anaconda7-ks.cfg /var/www/html/ksdir/ks7-4.cfg

root&Centos7: ~#cp -p /root/anaconda6-ks.cfg /var/www/html/ksdir/ks6-8.cfg

root&Centos7: ~#ls /var/www/html/ksdir/

root&Centos7: ~#chmod +r /var/www/html/ksdir/*.cfg

#为应答文件增加读权限,此步骤很重要,请确保执行。

编辑centos7的应答文件

root&Centos7: ~#vim /var/www/html/ksdir/ks7-4.cfg

#version=DEVEL

# System authorization information

auth --enableshadow --passalgo=sha512

# Use CDROM installation media

cdrom

url --url=http://192.168.75.88/centos/7

# Use graphical install

graphical

#text

# Run the Setup Agent on first boot

firstboot --enable

ignoredisk --only-use=sda

# Keyboard layouts

keyboard 'us'


# System language

lang en_US.UTF-8


# Network information

network  --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate

network  --hostname=localhost.localdomain


# Root password

rootpw --iscrypted $6$rEuaZPdxUDJ1XoEg$b7RGDIloZUqok1A1a8WM60.2RosegHs4Vh8PtgCfobWkW74IaOtyVJGdFMSBL1z5Gzn4PSJA.6TusBXGlTjgm0

# System services

services --enabled="chronyd"

# System timezone

timezone Asia/Shanghai --isUtc --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org

# X Window System configuration information

# xconfig  --startxonboot

# System bootloader configuration

bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda

# Partition clearing information

#clearpart --none --initlabel

# Disk partitioning information

#part /home --fstype="xfs" --ondisk=sda --size=17408

#part /boot --fstype="xfs" --ondisk=sda --size=1024

#part swap --fstype="swap" --ondisk=sda --size=2049

#part / --fstype="xfs" --ondisk=sda --size=61437


%packages

@^gnome-desktop-environment

@base

@core

@desktop-debugging

@development

@dial-up

@directory-client

@fonts

@gnome-desktop

@guest-agents

@guest-desktop-agents

@input-methods

@internet-browser

@java-platform

@multimedia

@network-file-system-client

@networkmanager-submodules

@print-client

@security-tools

@x11

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


%post   #安装完成后要执行的脚本

systemctl enable autofs

rm -rf /etc/yum.repos.d/*

cat > /etc/yum.repos.d/base.repo <<eof

[base]

name=base

baseurl=file:///misc/cd

gpgcheck=0

eof

%end

编辑centos6的应答文件

root&Centos7: ~#vim /var/www/html/ksdir/ks6-8.cfg

# Kickstart file automatically generated by anaconda.

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard 'us'

# System authorization information

#auth --enableshadow --passalgo=sha512

# Use CDROM installation media

#cdrom

# Use network installation

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

# System language

lang en_US

# Firewall configuration

firewall --disabled

# Use graphical install

graphical

zerombr

# Run the Setup Agent on first boot

#firstboot --enable

#ignoredisk --only-use=sda

# SELinux configuration

selinux --disabled


# Network information

network  --onboot yes --device eth0 --bootproto dhcp --noipv6

network  --hostname=localhost.localdomain

# Root password

rootpw --iscrypted $6$rEuaZPdxUDJ1XoEg$b7RGDIloZUqok1A1a8WM60.2RosegHs4Vh8PtgCfobWkW74IaOtyVJGdFMSBL1z5Gzn4PSJA.6TusBXGlTjgm0

# System services

firewall --service=ssh

authconfig --enableshadow --passalgo=sha512

#selinux --enforcing

# System timezone

timezone Asia/Shanghai --isUtc

# X Window System configuration information

#xconfig  --startxonboot

# System bootloader configuration

bootloader --append=" crashkernel=auto" --location=mbr --driveorder=sda

# Partition clearing information

#clearpart --none --initlabel

# Disk partitioning information

#part /home --fstype="xfs" --ondisk=sda --size=2048

#part /boot --fstype="ext4" --ondisk=sda --size=1024

#part swap --fstype="swap" --ondisk=sda --size=2048

#part / --fstype="xfs" --ondisk=sda --size=4096


%packages

#@^minimal

@^gnome-desktop-environment

@base

@core

@desktop-debugging

@development

@dial-up

@directory-client

@fonts

#@gnome-desktop

#@guest-agents

#@guest-desktop-agents

@input-methods

@internet-browser

@java-platform

#@multimedia

@network-file-system-client

#@networkmanager-submodules

@print-client

@security-tools

@x11

kexec-tools

%end

检查应答文件格式

root&Centos7: ~#yum install system-config-kickstart -y

root&Centos7: ~#ksvalidator /var/www/html/ksdir/ks7-4.cfg

root&Centos7: ~#ksvalidator /var/www/html/ksdir/ks6-8.cfg

配置tftp服务

root&Centos7: ~#systemctl enable tftp.socket

root&Centos7: ~#systemctl start tftp.socket

root&Centos7: ~#ss -nul|grep 69

配置DHCP服务

默认dhcp配置文件内没有配置信息,可以使用配置示例文件将配置文件覆盖后进行修改,dhcp服务必须在更改配置文件后才能启动。dhcp配置文件必须要dhcp服务器所在网段的地址池。

root&Centos7: ~#cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

#制作配置文件

root&Centos7: ~#vim /etc/dhcp/dhcpd.conf

#编辑配置文件

# DHCP server to understand the network topology.

[root@localhost tftpboot]# cat /etc/dhcp/dhcpd.conf

#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.sample

#   see 'man 5 dhcpd.conf'

#

subnet 192.168.75.0 netmask 255.255.255.0 {

        option routers 192.168.75.254;         #设置网关

        option subnet-mask  255.255.255.0;     #设置地址段

        option time-offset -18000;

        range dynamic-bootp 192.168.75.100 192.168.75.200;  #设置地址池

        default-lease-time 21600;

        max-lease-time 43200;

        next-server 192.168.75.88;#提供引导文件的服务器ip网络安装操作系统

        filename "pxelinux.0";         #指明引导文件名称

}

[root@localhost tftpboot]#

root&Centos7: ~#systemctl enable dhcpd        #将dhcp服务设置为开机自启动

root&Centos7: ~#systemctl start dhcpd #启动dhcp服务

root&Centos7: ~#ss -nul|grep 67               #检查确认dhcp服务已经启动

制作PXE相关文件

root&Centos7: ~#mkdir /var/lib/tftpboot/pxelinux.cfg/

root&Centos7: ~#mkdir /var/lib/tftpboot/centos{6,7}

#cp /var/www/html/centos/7/isolinux/isolinux.msg /var/lib/tftpboot/pxelinux.cfg/default

root&Centos7: ~#cp /var/www/html/centos/7/isolinux/*.msg /var/lib/tftpboot/

root&Centos7: ~# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/

root&Centos7: ~#cp /var/www/html/centos/7/isolinux/vesamenu.c32 /var/lib/tftpboot/

root&Centos7: ~#cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/

root&Centos7: ~#cp /var/www/html/centos/7/images/pxeboot/{initrd.img,vmlinux}  /var/lib/tftpboot/

root&Centos7: ~#cp /var/www/html/centos/7/isolinux/{initrd.img,vmlinuz}  /var/lib/tftpboot/centos7

root&Centos7: ~#cp /var/www/html/centos/6/isolinux/{initrd.img,vmlinuz}  /var/lib/tftpboot/centos6

root&Centos7: ~#cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

root&Centos7: ~#tree /var/lib/tftpboot/

/var/lib/tftpboot/

├── boot.msg

├── centos6

│   ├── initrd.img

│   └── vmlinuz

├── centos7

│   ├── initrd.img  #伪文件系统文件

│   └── vmlinuz     #内核文件

├── initrd.img       #伪文件系统文件

├── menu.c32         #纯文本菜单 

├── pxelinux.0       #引导文件,相当于grub

├── pxelinux.cfg

│   └── default     #启动菜单文件

├── vesamenu.c32

└── vmlinuz


3 directories, 11 files

[root@localhost tftpboot]#

制作启动菜单

root&Centos7: ~#vim /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32

timeout 600

menu title CentOS Linux  PXE Install


label centos7     #自动安装centos7

      menu label Auto Install CentOS Linux ^7

      kernel centos7/vmlinuz

      append initrd=centos7/initrd.img ks=http://192.168.10.43/ksdir/ks7-1.cfg  #应答文件所在路径


label centos6      #自动安装centos6

      menu label Auto Install CentOS Linux ^6

      kernel centos6/vmlinuz

      append initrd=centos6/initrd.img ks=http://192.168.10.43/ksdir/ks6-1.cfg


label manual7     #手动安装centos7

      menu label ^Manual Install CentOS Linux 7

      kernel centos7/vmlinuz

      append initrd=centos7/initrd.img inst.repo=http://192.168.10.43/centos/7


label manual6      #手动安装centos6

      menu label Manual ^Install CentOS Linux 6

      kernel centos6/vmlinuz

      append initrd=centos6/initrd.img inst.repo=http://192.168.10.43/centos/6


label local     #本地硬盘启动

     menu default    #默认启动项

     menu label Boot from ^local drive

     localboot 0xffff

    menu end

系统安装

使用网络引导启动,下图是启动后的安装界面:选择Auto Install Centos Linux6

注意:使用虚拟机安装时,centos7内存要大于1024M,否则无法成功安装。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,367评论 6 512
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,959评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,750评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,226评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,252评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,975评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,592评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,497评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,027评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,147评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,274评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,953评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,623评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,143评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,260评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,607评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,271评论 2 358

推荐阅读更多精彩内容