Install the operating system using COBBLER batch

Personal blog address:http://www.pojun.tech/Welcome to visit

Foreword< /h1>

In actual production, We often encounter such a situation that we need to install dozens or even hundreds of servers at the same time. If we use U disk or CD-ROM, perhaps the boss will fire us directly. Here we introduce a way to automate the installation of operating systems.
Our experimental environment for Cobbler is based on CentOS 7.3 -1611.
At the same time, this experiment can help you complete all the operations step by step. However, if you want to customize the content of the installation, it is recommended that you read the Custom kickstart file section of this article first in order to have some impression.

Introduction to Cobbler

The Cobbler project is a network installation server kit released by RedHat in 2008. It is a service for fast network installation of Linux operating system, supports many Linux distributions: Red Hat, Fedora, CentOS, Debian, Ubuntu and SuSE, and also supports network installation of windows.

PXE is a technology developed by Intel, based on the Client/Server network model, which supports remote hosts to download images from remote servers through the network, and thus supports starting through the network operating system. It is also possible to install the operating system in batches via the network.

Cobbler is based on PXE secondary packaging, which encapsulates multiple installation parameters into one menu. Cobbller provides two installation methods, CLI and WEB, which are more user-friendly.

Cobbler workflow

About Cobbler’s workflow, you can use the following diagram to summarize.

Experimental environment preparation

Because we are building a network service , So you need to have at least two hosts, one of which assumes the role of the server. In this experiment, I used the network service built by CentOS 7 to assume the role of Server.

Turn off the firewall and SELinux

Firewall and SELinux may cause unexpected problems during the experiment, so we turn it off here. In actual production, please adjust according to your actual situation. As for turning off the firewall and SELinux, it is not listed, it is very simple.

Install Cobbler< /h2>

Cobbler is not included in the CD by default, so download and install from EPEL source. After configuring the epel source, execute yum install cobbler You can install Cobbler.
After installing Cobbler, we will find that Cobbler also installs many other services, as shown in the figure below. This also explains why so many services can be used in Cobbler’s workflow. As can be seen from the figure, there is still a lack of DHCP service, so we have to install it next. Among them, syslinux is the PXE service installed.

Set common services

Set the Cobbler service to start on boot

systemctl enable cobblerdsystemctl start cobblerd

Set tftp to boot

systemctl enable tftpsystemctl start tftp

Set http to Start on boot

systemctl enable httpdsystemctl start httpd

Install the DHCP service to prepare for the later use of Cobbler to manage DHCP

Later, we will use Cobbler to automatically manage DHCP.

yum install dhcp

Run Cobbler Check to check the environment

Cobbler Check The command can very quickly help us find what is missing in the current environment , And then we adjust the configuration accordingly according to the prompts here. There are a lot of problems here. Don’t panic after you see them. Just follow the prompts to deal with them bit by bit. In addition, because all hosts will be different in the actual production environment, the prompt information here should also be different. We are only solving the problem according to the experimental environment. You can leave a message to discuss the rest of the problem.

#Execute Cobbler check Check what is missing in the current environment [root@localhost~ ]#cobbler checkThe 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 be not work. 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 other must be 0.1 to something. should match the IP of the boot server on the PXE network.3: change'disable' to'no' in /etc/xinetd.d/tftp4: some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run'cobbler get-loaders' to downlo ad 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 to this support folder, exactly. all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The'cobbler get-loaders' command is the easy way to resolve the requirements. 5: enable and start: rsyncctl service is not installed, it will be required to manage debian deployments and repositories7: The default password used by the sample templates for newly installed machines (default_password_crypted in/etc/cobbler/settings) is trying to change the order : "Openssl passwd -1 -salt'random-phrase-here''your-password-here'" to generate new one8: fencing tools were not found, and are required to use the (optional) power management features. fence-agents to use themRestart cobblerd and then run'cobbler sync' to apply changes.

Let’s first look at the first question. Information prompt, in /etc/cobbler/settings The server field in this configuration file must be accessible by other hosts Host name or IP address, otherwise some features of KickStart will not be available. In fact, it is well understood that our current host is used to provide network services. Other hosts download and install the operating system by accessing our Cobbler service. If our Server field cannot be accessed by others, how can it be done! So open the configuration file and modify the server field to be the IP address of the machine.

After the modification is completed, we noticed that there is a prompt message at the end of the previous prompt messageRestart cobblerd and then run'cobbler sync' to apply changes., so let’s run these two commands.

#Restart service[root@localhost~]#systemctlrestartcobblerd#Sync information [root@localhost ~]#cobbler sync...........# Omit the output information in the middle # Check again to see what is still missing. [root@localhost~]#cobbler checkThe following are potential configuration items that you may want to fix:1: For PXE to be functional, the'next_server' field in /etc/cobbler/settings other must be 7.0 set to something. 0.1, and should match the IP of the boot server on the PXE network. 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 messages in this directory, will support all archives in this to support pxelinux.0, menu.c32, elilo.efi, and yaboot. The'cobbler get-loaders' command is the easy way to resolve these requirements.3: enable and start rsyncd.service with systemctlnot install, package, it will be required to manage debian deployments and repositories 5: The default password use d 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 password-here'" to generate new one6: 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 to then run change. 

After rechecking, we found that 2 problems were resolved. Then we move on to the first question. The problem is that the next_server field should also be a specific address, not 127.0.0.1. In fact, this problem is the same as the one we modified above. So we re-modified the address of next_server to the address of our local machine.

After modification, restart the service and synchronize.

#Restart service[root@localhost~]#systemctlrestartcobblerd#Sync information [root@localhost ~]#cobbler sync...........# Omit the output information in the middle # Check again to see what is still missing. [root@localhost~]#cobbler checkThe following are potential configuration items that you may want to fix: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 to this support folder, exactly. all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The'cobbler get-loaders' command is the easy way to resolve the requirements. 2: enable and start: rsyncctl service is not installed, it will be required to manage debian deployments and repositories4: The default password used by the sample templates for newly installed machines (default_password_crypted in/etc/cobbler/settings) is trying to change the order : "Openssl passwd -1 -salt'r andom-phrase-here'your-password-here'" to generate new one5: fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to the n cman and restart run'cobbler sync' to apply changes.

The problems that occurred continue to decrease. Let’s move on to the first message. This message means that in /var/lib/cobbler/loaders Under the path, some necessary files are missing, you can use it. code class=”highlighter-rouge” style=”font-family:Menlo, Monaco, Consolas,’Courier New’, monospace;font-size:16.875px;padding:2px 4px;color:rgb(199,37,78) ;background-color:rgb(249,242,244);white-space:nowrap;”>cobbler get-loaders command to download related files from the network. So, let’s run cobbler get-loaders

# You can see that there is no content in the /var/lib/cobbler/loaders directory [root@localhost~]#ls/var/lib/cobbler/ loaders[root@localhost~]#cobbler get-loaderstask started: 2017-09-20_084605_get_loaderstask started (id=Download Bootloader Content, time=Wed Sep 20 08:46:05 2017)downloading https://cobbler.github.io/ loaders/README to /var/lib/cobbler/loaders/READMEdownloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilodownloading https://cobbler.github. io/loaders/COPYIN G.yaboot to /var/lib/cobbler/loaders/COPYING.yabootdownloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinuxdownloading https://cobbler. github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efidownloading https://cobbler.github.io/loaders/yaboot-1.3.17 to/var/lib /cobbler/loaders/yabootdownloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0downloading https://cobbler.github.io/loaders/menu. c32-3.86 to /var/lib/cobbler/loaders/menu.c32downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efidownloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi*** TASK COMPLETE***

View now/var/lib/cobbler/loaders In the directory, you will find that a lot of content has been downloaded. Then restart and synchronize the service, and run cobbler check to see what problems are left, we will solve them one by one.

#The most critical file in this directory is menu.c32 pxelinux.0[ root@localhost~]#ls/var/lib/cobbler/loadersCOPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 READMECOPYING.syslinux elilo-ia64.efi grub-x86.efi localhost~root pxelinux.0 ]#cobbler checkThe following are potential configuration items that you may want to fix:1: enable and start rsyncd.service with systemctl2: debmirror package is not installed, it will be required and re-managedebian 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-password-her-'your e'" to generate new one4: fencing tools were not found, and are required to use the (optional) power management features. install cman orfence-agents to use themRestart cobblerd and torapp change's pre> 

Next, I will look at the remaining questions. The first two questions are not very important, let's ignore the past. Looking at the third question, this question is to say that a default user password should be set for each newly installed host. And the information suggests to use

openssl passwd -1 -salt'random-phrase-here''your-password-here'

command to generate encrypted User password. If not set, the default user password is cobbler.

#Generate a user password with a password of 123456 [root@localhost~]openssl passwd -1 123456$1$wuX5VyFf$a0Y/HdzHRCbVWhSFnbV8n/

Then replace the generated password with /etc /cobbler/settingsdefault_password_crypted字段中。

修改Cobbler 默认口令

重新启用并同步服务,然后看看还有什么问题。

[root@localhost ~]#cobbler checkThe following are potential configuration items that you may want to fix:1 : enable and start rsyncd.service with systemctl2 : debmirror package is not installed, it will be required to manage debian deployments and repositories3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use themRestart cobblerd and then run 'cobbler sync' to apply changes.

 fencing tools 是在集群环境中才会使用到的工具,我们暂且先不用管。这样一来,关于Cobbler的check 工作我们就完成了。

通过Cobbler 管理DHCP

我们利用DHCP的cobbler 功能来自动管理DHCP,修改 /etc/cobbler/settings 配置文件中的manage_dhcp字段。设置为1,则由Cobbler 来管理DHCP

Cobbler dhcp

修改Cobbler下 /etc/cobbler/dhcp.template 模板文件

 /etc/cobbler/dhcp.template 这个文件是配置DHCP的内容的。但是这个文件是Cobbler来提供的。也就是说,配置好了这个文件,重新启动Cobbler 服务,Cobbler就会自动地替我们管理DHCP。

# 在/etc/cobbler/dhcp.template 找到下面地这段内容进行修改整理。 # 按照自己地要求进行DHCP地配置。 subnet 172.18.2.0 netmask 255.255.255.0 {     option subnet-mask         255.255.255.0;     range dynamic-bootp        172.18.2.100 172.18.2.254;     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 {                  filename "pxelinux.0";                            }     }}

重新启动和同步Cobbler 服务。

# 重新启动服务[root@localhost ~]#systemctl restart cobblerd[root@localhost ~]#cobbler sync........#中间省略很多输出#查看DHCP的配置文件[root@localhost ~]#cat /etc/dhcp/dhcpd.conf # ******************************************************************# Cobbler managed dhcpd.conf file# generated from cobbler dhcp.conf template (Wed Sep 20 01:36:15 2017)# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be# overwritten.# ******************************************************************ddns-update-style interim;allow booting;allow bootp;ignore client-updates;set vendorclass = option vendor-class-identifier;option pxe-system-type code 93 = unsigned integer 16;subnet 172.18.2.0 netm ask 255.255.255.0 {     option subnet-mask         255.255.255.0;     range dynamic-bootp        172.18.2.100 172.18.2.254;     default-lease-time         21600;     max-lease-time             43200;     next-server                172.18.2.77;     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 {                  filename "pxelinux.0";                            }     }}          # group for Cobbler DHCP tag: default     group {     }

制作 yum 源

与PXE不同,Cobbler可以自动帮助我们生成系统安装的yum 源,而不需要我们自己去制作,我们只要指定光盘路径就好了

# 执行下面的命令制作 CentOS 7.3 的启动光盘[root@localhost ~]#cobbler import --path=/misc/cd --name=centos7.3# 然后更换ISO镜像,制作6.9的光盘内容[root@localhost ~]#cobbler import --path=/misc/cd --name=centos6.9

Cobbler 制作的光盘yum源到底放在了什么地方呢? ?

#进入到下面的这个路径下,可以看到这里生成了两个源,其实也就是将光盘里的内容复制过来了而已。 [root@localhost ~]#cd /var/www/cobbler/ks_mirror/[root@localhost ks_mirror]#lscentos6.9  centos7.3  config# 执行下面的命令可以看到,这里已经成功的制作了两个系统yum源。 [root@localhost ks_mirror]#cobbler distro list   centos6.9-x86_64   centos7.3-x86_64

修改启动菜单

yum 源文件创建成功之后,可以进行自定义的配置修改。

# 查看生成的启动菜单文件[root@localhost tftpboot]#cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menuPROMPT 0MENU TITLE Cobbler | http://cobbler.github.io/   #可以修改为自己的标签。 TIMEOUT 200TOTALTIMEOUT 6000ONTIMEOUT localLABEL local                MENU LABEL (local)        MENU DEFAULT        LOCALBOOT -1LABEL centos6.9-x86_64        kernel /images/centos6.9-x86_64/vmlinuz        MENU LABEL centos6.9-x86_64        append initrd=/images/centos6.9-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.18.2.77/cblr/svc/op/ks/profile/centos6.9-x86_64        ipappend 2LABEL centos7.3-x86_64        kernel /images/centos7.3-x86_64/vmlinuz        MENU LABEL centos7.3-x86_64        append initrd=/images/centos7.3-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.18.2.77/cblr/svc/op/ks/profile/centos7.3-x86_64        ipappend 2MENU end

启动网络安装

重新新建一个虚拟机,作为客户端,然后启动网络安装,就可以看到我们刚刚制作的界面了。

Cobbler 启动界面

自定义KickStart文件

首先准备KickStart文件

在上面的实验中,我们没有进行任何的安装配置,全部都是Cobbler帮助我们完成的。可是在实际生产中,我们对每台主机的硬盘分区,安装的软件都有相应的要求,所以我们需要自己来定制KickStart文件,这样我们就能够定制地批量安装操作系统了。
我们就利用实验环境(CentOS 7.3)中的KickStart文件来定制我们自己的KickStart文件。

# 首先进入到Cobbler 的KickStart 目录下[root@localhost] cd /var/lib/cobbler/kickstarts/# 将根目录下的ks 文件复制到当前目录下[root@localhost kickstarts]cp /root/anaconda-ks.cfg  centos7.cfg[root@localhost kickstarts]#cat centos7.cfg #version=DEVEL# System authorization informationauth --enableshadow --passalgo=sha512# Use CDROM installation mediaurl --url=$tree	# url可以指定详细路径也可以使用$tree变量来进行替代# Use graphical installreboot	#安装成功之后可以重启text	#采用字符界面进行安装# Run the Setup Agent on first bootfirstboot --enableignoredisk --only-use=sda# Keyboard layoutskeyboard --vckeymap=us --xlayouts='us'# System languagelang en_US.UTF-8# Network information #修改网络环境network  --bootproto=dhcp --device=ens33 --onboot=yes --ipv6=auto --activatenetwork  --hostname=localhost.localdoma inselinux --disabled #禁用SElinux 也可以禁用防火墙# Root password	#设置root用户的初始密码rootpw --iscrypted $6$BlwRFg7fgO1i8eQa$F9yjtePt1aOnsIwmNO7mexdnBOsJTVSSyTnwp2hS2lSY87thmNylXw43.Ycj6lfY1wk2NmoQjO/WzEEGBUlZt.# System servicesservices --disabled="chronyd"# System timezonetimezone Asia/Shanghai --isUtc --nontp# X Window System configuration informationxconfig  --startxonboot# System bootloader configurationbootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda# Partition clearing informationzerombr	#清楚MBR分区clearpart --all #清楚系统中原有分区# Disk partitioning informationpart / --fstype="xfs" --ondisk=sda --size=56320part swap --fstype="swap" --ondisk=sda --size=2000part /app --fstype="xfs" --ondisk=sda --size=51200part /boot --fstype="xfs" --ondisk=sda --size=1024%packages@^graphical-server-environment@base@core@desktop-debugging@dial-up@fonts@gnome-desktop@guest-agents@guest-desktop-agents@hardware-monitoring@input-methods@internet-browser@multimedia@print-client@x11kexec-tools%end%post#删除旧的yum仓库#可根据实际情况稍作调整。 rm -rf /etc/yum.repos.d/*cat > /etc/yum.repos.d/base.repo <

将KickStart文件和yum源做关联

在Cobbler 自动创建了yum源之后,会自动有一个ks文件与该源相对应。现在我们需要将自己制作的KS文件与原有的yum源进行关联。

# --name 我们需要添加的启动菜单的名字# --distro  我们自定制的ks文件关联的yum库# --kickstart 我们自定制的ks文件的路径[root@localhost kickstarts]#cobbler profile add --name=centos7.3-x86_64-desktop --distro=centos7.3-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg# 查看Cobbler中现在还有多少个启动项[root@localhost kickstarts]#cobbler profile list   centos6.9-x86_64   centos7.3-x86_64   centos7.3-x86_64-desktop

重新修改/var/lib/tftpboot/pxelinux.cfg/default文件

在执行Cobbler sync 同步操作之后,Cobbler会自动的将/var/lib/tftpboot/pxelinux.cfg/default文件重新生成,所以,最好重新按照自己的需求修改一下这个文件。然后就可以开始进行网络安装操作系统了。

Cobbler启动界面2

从图中可以清楚地看到我们新增地一个启动选项。至此,我们搭建Cobbler 的环境就成功了。

注意事项

  • 在实际生产中,一般是局域网环境,所以在配置DHCP服务的时候,要注意局域网的工作环境。

  • Cobbler实际上就是对PXE的封装,它帮助我们实现了很多的内容,免去了我们很多的手动配置,但是这样的话,我们也不能清楚的了解底层的运行机制,出了问题,不便于处理,所以最好还是尝试手动配置一下PXE来搭建网络操作系统安装环境,以便了解的更详细一下其中的运行机制。

  • 最好手动配置ks文件,这样能够最大限度上定制自己的集群操作系统。

结语

Cobbler 其实还支持基于Web的管理方式。在配置好Cobbler 服务环境之后,安装一个cobbler-web 的软件包,然后就可以进行相应的配置管理了,这里我们不做详细介绍,感兴趣的朋友可以去查阅一下资料。 Cobbler_web 的图形管理界面如下图所示,从图中我们能够看到我们自己指定的菜单和系统yum源。

Cobbler-web管理

通过上面的操作,我们已经能够完全搭建一个基于Cobbler的网络服务,用来给生产环境中批量的安装操作系统了。

个人博客地址:http://www.pojun.tech/ 欢迎访问

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5336 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.