基于centos7的PXE自动化安装centos6,7
环境:
两台主机
一台DHCP,HTTPD,TFTP服务器(一个网卡172.16.44.7,仅主机),一台测试机(一个网卡,仅主机)
关闭仅主机的vmware中dhcp服务
#创建ks文件
yum install system-config-kickstart #kickstart图形化工具
#使用图形化工具创建ks应答文件
#centos7需要修改yum仓库,添加一个"development"的yum仓库
[root@Centos7 ~]# cat ks6_mini.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.16.44.7/centos/6/os/x86_64"
# Root password default:centos
rootpw --iscrypted $1$JmO.k3YO$aE.aDZUW/6QQTeIXi0Phn0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
#graphical
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=102400
part /data --fstype="ext4" --size=51200
part swap --fstype="swap" --size=4096
%packages
@core
%end
[root@Centos7 ~]# cat /var/www/html/ksdir/ks6_desktop.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.16.44.7/centos/6/os/x86_64"
# Root password default:centos
rootpw --iscrypted $1$iDhaegPv$emFtFFmLkKBNXq6GgGZ/j.
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --size=102400
part /data --fstype="ext4" --size=51200
part swap --fstype="swap" --size=4096
%packages
@base
@basic-desktop
@core
@debugging
@desktop-debugging
@desktop-platform
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@kde-desktop
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@workstation-policy
@x11
abrt-gui
certmonger
device-mapper-persistent-data
genisoimage
krb5-workstation
libXmu
mtools
oddjob
pam_krb5
pax
python-dmidecode
qt-mysql
rdesktop
samba-winbind
sgpio
wodim
xorg-x11-xdm
xsettings-kde
xterm
%end
[root@Centos7 ~]# cat ks7_mini.cfg
#platform=x86, AMD64, or Intel EM64T
#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 $1$46GvT151$zirNpc/cWEBEADLx/hw5V.
# Use network installation
url --url="http://172.16.44.7/centos/7/os/x86_64"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System services
services --enabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --size=102400
part /data --fstype="xfs" --size=5120
part swap --fstype="swap" --size=4096
%packages
@core
%end
[root@Centos7 ~]# cat ks7_desktop.cfg
#platform=x86, AMD64, or Intel EM64T
#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 $1$kBKcOyBL$3DtOLufV3y.oQTjv1fQgd1
# Use network installation
url --url="http://172.16.44.7/centos/7/os/x86_64"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --disabled
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System services
services --enabled="chronyd"
ignoredisk --only-use=sda
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --size=102400
part /data --fstype="xfs" --size=5120
part swap --fstype="swap" --size=4096
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@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
@x11
wodim
-firefox
-icedtea-web
%end
#环境准备
[root@Centos7 ~]# yum install httpd tftp-server dhcp syslinux
[root@Centos7 ~]# mkdir -pv /var/www/html/centos/{6,7}/os/x86_64
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/6/os’
mkdir: created directory ‘/var/www/html/centos/6/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
[root@Centos7 ~]# mount /dev/sr1 /var/www/html/centos/7/os/x86_64
mount: /dev/sr1 is write-protected, mounting read-only
[root@Centos7 ~]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64
mount: /dev/sr0 is write-protected, mounting read-only
#搭建DHCP
[root@Centos7 ~]# cp /etc/dhcp/dhcpd.conf{,.bak}
[root@Centos7 ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "example.org";
option domain-name-servers 114.114.114.114, 180.76.76.76;
default-lease-time 600;
max-lease-time 7200;
subnet 172.16.44.0 netmask 255.255.255.0 {
range 172.16.44.50 172.16.44.100;
option routers 172.16.44.2;
next-server 172.16.44.7;
filename "pxelinux.0";
}
#准备引导的相关文件
[root@Centos7 ~]# mkdir /var/www/html/ksdir
[root@Centos7 ~]# chmod 755 -R /var/www/html/ksdir
[root@Centos7 ~]# cp ks6_mini.cfg ks6_desktop.cfg ks7_mini.cfg ks7_desktop.cfg /var/www/html/ksdir
[root@Centos7 ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
[root@Centos7 ~]# mkdir /var/lib/tftpboot/centos{6,7}
[root@Centos7 ~]# cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6
[root@Centos7 ~]# cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7
[root@Centos7 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@Centos7 ~]# cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@Centos7 ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
3 directories, 7 files
#准备启动菜单
[root@Centos7 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
label CentOS 7.6 mini
menu label Install CentOS 7.6 ^Mini
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://172.16.44.7/ksdir/ks7_mini.cfg
label CentOS 7.6 Desktop
menu label Install CentOS ^7.6 Desktop
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://172.16.44.7/ksdir/ks7_desktop.cfg
label CentOS 6.10 mini
menu label Install CentOS 6.10 ^Mini
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://172.16.44.7/ksdir/ks6_mini.cfg
label CentOS 6.10 Desktop
menu label Install CentOS ^6.10 Desktop
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://172.16.44.7/ksdir/ks6_desktop.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
#启动服务
[root@Centos7 ~]# systemctl start httpd dhcpd tftp.socket
-
至此配置完毕,客户端可以网卡启动测试
基于cobbler自动化安装
环境:
两台主机
一台DHCP,HTTPD,TFTP服务器(一个网卡172.16.44.7,仅主机),一台测试机(一个网卡,仅主机)
关闭仅主机的vmware中dhcp服务
#清除原来没用的配置文件
[root@Centos7 ~]# umount /dev/sr0
[root@Centos7 ~]# rm -rf /var/lib/tftpboot/*
[root@Centos7 ~]# echo > /etc/dhcp/dhcpd.conf
#安装cobbler
[root@Centos7 ~]# yum install cobbler dhcpd -y #需要EPL源
[root@Centos7 ~]# systemctl restart httpd cobblerd tftp.socket
#检查并修改配置文件
[root@Centos7 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely. Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
Restart cobblerd and then run 'cobbler sync' to apply changes.
[root@Centos7 ~]# vim /etc/cobbler/settings
[root@Centos7 ~]# cobbler get-loaders #自动配置菜单文件(需要联网)
task started: 2020-03-24_145101_get_loaders
task started (id=Download Bootloader Content, time=Tue Mar 24 14:51:01 2020)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***
[root@Centos7 ~]# vim /etc/cobbler/dhcp.template #修改模板文件
subnet 172.16.44.0 netmask 255.255.255.0 {
option routers 172.16.44.2;
option domain-name-servers 172.16.44.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 172.16.44.100 172.16.44.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else if option pxe-system-type = 00:09 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
#同步文件
[root@Centos7 ~]# systemctl restart cobblerd
[root@Centos7 ~]# cobbler sync
task started: 2020-03-24_151509_sync
task started (id=Sync, time=Tue Mar 24 15:15:09 2020)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.manage_genders
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***
#导入光盘文件
[root@Centos7 ~]# mount /dev/sr0 /mnt #挂载centos6光盘
[root@Centos7 ~]# cobbler import --path=/mnt --name=Centos6.10-x86_64 --arch=x86_64
task started: 2020-03-24_151746_import
task started (id=Media import, time=Tue Mar 24 15:17:46 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos6.10-x86_64:
creating new distro: Centos6.10-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos6.10-x86_64 -> /var/www/cobbler/links/Centos6.10-x86_64
creating new profile: Centos6.10-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos6.10-x86_64 for Centos6.10-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos6.10-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos6.10-x86_64
looking for /var/www/cobbler/ks_mirror/Centos6.10-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos6.10-x86_64/repodata
*** TASK COMPLETE ***
[root@Centos7 ~]# umount /dev/sr0
[root@Centos7 ~]# mount /dev/sr1 /mnt #挂载centos7光盘
mount: /dev/sr1 is write-protected, mounting read-only
[root@Centos7 ~]# cobbler import --path=/mnt --name=Centos7.6-x86_64 --arch=x86_64
task started: 2020-03-24_152040_import
task started (id=Media import, time=Tue Mar 24 15:20:40 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos7.6-x86_64:
creating new distro: Centos7.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos7.6-x86_64 -> /var/www/cobbler/links/Centos7.6-x86_64
creating new profile: Centos7.6-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos7.6-x86_64 for Centos7.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos7.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos7.6-x86_64
looking for /var/www/cobbler/ks_mirror/Centos7.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos7.6-x86_64/repodata
*** TASK COMPLETE ***
#关联自定义ks文件
[root@Centos7 ~]# cp ks6_* ks7_* /var/lib/cobbler/kickstarts/ #把做好的KS文件拷贝过去
[root@Centos7 ~]# cobbler profile add --name Centos6.10-x86_64_mini --distro=Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg
[root@Centos7 ~]# cobbler profile add --name Centos6.10-x86_64_Desktop --distro=Centos6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_desktop.cfg
[root@Centos7 ~]# cobbler profile add --name Centos7.6-x86_64_mini --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
[root@Centos7 ~]# cobbler profile add --name Centos7.6-x86_64_Desktop --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_desktop.cfg
[root@Centos7 ~]# cobbler profile list
Centos6.10-x86_64
Centos6.10-x86_64_Desktop
Centos6.10-x86_64_mini
Centos7.6-x86_64
Centos7.6-x86_64_Desktop
Centos7.6-x86_64_mini
[root@Centos7 ~]# cobbler profile remove --name Centos6.10-x86_64
[root@Centos7 ~]# cobbler profile remove --name Centos7.6-x86_64
[root@Centos7 ~]# cobbler profile list
Centos6.10-x86_64_Desktop
Centos6.10-x86_64_mini
Centos7.6-x86_64_Desktop
Centos7.6-x86_64_mini
#把ks文件url路径改为"url --url=$tree"
[root@Centos7 ~]# cd /var/lib/cobbler/kickstarts
[root@Centos7 kickstarts]# sed -i -r 's/(.*--url=)(.*)/\1$tree/' ks*
#引导菜单已自动生成
[root@Centos7 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL Centos6.10-x86_64_Desktop
kernel /images/Centos6.10-x86_64/vmlinuz
MENU LABEL Centos6.10-x86_64_Desktop
append initrd=/images/Centos6.10-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://127.0.0.1/cblr/svc/op/ks/profile/Centos6.10-x86_64_Desktop
ipappend 2
LABEL Centos6.10-x86_64_mini
kernel /images/Centos6.10-x86_64/vmlinuz
MENU LABEL Centos6.10-x86_64_mini
append initrd=/images/Centos6.10-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://127.0.0.1/cblr/svc/op/ks/profile/Centos6.10-x86_64_mini
ipappend 2
LABEL Centos7.6-x86_64_Desktop
kernel /images/Centos7.6-x86_64/vmlinuz
MENU LABEL Centos7.6-x86_64_Desktop
append initrd=/images/Centos7.6-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://127.0.0.1/cblr/svc/op/ks/profile/Centos7.6-x86_64_Desktop
ipappend 2
LABEL Centos7.6-x86_64_mini
kernel /images/Centos7.6-x86_64/vmlinuz
MENU LABEL Centos7.6-x86_64_mini
append initrd=/images/Centos7.6-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://127.0.0.1/cblr/svc/op/ks/profile/Centos7.6-x86_64_mini
ipappend 2
MENU end
#重新启动服务
[root@Centos7 ~]# systemctl restart cobblerd dhcpd tftp.socket httpd
-
至此配置完毕,客户端可以网卡启动测试
网友评论