准备

virtual box centos7

网络配置

NAT(172.16.0.0/24,dhcp)+host noly双网卡(192.168.56.2/24,dhcp关闭)

防火墙

systemctl stop firewalld
systemctl disable firewalld

selinux

# 临时关闭
setenforce 0

# 彻底关闭,编辑/etc/selinux/config
selinux=disabled

注意:关闭selinux如果按照某些教程所说直接用sed改/etc/sysconfig/selinux会导致该软链接变成普通文件,并不能真正关闭selinux。参考总结

而如果selinux没有真正关闭,后面运行cobbler check时会报错:cobbler_api: 503 Service Unavailable

安装相关包

  • 首先开启epel:yum install epel-release

  • yum install dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart

修改cobbler配置

# /etc/cobbler/settings
#server: 127.0.0.1
server: 192.168.56.2
#next_server: 127.0.0.1
next_server: 192.168.56.2
# 系统的root密码。这里需要手动运行生成密码 
default_password_crypted: `openssl passwd -1` 
manage_dhcp: 1
pxe_just_once: 1

# /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
     option routers             192.168.56.1;
     option domain-name-servers 192.168.56.1;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.56.100 192.168.56.254;

# /etc/xinetd.d/tftp
disable = no

cobbler自检与修复

先启动cobblersystemctl start cobbler

运行cobbler check得到下面结果

The following are potential configuration items that you may want to fix:

1 : 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.
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.
  • 修复1:cobbler get-loaders

  • 2和3可以忽略

更新配置

顺利完成以下命令,最终只返回之前2和3提示即可。

cobbler sync
cobbler check

启动相关服务

systemctl start httpd rsyncd tftp cobblerd dhcpd
systemctl enable httpd rsyncd tftp cobblerd dhcpd

web界面

  • 修改默认用户cobbler的密码htdigest /etc/cobbler/users.digest "Cobbler" cobbler

  • 访问https://192.168.56.2/cobbler_web

导入镜像

以CentOS7.7为例:

# 先scp拷贝镜像到/root/
scp ~/Documents/CentOS-7-x86_64-DVD-1908.iso root@192.168.56.2:/root/

# 挂载到/mnt目录
mount -t iso9660 -o loop,ro /root/CentOS-7-x86_64-DVD-1908.iso /mnt

# 导入cobbler
cobbler import --name=CentOS7.7 --arch=x86_64 --path=/mnt
# 导入成功后会看到distro和profile
cobbler distro list
cobbler profile list

导入镜像后,mount的部分不再需要

PXE超时后默认选项

默认情况下,只有distro和profile时,pxe菜单超时后会进入local引导,因此开机需要人为干预选择要安装的操作系统。如何流畅地完成全部自动化呢:开机--pxe引导-装系统-重启-可登陆?

目前还缺的一环就是从进入pxe到开始装系统,经过参考相关文章,cobbler会优先安装名字叫default的system,其次是local。因此只要增加一个名字为default的system即可。

cobbler system add --name=default --profile=CentOS7.7-x86_64

然后cobbler sync一下即可。

这样,开机后如果不选择菜单,超时后默认就会开始该system的安装。

测试安装系统

默认配置安装系统

在完成以上步骤后,即可测试是否可以成功安装一个系统并获得基本的网络配置。

在virtual box中新建虚拟机后调整设置:

  1. 启用网络启动并排序到前面,放到启动顺序的最后。
  2. 双网卡,host-only+NAT
  3. 内存大于2G

开机安装即可

修改kickstart文件

将默认的ks文件复制一份,对其进行修改后,和profile关联即可。

cobbler list
cobbler profile report --name=XXXXX
cobbler profile edit --name=XXX --kickstart=XXX

virtualbox中CentOS7.7 Kickstart修改案例

firewall --disabled
lang zh_CN
timezone Asia/Shanghai
网卡自启
双网卡defroute配置(sed命令的写法要结合ifcfg配置情况,且使用cobbler system和不使用system时的ifcfg默认配置是不一样的)
ssh key 注入
ssh公钥认证开启

基于system对象安装

复制虚拟机,规划MAC和IP:

名称 HOST_ONLY MAC NAT MAC HOST-ONLY IP
kube1 08002782F1B1 080027E53A97 11
kube2 080027C77358 08002774C3CE 12
kube3 080027F7A341 0800279B0C9A 13
template 0800272A1265 08002725E523

创建system

cobbler system add --name=kube1-11 --profile=CentOS7.7-x86_64 --ip-address=192.168.56.11 --mac-address=08:00:27:82:F1:B1 --interface=enp0s3 --netboot-enabled=1
cobbler system add --name=kube2-12 --profile=CentOS7.7-x86_64 --ip-address=192.168.56.12 --mac-address=08:00:27:C7:73:58 --interface=enp0s3 --netboot-enabled=1
cobbler system add --name=kube3-13 --profile=CentOS7.7-x86_64 --ip-address=192.168.56.13 --mac-address=08:00:27:F7:A3:41 --interface=enp0s3 --netboot-enabled=1

完成后,当指定mac地址的机器启动pxe后,自动开始按照指定的profile开始安装,并设置相应的ip。

如果以后需要重新安装,需要在cobbler的相应system中将netboot_enabled重新设为1

注意:被安装机器内存大于2GB,否则会报错。

参考