Cobbler原理与实战

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值