Automatic installation system (3)

Cobbler

Introduction

Cobbler is an automated operation and maintenance tool for Linux ecology, developed based on Python2, and used to automate batch deployment and installation of operating systems
; it provides a CLI-based management method and a WEB configuration interface, of which the WEB configuration interface is developed based on Python2 and the Django framework. In addition, cobbler also provides an API to facilitate secondary development. Cobbler belongs to the C/S model (client/server model);

Cobbler is mainly used for fast network installation of linux operating system, supports many Linux distributions such as: Red Hat, Fedora, CentOS, Debian, Ubuntu and SuSE, etc., and even supports the installation of windows.

Cobbler is essentially the secondary packaging of PXE, which encapsulates various installation parameters and provides a unified management method

Cobbler performs related operations on the basis of various services such as HTTP, TFTP, and DHCP. The actual installation process is similar to the PXE-based network installation: the client (bare metal) boots with the network card to boot, and requests DHCP to assign an address. Obtain the startup file from the TFTP server, load it into the local memory of the client to run, and display a list of systems that can be installed; after artificially selecting the type of operating system to be installed, the client will download the corresponding system installation file from the HTTP server and perform automatic installation

working principle

  • After the bare metal client is configured to start from the network, it will broadcast a packet after booting to request the DHCP server (cobbler server) to send an IP assigned by it.
  • The DHCP server (cobbler server) sends a response after receiving the request, including its ip address
  • After the bare metal client gets the ip, it sends a request for the OS boot file to the cobbler server
  • The cobbler server tells the name of the bare metal OS boot file and the ip and port of the TFTP server
  • The client bare metal communicates through the TFTP server address notified above, and downloads the boot file
  • The client executes the boot file on bare metal, determines the loading information, and selects the os to be installed. During this period, it will request the kickstart file and os image from the cobbler server
  • Cobbler server sends the requested kickstart and os iamge
  • The client bare metal loads the kickstart file
  • The client bare metal receives the os image and installs the os image

Related documents

configuration file

/etc/cobbler/settings  #cobbler 主配置文件 
/etc/cobbler/iso/  #iso模板配置文件
/etc/cobbler/pxe   #pxe模板文件
/etc/cobbler/power  #电源配置文件 
/etc/cobbler/user.conf   #web服务授权配置文件 
/etc/cobbler/users.digest  #web访问的用户名密码配置文件 
/etc/cobbler/dhcp.template #dhcp服务器的的配置模板
/etc/cobbler/dnsmasq.template #dns服务器的配置模板
/etc/cobbler/tftpd.template  #tftp服务的配置模板
/etc/cobbler/modules.conf #cobbler模块的配置文件

data directory

/var/lib/cobbler/config/     #用于存放distros,system,profiles 等信息的配置文件
/var/lib/cobbler/triggers/   #用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstarts/  # 默认存放kickstart文件
/var/lib/cobbler/loaders/     #存放各种引导程序

mirror directory

/var/www/cobbler/ks_mirror/    #导入的发行版系统的所有数据
/var/www/cobbler/images/       #导入发行版kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/   #yum 仓库存储目录

log directory

/var/log/cobbler/installing  #客户端安装日志 
/var/log/cobbler/cobbler.log #cobbler日志

Related commands

cobbler check to check if there is any problem with the current settings
cobbler list lists all cobbler elements
cobbler report lists the detailed information of the elements
cobbler sync synchronizes the configuration to the data directory, it is best to execute the
cobbler reposync to synchronize the yum warehouse
cobbler distro to view the imported ones Release version system information, get more command help through cobbler distro --help
cobbler system view added system information
cobbler profile view configuration information

common usage

#列出当前导入的linux发行版条目
cobbler distro list 
#报告当前所有的linux发行版详细信息
cobbler distro report 

#列出启动菜单条目
cobbler profile list

#导入系统源文件生成仓库。 实质是复制源镜像文件。
#--name指明目录名称,--paht指明源镜像文件路径,--arch指明架构,可选
#cobbler将系统yum源文件存放在 /var/www/cobbler/ks_mirror目录下
cobbler import --name=centos-8.0-x86_64 --path=/mnt --arch=x86_64


#新增启动菜单条目 并将linux发行版系统与其对应的ks文件建立关联。
#-- name指定新增的菜单条目,--distro指定发行版镜像,--kickstart指定自定义的ks文件
cobbler profile add --name=centos7 --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg 

#在导入发行版系统是会自动生成distro发行版列表,使用下面命令删除指定发行版条目再使用上面命令关联自定义的ks
cobbler profile remove --name=PROFILE_NAME

experiment

centos7 realizes system automation installation based on Cobbler

environment

NAT mode, turn off the DHCP function of vmware

centos7 (192.168.28.141), deploy cobbler, dhcp, httpd, tftp

Close firewalld and selinux

Software package: cobbler (the cobbler package is located in the epel source, httpd and tftp will be automatically installed when the dependencies are resolved during installation), dhcp

process

Install packages on centos7

[root@localhost ~]# yum -y install cobbler dhcp
[root@localhost ~]# systemctl enable --now cobblerd httpd tftp dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.
#DHCP未配置直接启动会报错

If it is found that the systemctl status cobblerd service is started but an error is reported: cannot touch '/usr/share/cobbler/web/cobbler.wsgi': No such file or directory, it is because cobbler-web is not installed, optional

Modify the cobbler configuration

#cobbler需要配置的提示信息
[root@localhost ~]# 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.  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.
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.

#修改 /etc/cobbler/settings
[root@localhost ~]# vim /etc/cobbler/settings
...
#指定cobbler服务器IP
server: 192.168.28.141
...
#指定tftp服务器IP
next_server: 192.168.28.141
...
#设置root加密后的密码,默认是cobbler,通过openssl passwd -数字 密码 生成加密后的密码
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
...
#默认0,cobbler不管dhcp,需要手动配置dhcp;现改为1,通过cobbler生成dhcp配置文件
manage_dhcp: 1
...

#再次运行cobbler check会发现提示信息发生变化
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : change 'disable' to 'no' in /etc/xinetd.d/tftp
2 : Some network boot-loaders are missing from /var/lib/cobbler/loaders.  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.
3 : enable and start rsyncd.service with systemctl
4 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5 : ksvalidator was not found, install pykickstart
6 : 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
7 : 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.


#cobbler的DHCP模版文件,修改此文件cobbler会自动生成dhcp配置文件
[root@localhost ~]# vim /etc/cobbler/dhcp.template
...
subnet 192.168.28.141 netmask 255.255.255.0 {
     option routers             192.168.28.2;
     option domain-name-servers 180.76.76.76,223.5.5.5;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.28.145 192.168.28.149;
     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";
          }
     }

}
...

#联网下载启动相关文件,会存放在 /var/lib/tftpboot/ 目录下
[root@localhost ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│   └── grub
│       └── menu.lst
├── etc
├── grub
│   ├── efidefault
│   └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── s390x
    └── profile_list

10 directories, 7 files
[root@localhost ~]# cobbler get-loaders
No such command: get-loaders

Step on the pit:

When executing cobbler get-loaders, it prompts that there is no such command. Just install yum -y install syslinux

#修改启动菜单标题模版
[root@localhost ~]# vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
# |后面是自定义标题
MENU TITLE Cobbler | WenZi Cobbler Menu
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end
#查看自动生成的启动菜单
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | WenZi Cobbler Menu
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1



MENU end


#导入系统镜像资源  虚拟机新加centos6/8 的镜像
[root@localhost ~]# mkdir /mnt/centos{6,7,8}
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sr0              11:0    1  3.7G  0 rom
sr1              11:1    1  7.7G  0 rom
sr2              11:2    1  4.4G  0 rom
[root@localhost ~]# mount /dev/sr0 /mnt/centos6
[root@localhost ~]# mount /dev/sr2 /mnt/centos7
[root@localhost ~]# mount /dev/sr1 /mnt/centos8
#cobbler将系统yum源文件存放在 /var/www/cobbler/ks_mirror目录下
[root@localhost ~]# cobbler import --name=centos-8.2-x86_64 --path=/mnt/centos8 --arch=x86_64
[root@localhost ~]# cobbler import --name=centos-7.0-x86_64 --path=/mnt/centos7 --arch=x86_64
[root@localhost ~]# cobbler import --name=centos-6.8-x86_64 --path=/mnt/centos6 --arch=x86_64
#导入后重启、同步
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
[root@localhost ~]# tree -d /var/www/cobbler/ks_mirror/
/var/www/cobbler/ks_mirror/
├── centos-6.8-x86_64
│   ├── EFI
│   │   └── BOOT
│   ├── images
│   │   └── pxeboot
│   ├── isolinux
│   ├── Packages
│   └── repodata
├── centos-7.0-x86_64
│   ├── EFI
│   │   └── BOOT
│   │       └── fonts
│   ├── images
│   │   └── pxeboot
│   ├── isolinux
│   ├── LiveOS
│   ├── Packages
│   └── repodata
├── centos-8.2-x86_64
│   ├── AppStream
│   │   ├── Packages
│   │   └── repodata
│   ├── BaseOS
│   │   ├── Packages
│   │   └── repodata
│   ├── EFI
│   │   └── BOOT
│   │       └── fonts
│   ├── images
│   │   └── pxeboot
│   └── isolinux
└── config

32 directories
#查看以导入的发行版信息
[root@localhost ~]# cobbler distro list
   centos-6.8-x86_64
   centos-7.0-x86_64
   centos-8.2-x86_64
#此时已经自动生成启动菜单文件,已关联ks文件
[root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | WenZi Cobbler Menu
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL centos-6.8-x86_64
        kernel /images/centos-6.8-x86_64/vmlinuz
        MENU LABEL centos-6.8-x86_64
        append initrd=/images/centos-6.8-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos-6.8-x86_64
        ipappend 2

LABEL centos-7.0-x86_64
        kernel /images/centos-7.0-x86_64/vmlinuz
        MENU LABEL centos-7.0-x86_64
        append initrd=/images/centos-7.0-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos-7.0-x86_64
        ipappend 2

LABEL centos-8.2-x86_64
        kernel /images/centos-8.2-x86_64/vmlinuz
        MENU LABEL centos-8.2-x86_64
        append initrd=/images/centos-8.2-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos-8.2-x86_64
        ipappend 2



MENU end




#若使用自定义ks应答文件,则如下
#将写好的ks应答文件复制到 /var/lib/cobbler/kickstarts目录下
[root@localhost ~]# ls
anaconda-ks.cfg  centos6_ks.cfg  centos7_ks.cfg  centos8_ks.cfg
[root@localhost ~]# cp centos* /var/lib/cobbler/kickstarts/
#将ks文件中 url  改为 url --url=$tree
[root@localhost ~]# vim /var/lib/cobbler/kickstarts/centos6_ks.cfg
[root@localhost ~]# vim /var/lib/cobbler/kickstarts/centos7_ks.cfg
[root@localhost ~]# vim /var/lib/cobbler/kickstarts/centos8_ks.cfg
#删除导入镜像时自动生成的发行版条目(菜单选项)
[root@localhost ~]# cobbler profile remove --name=centos-8.2-x86_64
[root@localhost ~]# cobbler profile remove --name=centos-7.0-x86_64
[root@localhost ~]# cobbler profile remove --name=centos-6.8-x86_64
[root@localhost ~]# cobbler profile list
#新增6/7/8的启动菜单并将各自镜像与各自ks文件对应
[root@localhost ~]# cobbler profile add --name=centos6_wenzi --distro=centos-6.8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6_ks.cfg
[root@localhost ~]# cobbler profile add --name=centos7_wenzi --distro=centos-7.0-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7_ks.cfg
[root@localhost ~]# cobbler profile add --name=centos8_wenzi --distro=centos-8.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8_ks.cfg
#启动菜单列表
[root@localhost ~]# cobbler profile list
   centos6_wenzi
   centos7_wenzi
   centos8_wenzi
#镜像列表
[root@localhost ~]# cobbler distro list
   centos-6.8-x86_64
   centos-7.0-x86_64
   centos-8.2-x86_64
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
#查看菜单配置
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | WenZi Cobbler Menu
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL centos6_wenzi
        kernel /images/centos-6.8-x86_64/vmlinuz
        MENU LABEL centos6_wenzi
        append initrd=/images/centos-6.8-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos6_wenzi
        ipappend 2

LABEL centos7_wenzi
        kernel /images/centos-7.0-x86_64/vmlinuz
        MENU LABEL centos7_wenzi
        append initrd=/images/centos-7.0-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos7_wenzi
        ipappend 2

LABEL centos8_wenzi
        kernel /images/centos-8.2-x86_64/vmlinuz
        MENU LABEL centos8_wenzi
        append initrd=/images/centos-8.2-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos8_wenzi
        ipappend 2



MENU end
#查看详细信息
[root@localhost ~]# cobbler report

test

Step on the pit:

There is a problem when installing centos8 automatically, and it stays on the download file page for two or three minutes

Then an error occurs, it feels like the kickstart file was not found

dracut- initqueue:Warning:dracut- initqueue timeout - starting timeout scripts

Check the centos8 ks file address ks=http://192.168.28.141/cblr/svc/op/ks/profile/centos8_wenzi in /var/lib/tftpboot/pxelinux.cfg/default, and find that ks cannot be viewed normally through browser access file content, web page prompt

# This kickstart had errors that prevented it from being rendered correctly.
# The cobbler.log should have information relating to this failure.

Check the log /var/log/cobbler/cobbler.log, it is related to language characters.

When installing centos8, I used the automatic installation system (2)_penluo_风雨的博客-CSDN blog ks file, including Chinese comments, delete the Chinese part, systemctl restart cobbler, regenerate and configure cobbler sync, just It worked.

Guess you like

Origin blog.csdn.net/qq_40875048/article/details/132331167