Cobbler是一款Linux生态的自动化运维工具,基于Python2开发,用于自动化批量部署安装操作系统;其提供基于CLI的管理方式和WEB配置界面,其中WEB配置界面是基于Python2和Django框架开发。另外,cobbler还提供了API,方便二次开发。当然,Cobbler属于C/S模型(客户端/服务器模型)
Cobbler主要用于快速网络安装linux操作系统,支持众多的Linux发行版如:Red Hat、
Fedora、CentOS、Debian、Ubuntu和SuSE等。
在cobbler之前,微软曾开发过另一项类似的基于C/S工作模式的技术PXE(Prebot eXecuteEnvironment,预启动执行环境),其支持通过网络启动操作系统,亦可以让需要安装系统的带支持PEX技术网卡的裸机通过网络从http服务器下载映像来安装,在启动过程中,客户端需要从dhcp服务器得到IP地址、掩码、网关以及相关的配置文件路径,再用TFTP(trivial file transferprotocol)协议从服务器下载一个引导启动的软件包(类似linux光盘的isolinux文件夹下的文件)并加载到本机内存中执行,经过启动软件包中配置文件指定的ks应答文件指明服务器中的操作系统位置,进而找到安装源,并在ks文件的指导下完成操作系统的安装。
Cobbler实质是PXE的二次封装,将多种安装参数封装到一起,并提供统一的管理方法。
使用Cobbler安装系统需要一台专门提供各种服务的服务器,提供的服务包括(HTTP/FTP/NFS,TFTP,DHCP),也可以将这几个服务分别部署到不同服务器。事实上在实际应用中,总是将不同的服务分别部署到专门的服务器。
Cobbler是在HTTP、TFTP、DHCP等各种服务的基础上进行相关操作的,实际安装的大体过程类似于基于PXE的网络安装:客户端(裸机)开机使用网卡引导启动,其请求DHCP分配一个地址后从TFTP服务器获取启动文件,加载到客户端本地内存中运行,并显示出可安装的系统列表;在人为的选定安装的操作系统类型后,客服端会到HTTP服务器下载相应的系统安装文件并执行自动安装。
PXE网络安装示意
[root@centos7 ~]#wget -O /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
2.2.安装Cobbler及其相关的服务和组件
[root@centos7 ~]#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
#修改dhcp的模版文件下面的行,用来生成dhcp的配置文件
[root@centos7 ~]#vim /etc/cobbler/dhcp.template
subnet 192.168.131.0 netmask 255.255.255.0 {
option routers 192.168.131.1;
option domain-name-servers 180.76.76.76,223.6.6.6;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.131.100 192.168.131.200;
#自动生成dhcp配置文件并启动
[root@centos7 ~]#cobbler sync
/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模块的配置文件
/var/lib/cobbler/config/: 用于存放distros,system,profiles 等信息的配置文件
/var/lib/cobbler/triggers/: 用于存放用户定义的cobbler命令
/var/lib/cobbler/kickstarts/: 默认存放kickstart文件
/var/lib/cobbler/loaders/: 存放各种引导程序
/var/www/cobbler/ks_mirror/: 导入的发行版系统的所有数据
/var/www/cobbler/images/ : 导入发行版kernel和initrd镜像用于远程网络启动
/var/www/cobbler/repo_mirror/: yum 仓库存储目录
/var/log/cobbler/installing: 客户端安装日志
/var/log/cobbler/cobbler.log : cobbler日志
3.2.配置及启动cobblerd服务
当httpd,tftp及dhcp服务都正常运行后,就可以启动cobblerd服务进行相关的配置了。
启动cobblerd
systemctl start cobbler
检测cobbler的运行环境,并根据提示逐步配置cobbler
cobbler check
[root@centos7 ~]#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/tftp7.7 cobbler命令用法
4 : 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.
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-phrasehere' '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.
1.更改/etc/xinetd.d/tftp配置文件
vim /etc/xinetd.d/tftp
disable = yes --> disable = no
systemctl restart xinetd
2.联网下载boot引导程序文件
cobbler get-loaders
[root@centos7 ~]cobbler get-loaders
No such command: get-loaders
当遇到这个问题时,安装syslinux,我们可以直接通过YUM的方式进行安装,安装后,尽管cobbler check命令依然报错,但是我们可以不用理会该报错,直接进行cobbler的下一步配置即可!
3.没有网络情况下拷贝启动文件到TFTP服务文件夹
cp -a /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot
4.更改/etc/cobbler/settings配置文件的server项为提供cobblerd服务的主机地址,也就是本机地址
sed -nri 's#server:127.0.0.1#server:192.168.100.100#' /etc/cobbler/settings
更改后的整行内容:server:192.168.100.100
5.更改/etc/cobbler/settings配置文件的next_server项,指明tftp服务器地址,使得客户端能够找
到TFTP服务器sed -i 's/next_server: 127.0.0.1/next_server: 192.168.100.100/'
/etc/cobbler/settings
更改后的整行内容:next_server:192.168.100.100
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
配置完成后重启
systemctl restart cobblerd
[root@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]
[root@centos7 ~]cobbler
[root@centos7 ~]cobbler --help
[root@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))
......
例如
cobbler distro list
列出当前导入的linux发行版条目
cobbler distro report
报告当前所有的linux发行版详细信息
cobbler profile --name=centos7 --distro=centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7.cfg
将linux发行版系统镜像与其对应的ks文件建立关联
[root@old_centos7 ~]#cp /var/www/html/ksdir/ks{6,7,8}.ks /var/lib/cobbler/kickstarts
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
systemctl restart cobblerd
cobbler sync
[root@centos7 ~]#du -sh /var/www/cobbler/ks_mirror/*
11G /var/www/cobbler/ks_mirror/centos-7.7-x86_64
7.2G /var/www/cobbler/ks_mirror/centos-8.1-x86_64
12K /var/www/cobbler/ks_mirror/config
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
cobbler profile remove --name=PROFILE_NAME
删除后,再关联ks文件。systemctl restart cobblerd
cobbler sync
4.2.6 查看详细信息
cobbler report
[root@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:
==========
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos8-x86_64'}
[root@old_centos7 ~]#vim /var/www/cobbler/ks_mirror/config/ centos8-x86_64.repo
中,是cobbler自己定义安装源路径的特有语法规定的,因此可以在ks文件中指定安装$tree``变量。
(url --url=$tree)`设置其网络类型为NAT,安装centos6时配置内存1G以上,安装centos7和centos8时配置内存大于2G
/etc/cobbler/pxe/pxedefault.template
模板文件,重启同步[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
/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
yum install cobbler-web
systemctl restart httpd
https://cobblerserver/cobbler_web
centos6:url --url=http://httpserver/ksdir/ks.cfg
或者url --url=$tree
centos7:url --url=http://httpserver/ksdir/ks.cfg
或者url --url=$tree
centos8:url --url=http://httpserver/ksdir/ks.cfg
或者url --url=$tree
systemctl restart httpd
[root@centos7 ~]cobbler get-loaders
No such command: get-loaders
重启httpd服务:·systemctl restart httpd·
login:cobbler
passwd:cobbler
默认账户密码都是:cobbler