从零到一教你部署Cobbler

Linux其他教程文章可以访问本人博客
https://blog.yangwn.top/index.php/archives.html

Cobbler简介

#官方网站
http://cobbler.github.io/

#Cobbler作用
Cobbler是Linux安装服务器可以快速设置网络安装环境、具备web管理界面

Cobbler部署前准备

#此博文适用于Centos7.9以上的操作系统
Centos7安装cobbler的版本为V2.8.5
Centos8安装cobbler的版本为V3.2.0(不推荐)
文章以Centos7部署V2.8.5版本为例进行示范

#操作系统版本
cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

#关闭防火墙和selinux
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

#关闭了selinux需要重启服务器生效
reboot

#yum源准备(必须有epel和Base源)
wget -O /tmp/system.sh https://index.swireb.cn/shell/system.sh && sh /tmp/system.sh #通过脚本优化yum源(使用的为阿里云yum仓库)

Cobbler部署

  • Cobbler组件安装
#Centos7(其余的软件会作为依赖安装)
yum install -y dhcp cobbler cobbler-web debmirror pykickstart 

#Centos8(不推荐)
yum install debmirror pykickstart dhcp-server
dnf module install cobbler

#组件作用简介
cobbler     #基础组件
cobbler-web #web组件
debmirror   #镜像管理工具
pykickstart #检查cobbler配置文件语法
httpd       #发布镜像
syslinux    #配置引导文件(生成pxelinux.0)
tftp-server #为PXE的客户端提供引导文件
dhcp        #为PXE的客户端提供IP地址、告知tftp的服务地址
  • Cobbler目录文件简介
rpm -ql cobbler
/etc/cobbler                  #配置文件目录
/etc/cobbler/settings         #cobbler主配置文件
/etc/cobbler/dhcp.template    #dhcp服务的配置模板
/etc/cobbler/tftpd.template   #tftp服务的配置模板
/etc/cobbler/rsync.template   #rsync服务的配置模板
/etc/cobbler/iso              #iso模板配置文件目录
/etc/cobbler/pxe              #pxe模板文件目录
/etc/cobbler/power            #电源的配置文件目录
/etc/cobbler/users.conf       #web服务授权配置文件
/etc/cobbler/users.digest     #用于web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template #dns服务的配置模板
/etc/cobbler/modules.conf     #cobbler模块配置文件
/var/lib/cobbler              #cobbler数据目录
/var/lib/cobbler/config       #配置文件
/var/lib/cobbler/kickstarts   #默认存放kickstart文件
/var/lib/cobbler/loaders      #存放的各种引导程序
/var/www/cobbler              #系统安装镜像目录
/var/www/cobbler/ks_mirror    #导入的系统镜像列表
/var/www/cobbler/images       #导入的系统镜像启动文件
/var/www/cobbler/repo_mirror  #yum源存储目录
/var/log/cobbler              #日志目录
/var/log/cobbler/install.log  #客户端系统安装日志
/var/log/cobbler/cobbler.log  #cobbler日志
  • Cobbler主配置文件修改
#cobbler主配置文件修改
vim /etc/cobbler/settings
default_password_crypted: "$1$MJtVUpSN$7GvTgV5YO3NT1LZ7S2U0Q1"  #通过openssl passwd -1生成密文密码
manage_dhcp: 0  #cobbler接管dhcp(0为关闭 1为开启)
manage_tftpd: 1 #cobbler接管tftp(0为关闭 1为开启)
next_server: 192.168.1.11  #tftp服务地址
server: 192.168.1.11       #cobbler服务地址

#cobbler启动服务
systemctl enable --now httpd.service
systemctl enable --now cobblerd.service

#cobbler可以将自身作为dhcp服务器为安装系统的客户端分发IP地址、也可以使用已有的dhcp服务器

#为了首次同步成功这里统一将cobbler接管dhcp的功能暂时关闭
  • Cobbler首次检查
#可能每人的报错问题不同此处列举我的报错问题
cobbler check
1 : change 'disable' to 'no' in /etc/xinetd.d/tftp
2 : 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. #可以忽略(确保系统已经安装selinux)
3 : enable and start rsyncd.service with systemctl
4 : comment out 'dists' on /etc/debmirror.conf for proper debian support
5 : comment out 'arches' on /etc/debmirror.conf for proper debian support
6 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them #可以忽略
  • 解决Cobbler检查报错
#报错1问题解决
vim /etc/xinetd.d/tftp
service tftp
{
    
    
        socket_type             = dgram
        protocol                = udp
        wait                    = yes 
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no #只修改这里
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

#报错3问题解决
systemctl enable --now rsyncd.service

#报错3、4问题解决
vim /etc/debmirror.conf
# @dists="sid";    #注释这行信息
# @arches="i386";  #注释这行信息 
  • Cobbler首次同步
#重启cobbler服务
systemctl restart cobblerd.service

#再次运行检查
cobbler check
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 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them 

#cobbler首次同步
cobbler sync

配置dhcp服务

  • cobbler接管dhcp
#修改dhcp模板文件
vim /etc/cobbler/dhcp.template  
subnet 192.168.1.0 netmask 255.255.255.0 {
    
    
     option routers             192.168.1.1;
     option domain-name-servers 192.168.1.1;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.1.60 192.168.1.80; 
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;

#cobbler主配置文件开启dhcp接管
vim /etc/cobbler/settings  
manage_dhcp: 1

#重新同步
systemctl restart cobblerd.service
cobbler sync  

#启动dhcp服务
systemctl enable --now dhcpd.service 
systemctl restart dhcpd.service 
  • 使用其他dhcp服务器
#修改dhcp配置文件
vim /etc/dhcp/dhcpd.conf 
subnet 192.168.1.0 netmask 255.255.255.0 {
    
    
  range 192.168.1.60 192.168.1.80; 
  option routers 192.168.1.1;
  option domain-name-servers 192.168.1.1;
  option broadcast-address 192.168.1.255; 
  default-lease-time 600;
  next-server 192.168.1.11;  #指定cobbler服务器为tftp服务器
  filename "pxelinux.0";    
  max-lease-time 7200;
}

#启动dhcp服务
systemctl enable --now dhcpd.service 
systemctl restart dhcpd.service

其他相关服务配置

  • 配置tftp服务
#确保tftp的站点目录存在引导文件(cobbler检查问题的过程中已经修了tftp的配置文件)
ll /var/lib/tftpboot/
drwxr-xr-x  3 root root   4096 Mar  1 23:54 boot
drwxr-xr-x. 2 root root   4096 Oct 15  2019 etc
drwxr-xr-x. 2 root root   4096 Mar  1 23:54 grub  #UEFI启动菜单目录
drwxr-xr-x. 7 root root   4096 Mar  1 23:54 images
drwxr-xr-x. 2 root root   4096 Oct 15  2019 images2
-rw-r--r--. 2 root root  26140 Oct 31  2018 memdisk
-rw-r--r--. 2 root root  54964 Mar  1 23:54 menu.c32
drwxr-xr-x. 2 root root   4096 Oct 15  2019 ppc
-rw-r--r--. 2 root root  16794 Mar  1 23:54 pxelinux.0
drwxr-xr-x. 2 root root   4096 Mar  1 23:56 pxelinux.cfg #BIOS启动菜单目录
drwxr-xr-x. 2 root root   4096 Mar  1 23:54 s390x
-rw-r--r--  2 root root 198236 Feb  8 15:17 yaboot

#启动tftp服务
systemctl enable --now tftp.service 
systemctl restart tftp.service 
  • 客户端测试访问

image-20210301152228267

  • 系统镜像挂载
#Ubuntu镜像注意事项
不支持desktop、live版本(仅支持LTS server version版本)
推荐ubuntu-18.04-server-amd64

#使用光驱加载Centos6的系统镜像

#为后续cobble导入镜像做准备
mount -t iso9660 -o loop,ro /dev/cdrom /mnt

Cobbler使用

  • Cobbler命令语法
#命令语法
cobbler --help
cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]
  • Cobble导入镜像
#命令语法
cobbler import --help
Usage: cobbler import [options]
Options:
  --arch=ARCH           镜像架构
  --path=PATH           镜像导入路径
  --name=NAME           镜像名称

#命令操作
cobbler import --name=Centos6 --arch=x86_64 --path=/mnt
cobbler import --name=Centos7 --arch=x86_64 --path=/mnt
cobbler import --name=Centos8 --arch=x86_64 --path=/mnt
cobbler import --name=Ubuntu18 --arch=x86_64 --path=/mnt

#列出对象
cobbler distro list
cobbler profile list

#列出对象详细信息
cobbler distro report --name=Centos6-x86_64
Name                           : Centos6-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {
    
    }
Breed                          : redhat
Comment                        : 
Fetchable Files                : {
    
    }
Initrd                         : /var/www/cobbler/ks_mirror/Centos6-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/Centos6-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {
    
    }
Kernel Options (Post Install)  : {
    
    }
Kickstart Metadata             : {
    
    'tree': 'http://@@http_server@@/cblr/links/Centos6-x86_64'}
Management Classes             : []
OS Version                     : rhel6
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {
    
    }

#导入镜像的过程
将光盘文件复制到/var/www/cobbler/ks_mirror目录下
并安装会cobbler自动生成apahce的一个子配置文件/etc/httpd/conf.d/cobbler.conf将镜像发表出去
http://IP/cobbler/

#导入Centos6和Centos7导入无异常
#导入Centos8的镜像会报错解决办法在文件下方cobbler导入镜像失败
#导入Ubuntu 18.04之后的版本也是导入失败(非LTS版本可能支持的不友好)
  • 自定义ks模板文件
#Centos系统ks模板文件(适配Centos6、Centos7、Centos8)
vim /var/lib/cobbler/kickstarts/sample_end.ks
firewall --disabled
selinux --disabled
timezone  Asia/Shanghai
%packages #自定义安装软件包
@base
@core
%pre      #安装系统之前执行的脚本
%post     #安装系统之后执行的脚本
wget -O ~/system.sh https://index.swireb.cn/shell/system.sh && sh ~/system.sh
# $yum_config_stanza

#Ubuntu系统ks模板文件(适配Ubuntu18.04、其余版本需要自己创建ks文件)
vim /var/lib/cobbler/kickstarts/sample.seed
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp-server string cn.pool.ntp.org
# d-i pkgsel/include string ntp ssh wget  #这行注释(这几个软件默认会安装)
  • 其他相关操作
#指定计算机网络
cobbler system edit --name=test --interface=eth0 --mac=00:50:56:31:21:85 --ip-address=192.168.1.7 --netmask=255.255.255.0 --static=1 --dns-name=192.168.1.1

#指定计算机名称
cobbler system edit --name=test --gateway=192.168.1.1 --hostname=test.mydomain.com

Cobbler配置启动菜单

  • 客户端配置

image-20210302000400700

  • 服务端配置BIOS启动菜单
#修改启动菜单配置文件
vim /etc/cobbler/pxe/pxedefault.template
TIMEOUT 6000

#cobbler重新同步
cobbler sync
  • 服务端配置UEFI启动菜单
#联网下载UEFI启动的相关文件
cobbler get-loaders

#修改启动菜单配置文件
vim /etc/cobbler/pxe/efidefault.template
timeout=6000  #修改启动菜单加时间(必须修改不然一闪则过)

#cobbler重新同步
cobbler sync

Cobbler配置Web管理界面

#访问地址(必须为https)
https://192.168.1.11/cobbler_web

#默认访问用户
用户:cobbler
密码:cobbler

#创建用户
/etc/cobbler/users.conf       #web服务授权配置文件
/etc/cobbler/users.digest     #用于web访问的用户名密码配置文件

image-20210302002442859

Cobbler导入镜像失败

  • 故障示意图

image-20210302150753759

  • Centos8.3解决办法
#修改签名文件(修改rhel8键值对内的二行信息即可)
vim /var/lib/cobbler/distro_signatures.json
"rhel8": {
    
    
    "signatures":["BaseOS"],
    "version_file": "(redhat|sl|slf|centos|centos-linux|centos-stream|oraclelinux|vzlinux)-release-(?!notes)([\\w]*-)*8[\\.-]+(.*)\\.rpm",
    "version_file_regex":null,
    "kernel_arch":"kernel-(.*).rpm",
    "kernel_arch_regex":null,
    "supported_arches":["aarch64","i386","x86_64","ppc64le"],
    "supported_repo_breeds":["rsync", "rhn", "yum"],
    "kernel_file":"vmlinuz(.*)",
    "initrd_file":"initrd(.*)\\.img",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample_end.ks",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]
   },

#更新签名文件(不推荐)
cobbler signature report #列出
cobbler signature update #更新

#重启服务
systemctl restart cobblerd.service

Ubuntu18、Ubuntu19解决办法

#Ubuntu 18.10
    "cosmic": {
    
    
    "signatures":["dists", ".disk"],
    "version_file":"Release|mini-info",
    "version_file_regex":"Codename: cosmic|Ubuntu 18.10",
    "kernel_arch":"linux-headers-(.*)\\.deb",
    "kernel_arch_regex":null,
    "supported_arches":["i386","amd64"],
    "supported_repo_breeds":["apt"],
    "kernel_file":"linux(.*)",
    "initrd_file":"initrd(.*)\\.gz",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample.seed",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]

#Ubuntu 19.04
    "disco": {
    
    
    "signatures":["dists", ".disk"],
    "version_file":"Release|mini-info",
    "version_file_regex":"Codename: disco|Ubuntu 19.04",
    "kernel_arch":"linux-headers-(.*)\\.deb",
    "kernel_arch_regex":null,
    "supported_arches":["i386","amd64"],
    "supported_repo_breeds":["apt"],
    "kernel_file":"linux(.*)",
    "initrd_file":"initrd(.*)\\.gz",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample.seed",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]

#Ubuntu 19.10
    "eoan": {
    
    
    "signatures":["dists", ".disk"],
    "version_file":"Release|mini-info",
    "version_file_regex":"Codename: eoan|Ubuntu 19.10",
    "kernel_arch":"linux-headers-(.*)\\.deb",
    "kernel_arch_regex":null,
    "supported_arches":["i386","amd64"],
    "supported_repo_breeds":["apt"],
    "kernel_file":"linux(.*)",
    "initrd_file":"initrd(.*)\\.gz",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample.seed",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]
    
#重启服务
systemctl restart cobblerd.service   

猜你喜欢

转载自blog.csdn.net/qq_41938046/article/details/114309509