Cobbler原理与实战

Cobbler实战

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。

使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。 Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用,Cobbler客户端Koan支持虚拟机安装和操作系统重新安装。

 

Cobbler可以干什么

  • 服务器上架后,可以手动选择需要安装的系统(如:Centos6.8 或 Centos 7.3)

  • 服务器上架后,能够根据需求,安装配置操作系统(如:修改IP地址、主机名、选择安装包)

  • 系统安装后,可以自定义的执行脚本,完成系统基础软件初始化(如:Zabbix安装配置、SaltStack安装配置)

  • 可以当内部YUM源,并在系统安装时进行初始化

  • 可以重装系统

  • Cobbler支持API,可以无缝融合到自建运维平台中

  • Cobbler支持网卡的路由配置、DNS配置、bonding

 

Cobbler基础原理

Cobbler是通过将DHCP、TFTP、DNS、HTTP等服务进行集成,创建一个中央管理节点,其可以实现的功能有配置服务,创建存储库,解压缩操作系统媒介,代理或集成一个配置管理系统,控制电源管理等。 Cobbler的最终目的是实现无需进行人工干预即可安装机器。在进行进一步的操作之前,我们有必要先了解下pxe和kickstart 。

PXE概述

预启动执行环境(Preboot eXecution Environment,PXE,也被称为预执行环境)是让计算机通过网卡独立地使用数据设备(如硬盘)或者安装操作系统。Intel 搞出来的。

其工作原理:

在这里插入图片描述

  • PXE Client发送广播包请求DHCP分配IP地址DHCP

  • Server回复请求,给出IP地址以及Boot

  • Server的地址PXE下载引导文件执行引导程序

  • 总结来说,PXE主要是通过广播的方式发送一个包,并请注获取一个地址,而后交给TFTP程序下载一个引导文件。

Kickstart 概述

Kickstart 是红帽开发的一种工具,我们可以简单理解为一个自动安装应答配置管理程序。通过读取这个配置文件,系统知道怎么去分区,要安装什么包,配什么IP,优化什么内核参数等等。其主要有以下部分组成:

  • Kickstart 安装选项,包含语言的选择,防火墙,密码,网络,分区的设置等;

  • %Pre 部分,安装前解析的脚本,通常用来生成特殊的ks配置,比如由一段程序决定磁盘分区等;

  • %Package 部分,安装包的选择,可以是 @core 这样的group的形式,也可以是这样 vim-* 包的形式;

  • %Post 部分,安装后执行的脚本,通常用来做系统的初始化设置。比如启动的服务,相关的设定等。

 

Cobbler的设计方式

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

  • 发行版:表示一个操作系统。它承载了内核和 initrd 的信息,以及内核参数等其他数据。

  • 配置文件:包含一个发行版、一个 kickstart 文件以及可能的存储库,还包含更多特定的内核参数等其他数据。

  • 系统:表示要配给的机器。它包含一个配置文件或一个镜像,还包含 IP 和 MAC 地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息。

  • 存储库:保存一个 yum 或 rsync 存储库的镜像信息。

  • 镜像:可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和 initrd 的对象)

 

Cobbler工作原理

在这里插入图片描述

server端:

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

 

Client端:

第一步,客户端以PXE模式启动 
第二步,客户端获取IP地址 
第三步,通过TFTP服务器获取启动文件 
第四步,进入Cobbler安装选择界面 
第五步,客户端确定加载信息 
第六步,根据配置信息准备安装系统 
第七步,加载Kickstart文件 
第八步,传输系统安装的其它文件 
第九步,进行安装系统

 

Cobbler安装

基础环境部署

关闭selinux:

setenforce 0

yum配置:

#讲旧仓库配置转移到某目录中 
mkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/ 

#安装wget,添加aliyun Base仓库及epel仓库 
yum install -y wget 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

 

Cobbler服务部署

安装服务:

yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd python-ctypes -y

服务自启动:

systemctl enable httpd 
systemctl enable xinetd 
systemctl enable rsyncd 
systemctl enable tftp 
systemctl enable cobblerd

启动服务:

systemctl restart httpd 
systemctl restart xinetd 
systemctl restart tftp 
systemctl restart cobblerd

执行cobbler check检查运行环境:

[root@l27-server1 ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : 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
8 : 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,2,7:

默认密码,setting,和dhcp

生成新的默认密码

[root@l27-server1 ~]# openssl passwd -1 -salt `openssl rand 15 -base64` '123' 
$1$Yo1o0fBf$pm5RkWqGdviwsu4YiWhF9/

注意: 此密码是系统安装后的默认密码,建议使用强密码

修改setting配置文件

sed -i 's%^server: 127.0.0.1%server: 192.168.217.155%g' /etc/cobbler/settings 
sed -i 's%^next_server: 127.0.0.1%next_server: 192.168.217.155%g' /etc/cobbler/settings 
sed -i 's%manage_dhcp: 0%manage_dhcp: 1%g' /etc/cobbler/settings 
sed -i 's%^default_password_crypted.*%default_password_crypted: "$1$Yo1o0fBf$pm5RkWqGdviwsu4YiWhF9/"%g' /etc/cobbler/settings

配置DHCP /etc/dhcp/dhcpd.conf(根据需求更改)

subnet 192.168.217.0 netmask 255.255.255.0 { 
	option routers 192.168.217.254; #网关地址 
	option domain-name-servers 114.114.114.114; #dns地址 
	option subnet-mask 255.255.255.0; #掩码 
	range dynamic-bootp 192.168.217.10 192.168.217.100; #地址分配范围 		default-lease-time 21600; 
	max-lease-time 43200; 
	next-server $next_server; #引用上面setting配置的nex-server值 
	filename "/pxelinux.0"; 
}

还要修改/etc/cobbler/dhcp.template 文件

subnet 192.168.217.0 netmask 255.255.255.0 {
     option routers             192.168.217.155;
     option domain-name-servers 114.114.114.114;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.217.10 192.168.217.100;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {

问题3:

关闭selinux

[root@l27-server1 ~]# setenforce 0 
#编辑/etc/selinux/config,并重启生效 
SELINUX=disabled
init 6

问题4

启动tftp服务

编辑tftp服务配置文件 /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 #修改此处值为
	no per_source = 11
	cps = 100 2 
	flags = IPv4 
}

问题5:

获取引导文件

[root@l27-server1 ~]# cobbler get-loaders

截图

在这里插入图片描述

问题6:

debian相关文件获取(如不需要部署debian系统可省略)

[root@l27-server1 ~]# yum -y install debmirror 
#修改/etc/debmirror.conf配置文件,注释掉@dists和@arches两行 
[root@l27-server1 ~]# vi /etc/debmirror.conf 
... 
#@dists="sid"; 
@sections="main,main/debian-installer,contrib,non-free"; 
#@arches="i386"; 
...

问题8:

电源管理工具(可选)

yum -y install fence-agents

重启服务并同步状态

[root@l27-server1 ~]# systemctl restart cobblerd 
[root@l27-server1 ~]# cobbler check
No configuration problems found.  All systems go.

这就完成

 

cobbler基础配置

同步配置是配置生效

cobbler sync

配置distro:

主要用来定义和设置系统发行版本,里包含了系统的内核,引导文件,以及安装包等内容,就相当于一个LINUX系统的ISO镜像。如:多个发行版本,同一发行版不同版本号。

1.首先上传系统iso镜像文件,此处以ubuntu12.04镜像为例,其他镜像做法类似

wget http://releases.ubuntu.com/precise/ubuntu-12.04.5-server-amd64.iso

[root@l27-server1 ~]# mkdir -p /system/ubuntu1204 ; mount -t iso9660 ~/ubuntu-12.04.5-server-amd64.iso /system/ubuntu1204

2.导入镜像

[root@l27-server1 ~]# cobbler import --name=ubuntu1204 --path=/system/ubuntu1204 --arch=x86_64 
task started: 2020-04-30_102441_import
task started (id=Media import, time=Thu Apr 30 10:24:41 2020)
Found a candidate signature: breed=freebsd, version=10.1
Found a candidate signature: breed=freebsd, version=10.0
Found a candidate signature: breed=freebsd, version=8.3
Found a candidate signature: breed=freebsd, version=8.2
Found a candidate signature: breed=freebsd, version=8.4
Found a candidate signature: breed=freebsd, version=11.0
Found a candidate signature: breed=freebsd, version=10.3
Found a candidate signature: breed=freebsd, version=11.2
Found a candidate signature: breed=freebsd, version=11.1
Found a candidate signature: breed=freebsd, version=12.0
Found a candidate signature: breed=freebsd, version=10.2
Found a candidate signature: breed=freebsd, version=11.3
Found a candidate signature: breed=freebsd, version=9.0
Found a candidate signature: breed=freebsd, version=9.1
Found a candidate signature: breed=freebsd, version=9.2
Found a candidate signature: breed=freebsd, version=9.3
Found a candidate signature: breed=ubuntu, version=precise
running: /usr/bin/file /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release.gpg
received on stdout: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release.gpg: PGP signature

received on stderr: 
running: /usr/bin/file /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release
received on stdout: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/dists/precise/Release: ASCII text

received on stderr: 
Found a matching signature: breed=ubuntu, version=precise
Adding distros from path /var/www/cobbler/ks_mirror/ubuntu1204-x86_64:
creating new distro: ubuntu1204-x86_64
trying symlink: /var/www/cobbler/ks_mirror/ubuntu1204-x86_64 -> /var/www/cobbler/links/ubuntu1204-x86_64
creating new profile: ubuntu1204-x86_64
associating repos
checking for apt repo(s)
adding apt repo for ubuntu1204-x86_64
Added repos for ubuntu1204-x86_64
*** TASK COMPLETE ***

3.查看distro配置

[root@localhost ~]# cobbler distro report 
Name                           : ubuntu1204-x86_64
Architecture                   : x86_64
TFTP Boot Files                : {}
Breed                          : ubuntu
Comment                        : 
Fetchable Files                : {}
Initrd                         : /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/install/netboot/ubuntu-installer/amd64/initrd.gz
Kernel                         : /var/www/cobbler/ks_mirror/ubuntu1204-x86_64/install/netboot/ubuntu-installer/amd64/linux
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart Metadata             : {'tree': 'http://@@http_server@@/cblr/links/ubuntu1204-x86_64'}
Management Classes             : []
OS Version                     : precise
Owners                         : ['admin']
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Template Files                 : {}

查看ubuntu相关文件:

[root@localhost ~]# cobbler list 
distros: 
	ubuntu1204-x86_64 #镜像 

profiles: 
	ubuntu1204-x86_64 #配置,用于配置关联自动应答ks文件 

systems: #可以为不同的主机根据MAC设置地址及安装参数 

repos: 
	ubuntu1204-x86_64 #仓库,用于自定义仓库 

images: 

mgmtclasses: 

packages: 

files:

(自定义)配置profifile:定义自动安装应答文件

主要用来定义kickstart配置文件,安装时依据配置文件进行定制化安装,配置此项时要和distro进行关联。

[root@localhost ~]# cobbler profile report 
Name                           : ubuntu1204-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : ubuntu1204-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample.seed #关联的kickstart文件 (ubuntu和centos的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

配置repo:定义本地或远程仓库源

查看默认repo

[root@localhost ~]# cobbler repo report 
Name                           : ubuntu1204-x86_64
Apt Components (apt only)      : ['main', 'universe']
Apt Dist Names (apt only)      : ['precise', 'precise-updates', 'precise-security']
Arch                           : x86_64
Breed                          : apt
Comment                        : 
Createrepo Flags               : <<inherit>>
Environment Variables          : {}
Keep Updated                   : True
Mirror                         : http://archive.ubuntu.com/ubuntu
Mirror locally                 : True
Owners                         : ['admin']
Priority                       : 99
External proxy URL             : 
RPM List                       : []
Yum Options                    : {'--verbose': '~', '--ignore-release-gpg': '~'}

自定义repo

cobbler repo add --help #创建
repo cobbler repo edit --help #修改repo

(自定义)配置system

主要用来定义内核参数,电源管理,计算机名,网络接口参数等(客户机),如:根据mac地址配置IP地址,通过和

profifile,distro关联实现自动化安装。

cobbler system add --help #创建
system cobbler system edit --help #修改system

测试

新建一台虚拟机,不用选光盘映像文件,直接打开

启动看到如下界面

在这里插入图片描述

选择第二个菜单,是之前制作的distro,接下来服务器会自动按照之前的ks文件自动安装

然后就等等等。

在这里插入图片描述

进入cobbler界面
https://192.168.217.155/cobbler_web

在这里插入图片描述

也可以在这创建新系统

在这里插入图片描述

  • 8
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值