O&M automation and Cobbler service deployment

O&M automation and Cobbler service deployment

1. Introduction to Cobbler

1.1. Introduction

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

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

  • Before cobbler, Microsoft had developed another similar technology based on the C/S working mode, PXE (Prebot eXecute
    Environment, pre-boot execution environment), which supports booting the operating system through the network, and also allows users who need to install the system to support it.
    The bare metal of the PEX technology network card is installed by downloading the image from the http server through the network. During the startup process, the client needs to
    obtain the IP address, mask, gateway and related configuration file path from the dhcp server, and then use TFTP (trivial file transfer
    protocol) The protocol downloads a bootable software package (similar to the files under the isolinux folder of the Linux CD) from the server and loads it
    into the local memory for execution. The ks answer file specified in the configuration file in the startup software package indicates the location of the operating system in the server , and then
    find the installation source, and complete the installation of the operating system under the guidance of the ks file.

  • Cobbler is essentially a secondary encapsulation of PXE, which encapsulates various installation parameters and provides a unified management method.

1.2. Cobbler's Subordinate Services

  • Using Cobbler to install the system requires a server dedicated to providing various services, including (HTTP/FTP/NFS,
    TFTP, DHCP), and these services can also be deployed to different servers. In fact, in practical applications, different services are always
    deployed to dedicated servers.

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

2. Cobbler installation

2.1. Install epel source

  • Cobbler comes from the epel source. Before installing cobbler, you need to configure the epel source, or use the command to install the epel source directly:
    [root@mainserver ~]#wget -O /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo

2.2. Install Cobbler and its related services and components

  • The services under Cobbler include HTTPD, TFTP, DHCP, etc. If there is a web interface requirement, you need to install related components

[root@mainserver ~]#yum install -y httpd dhcp tftp-server cobbler cobbler-web pykickstart xinetd

httpd:配合cobbler-web使得cobbler可以通过web网页界面进行配置管理
tftp-server.x86_64 : The server for the Trivial File Transfer Protocol (TFTP)
cobbler-web.noarch : Web interface for Cobbler
pykickstart.noarch : 基于python的管理kickstart文件的库
xinetd.x86_64 : A secure replacement for inetd

3. Cobbler configuration

3.1. Cobbler configuration file and each directory

  • 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日志

3.2. Configure and start cobblerd service

  • When the httpd, tftp and dhcp services are running normally, you can start the cobblerd service for related configuration.
  • start cobblerd
    systemctl start cobbler
  • Detect the operating environment of cobbler, and configure cobbler step by step according to the prompts
    cobbler check
1.更改/etc/xinetd.d/tftp配置文件
vim /etc/xinetd.d/tftp
disable  =  yes  -->  disable  =  no
systemctl restart xinetd
2.联网下载boot引导程序文件
cobbler get-loaders
3.没有网络情况下拷贝启动文件到TFTP服务文件夹
cp -a /usr/share/syslinux/{
    
    pxelinux.0,menu.c32}  /var/lib/tftpboot
4.更改/etc/cobbler/settings配置文件的server项为提供cobblerd服务的主机地址,也就是本机地址
sed -nri 's#server:172.0.0.1#server:192.168.31.17#' /etc/cobbler/settings
更改后的整行内容:server:192.168.131.17
5.更改/etc/cobbler/settings配置文件的next_server项,指明tftp服务器地址,使得客户端能够找
到TFTP服务器
sed -i 's/next_server: 127.0.0.1/next_server: 192.168.56.11/' /etc/cobbler/settings
更改后的整行内容:next_server:192.168.131.17
6.配置相应的选项来使用cobbler管理dhcp服务和tftp服务
manage_dhcp:1
manage_tftpd:1
7.pxe_just_once选项,该选项置1表示在pxe安装块结束时在cobbler系统中做相应的记录,这样会避免如果客户机的BIOS选项中PXE启动处于第一位导致的循环重启;如果第一个启动硬件不是PXE启动那就置0。
pxe_just_once:1  
  • Reboot after configuration is complete
    systemctl restart cobblerd

Four. Cobbler use

4.1 Usage

  • The ones in '<>' are mandatory options, and the ones in '[]' are optional
[root@old_centos7 ~]#cobbler
usage
=====
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]
  • You can use the following methods to get help
    [root@old_centos7 ~]cobbler
    [root@old_centos7 ~]cobbler --help
[root@old_centos7 ~]#cobbler distro --help
usage
=====
cobbler distro add
cobbler distro copy
cobbler distro edit
cobbler distro find
cobbler distro list
cobbler distro remove
cobbler distro rename
cobbler distro report
[root@old_centos7 ~]#cobbler distro add --help
Usage: cobbler [options]

Options:
  -h, --help            show this help message and exit
  --name=NAME           Name (Ex: Fedora-11-i386)
  --ctime=CTIME
  --mtime=MTIME
  --uid=UID       Owners (Owners list for authz_ownership (space delimited))
......
  • For example,
    cobbler distro listlist the currently imported linux distribution entries,
    cobbler distro reportreport the details of all current linux distributions,
    cobbler profile --name=centos7 --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfgassociate the linux distribution system image with its corresponding ks file

4.2 Configure the linux distribution and associate the corresponding ks file

4.2.1 Copy the ks file prepared in advance

[root@old_centos7 ~]#cp /var/www/html/ksdir/ks{6,7,8}.ks /var/lib/cobbler/kickstarts

4.2.2 Import the linux distribution into cobbler's httpd service folder

  • Cobbler's service folder in httpd is located at/var/www/cobbler/ks_mirror
    cobbler import --name=centos6 --path=/var/www/html/centos/6/isos/x86_64/ --arch=x86_64
    cobbler import --name=centos7 --path=/var/www/html/centos/7/isos/x86_64/ --arch=x86_64
    cobbler import --name=centos8 --path=/var/www/html/centos/8/isos/x86_64/ --arch=x86_64

4.2.3 Restart and sync after import

systemctl restart cobblerd
cobbler sync

[root@old_centos7 /var/www/cobbler/ks_mirror]#ls
centos6-x86_64  centos-7.5-x86_64  centos7-x86_64  centos8-x86_64  config
# centos-7.5-x86_64 为cobbler默认创建的,里面无镜像
[root@old_centos7 /var/www/cobbler/ks_mirror]#ls -lh centos-7.5-x86_64/
total 0
[root@old_centos7 /var/www/cobbler/ks_mirror]#ls -lh centos6-x86_64/
total 276K
-r--r--r-- 1 root root   14 Jun 29  2018 CentOS_BuildTag
dr-xr-xr-x 3 root root   35 Jun 29  2018 EFI
-r--r--r-- 1 root root  212 Nov 27  2013 EULA
-r--r--r-- 1 root root  18K Nov 27  2013 GPL
dr-xr-xr-x 3 root root   95 Jun 29  2018 images
dr-xr-xr-x 2 root root  198 Jun 29  2018 isolinux
dr-xr-xr-x 2 root root 176K Jun 29  2018 Packages
-r--r--r-- 1 root root 1.4K Jun 29  2018 RELEASE-NOTES-en-US.html
dr-xr-xr-x 2 root root 4.0K Jun 29  2018 repodata
-r--r--r-- 1 root root 1.7K Nov 27  2013 RPM-GPG-KEY-CentOS-6
-r--r--r-- 1 root root 1.7K Nov 27  2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 1 root root 1.7K Nov 27  2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 1 root root 1.7K Nov 27  2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 root root 3.4K Jun 29  2018 TRANS.TBL

4.2.4 Associate the linux distribution system image with its corresponding ks file

cobbler profile --name=centos6 --distro=centos6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6.cfg
cobbler profile --name=centos7 --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg
cobbler profile --name=centos8 --distro=centos8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks8.cfg

  • Note that when importing distro, cobbler will automatically generate distro entries, which are not associated with ks files, you can delete them and
    cobbler profile remove --name=PROFILE_NAMEthen associate ks files.

4.2.5 Restart and synchronize after establishing association

systemctl restart cobblerd
cobbler sync

4.2.6 View detailed information

cobbler report

[root@old_centos7 ~]#cobbler report
distros:
==========
Name                           : centos7-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {
    
    }
Breed                          : redhat
Comment                        : 
Fetchable Files                : {
    
    }
Initrd                         : /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos7-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {
    
    }
Kernel Options (Post Install)  : {
    
    }
Kickstart Metadata             : {
    
    'tree': 'http://@@http_server@@/cblr/links/centos7-x86_64'}
Management Classes             : []
OS Version                     : rhel7
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {
    
    }

Name                           : centos8-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {
    
    }
Breed                          : redhat
Comment                        : 
Fetchable Files                : {
    
    }
Initrd                         : /var/www/cobbler/ks_mirror/centos8-x86_64/images/pxeboot/initrd.img
Kernel                         : /var/www/cobbler/ks_mirror/centos8-x86_64/images/pxeboot/vmlinuz
Kernel Options                 : {
    
    }
Kernel Options (Post Install)  : {
    
    }
Kickstart Metadata             : {
    
    'tree': 'http://@@http_server@@/cblr/links/centos8-x86_64'}
Management Classes             : []
OS Version                     : rhel8
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {
    
    }

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                 : {
    
    }


profiles:
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                      : xenpv

Name                           : Install_centos6
TFTP Boot Files                : {
    
    }
Comment                        : 
DHCP Tag                       : default
Distribution                   : centos6-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {
    
    }
Kernel Options                 : {
    
    }
Kernel Options (Post Install)  : {
    
    }
Kickstart                      : /var/lib/cobbler/kickstarts/ks6.cfg
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                      : xenpv


systems:
==========

repos:
==========

images:
==========

mgmtclasses:
==========

packages:
==========

files:
==========
  • There is a line in the above information as follows:
    Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos8-x86_64'}
  • The definition of this line is in the file [root@old_centos7 ~]#vim /var/www/cobbler/ks_mirror/config/centos8-x86_64.repo
    , which is specified by cobbler's own syntax for defining the installation source path, so it can be in the ks file When specifying the installation
    source in , it is directly specified as a tree variable. ( url − − url = tree variable. (url --url=t tree variable. ( u r lurl=tree)
[root@old_centos7 ~]#vim /var/www/cobbler/ks_mirror/config/centos8-x86_64.repo
[core-0]
name=core-0
baseurl=http://@@http_server@@/cobbler/ks_mirror/centos8-x86_64/AppStream
enabled=1
gpgcheck=0
priority=$yum_distro_priority

5. Test installation

5.1 Create a new virtual machine


  • Set its network type to NAT and bridge to the same VMnet8 as the server, configure memory more than 1G when installing centos6, and configure memory greater than 1.6G when installing centos7 and centos8

5.2 Use PXE network boot to start

5.3 Select the corresponding version to install

6. Optimization

6.1 Menu optimization

  • Modify the /etc/cobbler/pxe/pxedefault.template template file and restart the synchronization
[root@old_centos7 ~]#vim /etc/cobbler/pxe/pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Welcome! | suosuoli.cn      # 自定义项
TIMEOUT 200 
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile

LABEL local
        MENU LABEL (local installation) # 自定义项1
        MENU DEFAULT
        LOCALBOOT -1

$pxe_menu_items

MENU end
[root@old_centos7 ~]#systemctl restart cobblerd
[root@old_centos7 ~]#cobbler sync
  • After restarting the synchronization, cobbler updates the file /var/lib/tftpboot/pxelinux.cfg/default
[root@old_centos7 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Welcome! | suosuoli.cn
TIMEOUT 200 
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local installation)
        MENU DEFAULT
        LOCALBOOT -1
LABEL Install_centos6
        kernel /images/centos6-x86_64/vmlinuz
        MENU LABEL Install_centos6
        append initrd=/images/centos6-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.131.17/cblr/svc/op/ks/profile/Install_centos6
        ipappend 2

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

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



MENU end 

6.2 Use httpd service and cobbler-web to manage and configure cobbler based on web interface

6.2.1 Install cobbler-web

yum install cobbler-web

6.2.2 Restart http service

systemctl restart httpd

6.2.3 Accessing the web interface

https://cobblerserver/cobbler_web

七.Trouble Shooting

  • Encountered the following situation?

    • In this case, the installation source path in the ks file is wrong, change it to the following:
      centos6: url --url=http://httpserver/ksdir/ks.cfgor url --url=$tree
      centos7: url --url=http://httpserver/ksdir/ks.cfgor url --url=$tree
      centos8: url --url=http://httpserver/ksdir/ks.cfgorurl --url=$tree
  • Encountered the following situation?

    • This is because the httpd service has been running when the cobbler is installed and configured, and the service for the cobbler is not provided correctly,
      so restarting the httpd service is oksystemctl restart httpd
  • Encountered the following situation?

  • Cannot access the https://cobblerserver/cobbler-web management interface after installing the cobbler-web package while the httpd service is running?

    • Restart the httpd service:systemctl restart httpd
  • Default account for cobbler-web interface

login:cobbler
passwd:cobbler
  • Cobbler access diagram

insert image description here
The default account passwords are: cobbler
insert image description here
insert image description here
insert image description here

⬅️exit

Guess you like

Origin blog.csdn.net/wang11876/article/details/132645395