在Centos6/7上实现PXE自动化安装Centos6/7

Centos6上实现PXE自动化安装Centos6

一、1.安装相关包

yum install dhcp tftp-server httpd syslinux-nonlinux

设置为开机启动

chkconfig httpd on
chkconfig dhcpd on
chkconfig tftp on

由于tftp是一个非独立服务,所以,要让其生效需要启动超级守护进程xinetd
service xinetd start

二.准备yum仓库和应答文件

1.在/var/www/html/下创建文件夹 centos/6和ksdir
mkdir /var/www/html/centos/6 ksdir -pv

2.挂载光盘到centos/6

[root@Centos6 html]#mount /dev/sr0 centos/6

3.将应答文件放到ksdir目录下(文末附应答文件)

###可以通过浏览器http://192.168.36.6/ksdir/ks_centos6.cfg 查看该应答文件是否创建成功

三、配置DHCP

1.复制dhcp配置模板文件dhcpd.conf.sample覆盖dhcp配置文件dhcpd.conf,之后修改其中配置参数,在此我只修改了下面一项内容。

subnet 192.168.36.0 netmask 255.255.255.0 {
        range 192.168.36.10 192.168.36.200;
        next-server 192.168.36.6;
        filename "pxelinux.0";
}

重启dhcp服务
systemctl restart dhcpd

四、准备启动相关的文件

1.此时需要准备上一步中的pxelinux.0文件,此文件在syslinux-nonlinux中,可以直接从该包中复制(可通过rpm -ql syslinux-nonlinux 查看)

​​​​​​​cp /usr/share/syslinux/pxelinux.0   /var/lib/tftpboot/

重启dhcp服务 service dhcpd restart

2.将光盘中的部分必要文件复制到/var/lib/tftpboot/目录中。这些文件包括:isolinux.cfg、boot.msg、 splash.jpg、 initrd.img、  vmlinuz、vesamenu.c32

[root@Centos6 isolinux]#cp boot.msg splash.jpg initrd.img vesamenu.c32  vmlinuz /var/lib/tftpboot/

其中在/var/lib/tftpbpoot/下创建目录pxelinux.cfg,将isolinux.cfg复制到其中并重命名为default。修改default中的相关配置参数,在此处我修改了各个菜单的相关参数,最终制作了四个启动菜单,如下

default vesamenu.c32
#prompt 1
timeout 60:     #启动等待时间

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 ^Auto Install an Mini system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.36.6/ksdir/ks_centos6.cfg
#手动安装
label vesa
  menu label ^Manual Install an system 
  kernel vmlinuz
  append initrd=initrd.img nomodeset
#救援模式
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue repo://192.168.36.6/centos/6
#本地光盘启动
label local
  menu default
  menu label Boot from ^local drive
  localboot 0xffff

 到此在Centos6上实现PXE自动化安装Centos6就配置完毕了。接下来就可以测试安装了。

五、测试安装

【关闭防火墙后开始测试安装】

成功。

在Centos7上实现PXE自动化安装Centos7

【Centos7上实现PXE自动化安装Centos7,步骤和上面的centos6大致相同,下面是简单步骤描述。】

1.安装相关包,启动相应服务

yum install httpd dhcp tftp-server syslinux

systemctl enable httpd tftp dhcpd

2.准备yum和应答文件

mkdir /var/www/html/centos/7 -pv

mount /dev/sr0 /var/www/html/centos/7

准备应答文件

mkdir /var/www/html/ksdir
cp ks_centso7.cfg /var/www/html/ksdir

systemctl restart httpd

3.配置dhcp服务

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example   /etc/dhcp/dhcpd.conf
修改其中参数 vim /etc/dhcp/dhcpd.conf
subnet 192.168.36.0 netmask 255.255.255.0 {
        range 192.168.36.10 192.168.36.200;
        next-server 192.168.36.7;
        filename "pxelinux.0";
}

systemctl restart dhcpd

4.准备启动相关文件

cp /usr/share/syslinux/{pxelinux.0 , menu.c32}   /var/lib/tftpboot/
cp /misc/cd/isolinux/{initrd.img,vmlinuz}  /var/lib/tftpboot/
mkdir pxelinux.cfg/
cp /mnt/isolinux/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default
vim  /var/lib/tftpboot/pxelinux.cfg/defaultZ

default menu.c32
timeout 60


menu title PXE CentOS 7 Install

label linux
  menu label ^Auto Install Mini CentOS 7
  kernel vmlinuz
  append initrd=initrd.img ks=http://192.168.36.7/ksdir/ks_cent
os7.cfg

label local
menu default
  menu label Boot from ^local drive
  localboot 0xffff

systemctl start tftp

5.测试,网卡启动

在Centos7上同样可以配置Centos6的相关服务文件,从而实现以一台Centos7为服务机,可以同时选择自动安装Centos6/7两个或者多个版本


Centos6应答文件

#centos6应答文件


# Kickstart file automatically generated by anaconda.

#version=DEVEL
text
reboot
install
url --url=http://192.168.36.6/centos/6
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --ipv6 auto
rootpw  --iscrypted $6$pWrnXzIOssUEXD0m$DvHzCsm63yh945KMpJw2TZN
WkjVga/Y8iMsI5h0B7itb90cft9grVBHBO2k5ENfxuj29dS9COA3gvra4oFgH50
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkerne
l=auto rhgb quiet"
  kernelnmlinuz
# 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 --initlabel


part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /data --fstype=ext4 --size=30000

part swap --size=2048

repo --name="CentOS"  --baseurl=http://192.168.36.6/centos/6 --
cost=100

%packages
@core
@server-policy
@workstation-policy
autofs
vim-enhanced
tree
%end

%post
useradd xie
echo 256521 |passwd --stdin xie &> /dev/null
mkdir /etc/yum.repo.d/bak
mv /etc/yum.repo.d/base.repo <<ENF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF

mkdir /root/.ssh
cat > /root/.ssh/authorized_keys  <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxCW50MEYCIhQvKlThefaNt9GF61QI2WDoE+2v483lpVULyfAAhn9JR0+jFkzWeOeAPIGh23Aq8WRGwJ/kg1MoAdXLLfUQTQdBPLRTxoIAZdiphbNgSahTV56b+zfag22KbMuRDAdfWIC7nRCJS9vMvwiclddDKUepWUPt+lP20Bi06HIoCrmIqsXrXhiyCW1aWAq6/jQOK3SAXQj7lajYQ== [email protected]
EOF
chmod 600 /root/.ssh/authorized_keys
chmod 700 /root/.ssh
%end                       

Centos7应答文件

#platform=Intel Itanium
#version=DEVEL
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig  --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $6$pWrnXzIOssUEXD0m$DvHzCsm63yh945KMpJw2TZNW
kjVga/Y8iMsI5h0B7itb90cft9grVBHBO2k5ENfxuj29dS9COA3gvra4oFgH50
# Use network installation
url --url="http://192.168.36.7/centos/7"
# System language
lang en_US
user --name=xie --password=$6$XOdmF.0y/rtl1RSU$uh0W4Hp7UKCb6ofw
jxrCx9d7456d57Peqyo8UO6k9O.WQ94h7nd5PUhf6qW8fbBERQur4Thq32dJey5
FeCv67/ --iscrypted --gecos="xie"
# System authorization information
auth  --useshadow  --passalgo=sha512
<r/www/html/ksdir/ks_centos7.cfg" 58L, 1612C 14,1          Top
#platform=Intel Itanium
#version=DEVEL
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig  --startxonboot
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# Root password
rootpw --iscrypted $6$pWrnXzIOssUEXD0m$DvHzCsm63yh945KMpJwVga/Y8iMsI5h0b90cft9grVBHBO2k5ENfxuj29dS9COA3gvra4oFgH5
0
# Use network installation
url --url="http://192.168.36.7/centos/7"
# System language
lang en_US
user --name=xie --password=$6$XOdmF.0y/rtl1RSU$uh0W4Hp7UKx9d7456d57Peqyo8UO6k9O.WQ94h7nd5PUhf6qW8fbBERQur4Thq32dJe
y5FeCv67/ --iscrypted --gecos="xie"
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx

# System services
services --disabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /data --fstype="xfs" --ondisk=sda --size=30720
part / --fstype="xfs" --ondisk=sda --size=51200
part /boot --fstype="xfs" --ondisk=sda --size=1024
part swap --fstype="swap" --ondisk=sda --size=2048

%post
useradd xyc
%end

%packages
@core
%end

猜你喜欢

转载自blog.csdn.net/weixin_42255666/article/details/82805795