龙之介大人

Cobbler 自动化安装
1. Cobbler 简介1、Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快...
扫描右侧二维码阅读全文
06
2020/06

Cobbler 自动化安装

1. Cobbler 简介

1、Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCPDNS等。
2、Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
3、Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4、Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet

2. Cobbler对应关系

img

Cobbler的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。

  • 发行版(distros): 表示一个操作系统。它承载了内核和initrd的信息,以及内核参数等其他数据。
  • 配置文件(profiles):包含一个发行版、一个kickstart文件以及可能的存储库,还包括更多特定的内核参数等其他数据。
  • 系统(systems):表示要配给的机器。它包括一个配置文件或一个镜像、IPMAC地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息。
  • 镜像(images):可以替换一个保函不屑于此类别的文件的发行版对象(例如,无法分为内核和initrd的对象)。

3.Cobbler集成的服务

  • PXE服务支持
  • DHCP服务管理
  • DNS服务管理
  • 电源管理
  • Kickstart服务支持
  • YUM仓库管理
  • TFTP
  • Apache

4.Cobbler工作原理

img

Server端

  • 启动Cobbler服务
  • 进行Cobbler错误检查,执行cobbler check命令
  • 进行配置同步,执行cobbler sync命令
  • 复制相关启动文件到TFTP目录中
  • 启动DHCP服务,提供地址分配
  • DHCP服务分配IP地址
  • TFTP传输启动文件
  • Server端接收安装信息
  • Server端发送ISO镜像与Kickstart文件

Client端

  • 客户端以PXE模式启动
  • 客户端获取IP地址
  • 通过TFTP服务器获取启动文件
  • 进入Cobbler安装选择界面
  • 根据配置信息准备安装系统
  • 加载Kickstart文件
  • 传输系统安装的其它文件
  • 进行安装系统

5 .Cobbler安装

虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。

image-20200606173232352

5.1 部署约定

服务状态
selinuxdisabled
firewallddisabled

5.2安装cobbler

  • 安装方式
#安装epel源
yum install -y epel-release.noarch

#安装cobbler和dhcp 存在依赖关系其他的服务会自动安装
yum install cobbler dhcp
  • 程序版本及配置文件位置
应用名称版本安装方式配置文件目录
Cobbler2.8.5YUM/etc/cobbler/settings
DHCP4.2.5YUM/etc/cobbler/dhcpd.conf.template
Apache2.4.6YUM/etc/httpd/conf.d/(cobbler.conf & cobbler_web.conf)
Xinetd2.3.15YUM/etc/xinetd.conf
TFTP5.2-22YUM/etc/xinetd.d/tftp
pykickstart1.99.66YUM-
  • 添加开机启动
#添加开机自启
[root@cobbler ~]# systemctl enable httpd.service cobblerd.service dhcpd.service tftp.socket 

#开启服务
[root@cobbler ~]# systemctl start cobblerd.service httpd.service tftp.socket 
  • 安装后相关文件
#Cobbler相关文件
[root@cobbler ~]# rpm -ql cobbler
/etc/cobbler                  # 配置文件目录
/etc/cobbler/settings         # cobbler主配置文件,这个文件是YAML格式,Cobbler是python写的程序。
/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日志

#tftp目录
[root@cobbler ~]# tree -L 1 /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
├── etc
├── grub
├── images
├── images2
├── ppc
├── pxelinux.cfg
└── s390x

5.3 配置Cobbler

执行cobbler check命令检查存的问题,而后逐一按提示解决之。如果没有下面消息就再次重启cobbler常见的问题如下所示:

[root@cobbler ~]# 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 : ksvalidator was not found, install pykickstart
8 : 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
9 : 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、修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名,如10.10.2.27;
    2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如172.16.100.16;
    3、如果当前节点可以访问互联网,执行cobbler get-loaders命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中;
    4、执行cobbler sync把下载的文件同步到tftp的目录;

    5、执行chkconfig rsync on命令(可选);
    6、执行openssl passwd -1 -salt $(openssl rand -hex 4)生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
    7、执行yum install cman fence-agents命令安装相应的程序包即可(可选);

  • 配置cobbler的配置文件实现自动生成dhcp的配置文件

    #settings文件
    # set to 1 to enable Cobbler's DHCP management features.
    # the choice of DHCP management engine is in /etc/cobbler/modules.conf
    manage_dhcp: 1
    
    #dhcp.template文件
    subnet 10.10.2.0 netmask 255.255.255.0 {
         option routers             10.10.1.1;
         option domain-name-servers 223.5.5.5;
         option subnet-mask         255.255.255.0;
         range dynamic-bootp        10.10.2.30 10.10.2.230;
         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";
              }
         }
    
    }
    1. 修改/etc/cobbler/settings文件中的manage_dhcp1
    2. 修改/etc/cobbler/dhcp.template文件中的信息.
    3. 修改完成后执行cobbler sync同步
  • 测试:
测试注意:开启tftp;

image-20200606182543247

5.4 Cobbler命令帮助

命令说明
cobbler check核对当前设置是否有问题
cobbler list列出所有的cobbler元素
cobbler report列出元素的详细信息
cobbler sync同步配置到数据目录,更改配置最好都执行一下
cobbler reposync同步yum仓库
cobbler distro查看导入的发行版系统信息
cobbler system查看添加的系统信息
cobbler profile查看配置信息

5.5 导入安装镜像

5.5.1 挂载镜像

  • 挂载CentOS7.7镜像:
mount -t iso9660 -o loop /dev/sr1 /mnt/centos7
  • 挂载CentOS6.10镜像:
mount -t iso9660 -o loop /dev/sr0 /mnt/centos6

5.5.2 导入镜像

  • 导入Centos6.10:
cobbler import --path=/mnt/centos6/ --name=CentOS-6.10-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos6.9,如果重复,系统会提示导入失败。
  • 导入CentOS7.7:
cobbler import --path=/mnt/centos7/ --name=CentOS-7.7-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:centos6.9,如果重复,系统会提示导入失败。

5.5.3 查看导入的镜像

  • 查看导入的list
[root@cobbler ~]# cobbler distro list
   CentOS-6.10-x86_64
   CentOS-7.7-x86_64
[root@cobbler ~]# cobbler distro report --name=CentOS-6.10-x86_64
Name                           : CentOS-6.10-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-6.10-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-6.10-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-6.10-x86_64'}
Management Classes             : []
OS Version                     : rhel6
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}


[root@cobbler ks_mirror]# cobbler distro report --name=CentOS-7.7-x86_64
Name                           : CentOS-7.7-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : redhat
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/CentOS-7.7-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/CentOS-7.7-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.7-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}
  • 查看profile信息
[root@cobbler ~]# cobbler profile report --name=CentOS-6.10-x86_64
Name                           : CentOS-6.10-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-6.10-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

[root@cobbler ks_mirror]# cobbler profile report --name=CentOS-7.7-x86_64
Name                           : CentOS-7.7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-7.7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

5.5.4 自定义Kickstart

  • CentOS6:
由于默认的ks文件不满足我们的安装需求,所以我们要使用自定义的ks文件,修改Kickstart文件如下:
#动态编辑指定使用新的kickstart文件
cobbler profile edit --name=CentOS-6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.ks

#验证是否更改成功
[root@cobbler ~]# cobbler profile report --name=cobbler profile edit --name=CentOS-6.10-x86_64 | grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos6.ks
Kickstart Metadata             : {}
  • CentOS7:
修改Kickstart文件:
#动态编辑指定使用新的kickstart文件
[root@cobbler ~]# cobbler profile edit --name=CentOS-7.7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.ks

#验证是否更改成功
[root@cobbler ks_mirror]# cobbler profile report --name=CentOS-7.7-x86_64 | grep Kickstart
Kickstart                      : /var/lib/cobbler/kickstarts/centos7.ks
Kickstart Metadata             : {}
调整网卡内核参数(标准化,名称统一,关闭IPv6
[root@cobbler ~]# cobbler profile edit --name=CentOS-7.7-x86_64 --kopts='net.ifnames=0 biosdevname=0 noipv6'
  • 同步Cobbler配置文件
[root@cobbler ~]# cobbler sync

5.5.5 查看全局profile配置

[root@cobbler ~]# cobbler profile report
Name                           : CentOS-7.7-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-7.7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {'noipv6': '~', 'biosdevname': '0', 'net.ifnames': '0'}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/centos7.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                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

Name                           : CentOS-6.10-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS-6.10-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/centos6.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                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm

6.虚拟机测试:

  • 引导测试:

image-20200606215234366

  • CentOS6:

image-20200606215803998

  • CentOS7:

image-20200606222924263

7.Web管理界面配置

web界面有很多功能,包括上传镜像、编辑kickstart、等等很多在命令行操作的都可以在web界面直接操作。
在上面已经安装了cobbler-web软件,访问地址:https://IP/cobbler_web 即可。默认账号为cobbler,密码也为`cobbler

  • 安装WEB管理界面:
yum install cobbler-web -y

image-20200606230745621

7.1 修改密码

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

[root@cobbler ~]# cat /etc/cobbler/users.digest 
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3

# 设置密码,在Cobbler组添加cobbler用户,输入2遍密码确
[root@cobbler ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler
Changing password for user cobbler in realm Cobbler
New password: superman
Re-type new password: superman

# 同步配置并重启httpd、cobbler
[root@cobbler ~]# cobbler sync
[root@cobbler ~]# systemctl restart httpd
[root@cobbler ~]# systemctl restart cobblerd
再次登录即使用新设置的密码登录即可。
最后修改:2020 年 06 月 06 日 11 : 17 PM

1 条评论

  1. b2b系统

    感谢分享

发表评论