mynote/raspberry/cobbler.md
2020-12-21 10:40:31 +08:00

20 KiB
Raw Blame History

树莓派 配置 cobbler

[TOC]

安装

# 源码安装
sudo apt install git make python-dev python-setuptools python-cheetah openssl
sudo apt install createrepo apache2  python-cheetah python-netaddr python-simplejson python-urlgrabber python-yaml rsync  yum-utils  libapache2-mod-wsgi xinetd tftpd tftp python-django
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo a2ensite cobbler.conf

sudo apt install make git python3-yaml python3-cheetah python3-netaddr python3-simplejson python3-future python3-distro python3-setuptools python3-sphinx python3-coverage pyflakes3 python3-pycodestyle python3-django




git clone https://github.com/cobbler/cobbler.git
cd cobbler
git checkout release28

本来Google的方案需要从源码安装但是尝试了下apt 发现有现成的包,所以简单太多了 版本太老,有额外的问题要处理.

sudo apt install cobbler cobbler-web xinetd
# 安装过程中会让输密码
# 该包是2.6.6版本 有点老现在来说有好几个bug
# cobbler-web 有bug 不兼容新的
sudo pip install Django==1.8.9

image-20200712010915940

# 结果输出
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

# 是否开启DHCP0不开启 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;
}

#  树莓派版本用的dnsmasq所以改这个
#  配置DHCP /etc/cobbler/dnsmasq.template

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/centos_mini
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-mini --arch=x86_64 --path=/mnt/centos_mini


# 出现这个问题
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

image-20200714013540086

修改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
# centos8 已经将authconfig 更新为authselect
# auth  --useshadow  --enablemd5
authselect --enableshadow --passlgo=sha512
#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
# add repo manually
# repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream

# 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')
%end

%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
$('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
%end

验证

  • failed to load ldlinux.c32

image-20200714060726959

sudo cp /usr/lib/syslinux/ldlinux.c32 /var/lib/cobbler/tftp/
  • Failed to load libutil.c32 failed to load COM32 file menu.c32

    image-20200714061319612

sudo cp /usr/lib/syslinux/libutil.c32 /var/lib/cobbler/tftp/
sudo cp /usr/lib/syslinux/menu.c32 /var/lib/cobbler/tftp/
  • 暂时成功

image-20200714061640172

  • failed to fetch kickstart from http://.../cblr/svc/op/ks/profile/cobbler-centos8-mini-x86_x64

    dracut-initqueue[944]: Warning: dracut-initqueue timeout

    image-20200714062152172

    # 又是版本不对应的锅
    # apache2 升级到2.4之后之前的的配置不能通过授权
    sudo vim /etc/apache2/apache2.conf
    
    <Directory />
    	Options FollowSymLinks
    	AllowOverride None
    #Require all denied
        Require all granted
    </Directory>
    
    # 查看日志有错误
    Tue Jul 14 08:18:54 2020 - INFO | Exception occured: <class 'cobbler.cexceptions.CX'>
    Tue Jul 14 08:18:54 2020 - INFO | Exception value: 'Error templating file, check cobbler.log for more details'
    Tue Jul 14 08:18:54 2020 - INFO | Exception Info:
      File "/usr/lib/python2.7/dist-packages/cobbler/remote.py", line 1062, in generate_kickstart
        return self.api.generate_kickstart(profile,system)
       File "/usr/lib/python2.7/dist-packages/cobbler/api.py", line 696, in generate_kickstart
        return self.kickgen.generate_kickstart_for_profile(profile)
       File "/usr/lib/python2.7/dist-packages/cobbler/kickgen.py", line 312, in generate_kickstart_for_profile
        return self.generate_kickstart(profile=g)
       File "/usr/lib/python2.7/dist-packages/cobbler/kickgen.py", line 290, in generate_kickstart
        data = self.templar.render(raw_data, meta, None, obj)
       File "/usr/lib/python2.7/dist-packages/cobbler/templar.py", line 116, in render
        data_out = self.render_cheetah(raw_data, search_table, subject)
       File "/usr/lib/python2.7/dist-packages/cobbler/templar.py", line 215, in render_cheetah
        raise CX("Error templating file, check cobbler.log for more details")
    
    # 修改该文件37行
    sudo vim /usr/lib/python2.7/dist-packages/cobbler/templar.py
    # 改为: fix_cheetah_class = (int(major), int(minor), int(release)) >= (2, 4, 2)
    
  • 系统安装中出现一些异常

    pykickstart.errors.KickstartError: /usr/sbin/authconfig is missing

    image-20200714085059931

    # 该问题是centos 8 没有authconfig指令了更新为了 authselect
    # 更改ks文件将auth 行 换成authselect
    
    • missing packages: 配置本地源即可解决

image-20200714184027547

  • sbin/dmsquash-live-root: line 273: write error: No space left on device

    确保虚拟机有至少2g内存

  • pyanaconda.payload.PayloadError: Payload error - DNF installation has ended up abruptly: No available modular metadata for modular package Traceback

Dnf.exceptions.Error: No available modular metadata for modular package

image-20200714233216115

配置 centos8 本地源

sudo apt install yum-utils
# 添加

sudo cobbler repo add --name=Centos8-BaseOS --mirror=http://mirrors.aliyun.com/centos/8.2.2004/BaseOS/x86_64/os/  --arch=x86_64 --breed=yum
sudo cobbler repo add --name=Centos8-AppStream --mirror=http://mirrors.aliyun.com/centos/8.2.2004/AppStream/x86_64/os/  --arch=x86_64 --breed=yum

sudo cobbler repo add --name=Centos8-extras --mirror=http://mirrors.aliyun.com/centos/8.2.2004/extras/x86_64/os/  --arch=x86_64 --breed=yum
sudo cobbler repo add --name=Centos8-Epel --mirror=http://mirrors.aliyun.com/epel/8/Everything/x86_64/  --arch=x86_64 --breed=yum

sudo cobbler repo add --name=Centos8-Openstack-ussuri --mirror=http://mirrors.aliyun.com/centos/8.2.2004/cloud/x86_64/openstack-ussuri/  --arch=x86_64 --breed=yum

# 查看
sudo cobbler repo list

# 同步
# 需要 sudo apt install yum-utils, 安装完后重启cobbler
# 存储在 /var/lib/cobbler/www/cobbler/repo_mirror/
sudo cobbler reposync
sudo cobbler profile edit --name=cobbler-centos8-mini-x86_64 --repos='Centos8-BaseOS Centos8-AppStream Centos8-extras Centos8-Epel Centos8-Openstack-ussuri'
# 或者手动在ks文件里添加
# repo --name="BaseOS" --baseurl=http://192.168.10.50/cblr/repo_mirror/Centos8-BaseOS/