文章目录
安装
本来Google的方案需要从源码安装,但是尝试了下apt, 发现有现成的包,所以简单太多了 版本太老,有额外的问题要处理.
sudo apt install cobbler cobbler-web
# 安装过程中会让输密码
# 该包是2.6.6版本 有点老,现在来说有好几个bug
# cobbler-web 有bug, 不兼容新的
sudo pip install Django==1.8.9
# 结果输出
Setting up liblwp-protocol-https-perl (6.07-2) ...
Setting up debmirror (1:2.32) ...
Setting up cobbler (2.6.6+dfsg1-13) ...
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.
To activate the new configuration, you need to run:
systemctl restart apache2
Module wsgi already enabled
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2
ERROR: Module python does not exist!
Enabling site cobbler.
To activate the new configuration, you need to run:
systemctl reload apache2
Created symlink /etc/systemd/system/multi-user.target.wants/cobbler.service → /lib/systemd/system/cobbler.service.
# 在重启前需要配置cobbler
配置
# 配置文件 /etc/cobbler/settings
# 自动化部署系统的密码的哈希, 用下行命令生成
# openssl passwd -1
# $1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG.
# 密文第一项 1 指hash方式, 第二项 j9.kasLF 指的salt,这样子用以系统判断密码是否正确但是又不存储密码,密码和salt都相同时才能计算出唯一的密文
default_password_crypted: "$1$j9.kasLF$4v5dJWXMDUmxYTXO9qPiG."
# 设置cobbler的ip, 不要设置0.0.0.0,设置一个不隔离广播域的内网ip
server: 192.168.1.2
# 设置的tftp ip,用于下载镜像,通常与上一个一样
next_server: 192.168.1.2
# 是否开启DHCP,0不开启 1开启
# 为了启动 pxe, 需要开启dhcp分发地址 并引导系统 到tftp server下载网络启动文件
manage_dhcp: 1
# 配置DHCP /etc/cobbler/dhcp.template
# 不要修改 next-server 项,该配置会自动从上面拉取变量
# 不要修改 #for dhcp_tag in $dhcp_tags.keys(): 这一行之后的内容
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 114.114.114.114,8.8.8.8;
option subnet-mask 255.255.255.0;
filename "/pxelinux.0";
default-lease-time 2.8.0;
max-lease-time 43200;
next-server $next_server;
}
cobbler 会将 镜像存储到 /var/lib/cobbler/www/cobbler/ks_mirror/下, 注意容量和权限
sudo systemctl enable cobbler
sudo systemctl start cobbler
# 检测 会提示一些操作, 根据需要去做
sudo cobbler check
sudo cobbler sync
# 会发现该指令报错 缺pxelinux.0等一批loaders
Raspberry 安装syslinux
scp CentOS-8.2.2004-x86_64-dvd1.iso pi@x.x.x.x:/home/pi/
ssh pi@x.x.x.x
sudo mount -o loop ~/CentOS-8.2.2004-x86_64-dvd1.iso /media/
sudo cp /media/BaseOS/Packages/syslinux-nonlinux-6.04-4.el8.noarch.rpm /tmp
sudo apt install rpm2cpio
sudo rpm2cpio /tmp/syslinux-nonlinux-6.04-4.el8.noarch.rpm | cpio -idmv
sudo cp /tmp/usr/share/syslinux/* /usr/lib/syslinux/
sudo umount /media
# 现在正常
sudo cobbler sync
导入镜像
# http://mirrors.aliyun.com/centos 下载镜像, 下载minimal版方便测试
sudo mkdir /mnt/centos_mini
sudo mount -t iso9660 -o loop,ro ~/CentOS-8.2.2004-x86_64-dvd1.iso /mnt
sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini
# 出现这个问题
task started: 2020-07-12_041754_import
task started (id=Media import, time=Sun Jul 12 04:17:54 2020)
No signature matched in /var/lib/cobbler/www/cobbler/ks_mirror/centos8-x86_64
!!! TASK FAILED !!!
# 使用该指令之后再导入一次
sudo cobbler signature update
sudo cobbler import --name=centos8 --arch=x86_64 --path=/mnt
# 出现这个问题
Exception occured: <type 'exceptions.KeyError'>
Exception value: 'default_kickstart'
Exception Info:
File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run
rc = self._run(self)
File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 231, in runner
self.logger
File "/usr/lib/python2.7/dist-packages/cobbler/api.py", line 938, in import_tree
return import_module.run(path,mirror_name,network_root,kickstart_file,arch,breed,os_version)
File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 132, in run
self.signature = self.scan_signatures()
File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 192, in scan_signatures
self.kickstart_file = sigdata["breeds"][breed][version]["default_kickstart"]
# 找到 distro_signatures 文件, 替换 default_autoinstall 为 default_kickstart
sudo vim /var/lib/cobbler/distro_signatures.json
:%s/default_autoinstall/default_kickstart/
sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini
## 出现错误
creating new profile: cobbler-centos8-x86_64
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'kickstart not found: None'
Exception Info:
File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run
rc = self._run(self)
File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 231, in runner
self.logger
File "/usr/lib/python2.7/dist-packages/cobbler/api.py", line 938, in import_tree
return import_module.run(path,mirror_name,network_root,kickstart_file,arch,breed,os_version)
File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 140, in run
os.path.walk(self.path, self.distro_adder, distros_added)
File "/usr/lib/python2.7/posixpath.py", line 239, in walk
walk(name, func, arg)
File "/usr/lib/python2.7/posixpath.py", line 239, in walk
walk(name, func, arg)
File "/usr/lib/python2.7/posixpath.py", line 231, in walk
func(arg, top, names)
File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 255, in distro_adder
adtls.append(self.add_entry(dirname,kernel,initrd))
File "/usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py", line 349, in add_entry
profile.set_kickstart(self.kickstart_file)
File "/usr/lib/python2.7/dist-packages/cobbler/item_profile.py", line 211, in set_kickstart
raise CX(_("kickstart not found: %s") % kickstart)
!!! TASK FAILED !!!
# 尝试查询distro, 发现centos已经导入,但是没有profile
sudo cobbler distro list
# 返回
# cobbler-centos8-mini-x86_64
sudo cobbler profile list
# 没有返回任何profile,中间出现了错误 导入distro成功但配置profile失败
# 手动删除 distro
sudo cobbler distro remove --name=cobbler-centos8-mini-x86_64
# 现在我们检查到底出什么错
sudo vim /usr/lib/python2.7/dist-packages/cobbler/item_profile.py
# 211行 如下图所示 修改,打印出到底是什么
# 重新导入 输出为
creating new profile: cobbler-centos8-mini-x86_64
Exception occured: <class 'cobbler.cexceptions.CX'>
Exception value: 'kickstart not found: sample.ks'
Exception Info:
File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 87, in run
rc = self._run(self)
.......
File "/usr/lib/python2.7/dist-packages/cobbler/item_profile.py", line 212, in set_kickstart
raise CX(_("kickstart not found: %s") % temp)
!!! TASK FAILED !!!
# 看来是sample.ks 未找到
# find_kickstart() 函数为
def find_kickstart(url):
"""
Check if a kickstart url looks like an http, ftp, nfs or local path.
If a local path is used, cobbler will copy the kickstart and serve
it over http.
Return None if the url format does not look valid.
"""
if url is None:
return None
x = url.lstrip()
for y in ["http://", "nfs://", "ftp://", "/"]:
# make sure we get a lower-case protocol without
# affecting the rest of the string
x = re.sub(r"(?i)%s" % y, y, x, count=1)
if x.startswith(y):
if x.startswith("/") and not os.path.isfile(x):
return None
return x
return None
# 明显输入为'sample.ks'时输出为None, 推测是未给url加绝对路径,文件在/var/lib/cobbler/kickstarts/sample.ks
# /usr/lib/python2.7/dist-packages/cobbler/modules/manage_import_signatures.py: 192 直接读取并没有添加,所以需要我们自己手动添加
sudo vim /var/lib/cobbler/distro_signatures.json
:%s/sample.ks/\/var\/lib\/cobbler\/kickstarts\/sample.ks/
# 重新导入, 一次成功
sudo cobbler import --name=centos8-mini --arch=x86_64 --path=/mnt/centos_mini
# 输出
➜ test sudo cobbler distro list
cobbler-centos8-mini-x86_64
➜ test sudo cobbler profile list
cobbler-centos8-mini-x86_64
➜ test sudo cobbler distro report --name=cobbler-centos8-mini-x86_64
Name : cobbler-centos8-mini-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/lib/cobbler/www/cobbler/ks_mirror/centos8-mini-x86_64/images/pxeboot/initrd.img
Kernel : /var/lib/cobbler/www/cobbler/ks_mirror/centos8-mini-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/cobbler-centos8-mini-x86_64'}
Management Classes : []
OS Version : rhel8
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
➜ test sudo cobbler profile report --name=cobbler-centos8-mini-x86_64
Name : cobbler-centos8-mini-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : cobbler-centos8-mini-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : virbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
修改centos用的kickstart文件
cd /var/lib/cobbler/kickstarts/
sudo cp sample.ks centos8.ks
sudo cobbler profile edit --name=cobbler-centos8-mini-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.ks
# 验证
sudo cobbler profile report --name=cobbler-centos8-mini-x86_64 | grep kickstart
# 同步
sudo cobbler sync
Centos8.ks
#platform=x86, AMD64, or Intel EM64T
#os=centos8
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone Asia/ShangHai
# System authorization information
auth --useshadow --enablemd5
#Root password
rootpw --iscrypted $default_password_crypted
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree
# Clear the Master Boot Record
zerombr
# System bootloader configuration
# bootloader --location=mbr
# interface can be named as eth*
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0 rhgb quiet"
# Partition clearing information
clearpart --all --initlabel
# Allow anaconda to partition the system as needed
autopart
# or
# # create 1MB biosboot type partition, centos7 and centos8 .
# part biosboot --fstype=biosboot --size=1
# # Disk partitioning information
# part /boot --fstype=xfs --size=300
# part pv.122 --fstype="lvmpv" --grow
# volgroup VolGroup00 --pesize=16384 pv.122
# logvol / --fstype="xfs" --size=10000 --name=LogVol00 --vgname=VolGroup00
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages
$SNIPPET('func_install_if_enabled')
# if you need puppet to install pkgs, just uncomment it
# $SNIPPET('puppet_install_if_enabled')
@core
@base
tree
nmap
wget
telnet
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('puppet_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
[ 1 ]: http://cobbler.github.io
[ 2 ]: https://cobbler.readthedocs.io/en/latest/
[ 3 ]: https://bashtheshell.com/guide/setting-up-pxe-boot-server-on-raspberry-pi/