Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。
Cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Server端:
第一步,启动Cobbler服务
第二步,进行Cobbler错误检查,执行cobbler check命令
第三步,进行配置同步,执行cobbler sync命令
第四步,复制相关启动文件文件到TFTP目录中
第五步,启动DHCP服务,提供地址分配
第六步,DHCP服务分配IP地址
第七步,TFTP传输启动文件
第八步,Server端接收安装信息
第九步,Server端发送ISO镜像与Kickstart文件
Client端:
第一步,客户端以PXE模式启动
第二步,客户端获取IP地址
第三步,通过TFTP服务器获取启动文件
第四步,进入Cobbler安装选择界面
第五步,客户端确定加载信息
第六步,根据配置信息准备安装系统
第七步,加载Kickstart文件
第八步,传输系统安装的其它文件
第九步,进行安装系统
IP:192.168.231.60
[root@n1 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@n1 ~]# uname -r
3.10.0-862.el7.x86_64
#关闭防火墙
[root@n1 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
#关闭selinux
[root@n1 ~]# getenforce
Disabled
虚拟机网卡采用nat模式
命令管理
usage
=====
cobbler ...
[add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler [options|--help]
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素cobbler
report 列出元素的详细信息
cobbler sync 同步配置到数据目录,更改配置最好都要执行下
cobbler reposync 同步yum仓库
cobbler distro 查看导入的发行版系统信息
cobbler system 查看添加的系统信息cobbler
profile 查看配置信息
安装相关依赖包
[root@n1 ~]# yum install cobbler cobbler-web pykickstart httpd dhcp tftp-server -y
cobbler #cobbler程序包
cobbler-web #cobbler的web服务包
pykickstart #cobbler检查kickstart语法错误
查看cobbler安装的部分文件
[root@n1 ~]# rpm -ql cobbler # 查看安装的文件,下面列出部分。
/etc/cobbler # 配置文件目录
/etc/cobbler/settings # cobbler主配置文件,这个文件是yaml格式,cobbler是python写的程序。
/etc/cobbler/dhcp.template # dhcp服务的配置模板
/etc/cobbler/tftpd.template # tftp服务的配置模板
/etc/cobbler/rsync.template # rsync服务的配置模板
/etc/cobbler/iso # iso模板配置文件目录
/etc/cobbler/pxe # pxe模板文件目录
/etc/cobbler/power # 电源的配置文件目录
/etc/cobbler/users.conf # web服务授权配置文件
/etc/cobbler/users.digest # web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template # DNS服务的配置模板
/etc/cobbler/modules.conf # cobbler模块配置文件
/var/lib/cobbler # cobbler数据目录
/var/lib/cobbler/config # 配置文件
/var/lib/cobbler/kickstarts # 默认存放kickstart文件
/var/lib/cobbler/loaders # 存放的各种引导程序
/var/www/cobbler # 系统安装镜像目录
/var/www/cobbler/ks_mirror # 导入的系统镜像列表
/var/www/cobbler/p_w_picpaths # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror # yum源存储目录
/var/log/cobbler # 日志目录
/var/log/cobbler/install.log # 客户端系统安装日志
/var/log/cobbler/cobbler.log # cobbler日志
启动相关服务
[root@n1 ~]# systemctl start httpd
[root@n1 ~]# systemctl start cobblerd
检测cobbler
[root@n1 ~]# 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/tftp
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 : 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.修改/etc/cobbler/settings中的"server"字段为提供cobbler服务的主机的IP或主机名
[root@n1 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.231.60/' /etc/cobbler/settings
[root@n1 ~]# grep "^server" /etc/cobbler/settings
server: 192.168.231.60
2.修改/etc/cobbler/settings中"next_server"为PXE网络上启动服务器的IP(这里PXE服务器和cobbler在同一主机)
[root@n1 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.231.60/' /etc/cobbler/settings
[root@n1 ~]# grep "^next_server" /etc/cobbler/settings
next_server: 192.168.231.60
3.修改/etc/xinet.d/tftp文件中的disable的参数为no
[root@n1 ~]# cp /etc/xinetd.d/tftp{,.bak} #备份
[root@n1 ~]# vim /etc/xinetd.d/tftp
disable = no
4.执行cobbler get-loaders命令
5.启动rsync服务
[root@n1 ~]# systemctl start rsyncd.service
[root@n1 ~]# systemctl enable rsyncd.service
6.安装包用来管理debian部署和存储库,这里不需要,就不安装了
7.修改cobbler中的加密密码(即为自动安装系统后的root登录密码)
#生成加密密码openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
[root@n1 ~]# openssl passwd -1 -salt '123456' 'realxw'
$1$123456$jMyuS0sKNP4A/OOlui3lR/
[root@n1 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$123456$jMyuS0sKNP4A/OOlui3lR/"
8.安装cman fence-agents(可选),电源管理功能
[root@n1 ~]# yum install cman fence-agents -y
修改一些其他配置
[root@n1 ~]# vim /etc/cobbler/settings
manage_dhcp: 1 #用cobbler管理dhcp
pxe_just_once: 1 #防止循环安装系统,适用于服务器第一启动选项是pxe启动
同步cobbler配置
[root@n1 ~]# cobbler sync
[root@n1 ~]# systemctl restart cobblerd.service
重新检测cobbler
[root@n1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.
#管理deban,这里不需要安装
配置dhcp
[root@n1 ~]# cp /etc/cobbler/dhcp.template{,.bak}
[root@n1 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.231.0 netmask 255.255.255.0 {
option routers 192.168.231.2;
option domain-name-servers 192.168.231.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.231.100 192.168.231.110;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
同步cobbler配置
[root@n1 ~]# cobbler sync
重新检测cobbler
[root@n1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
Restart cobblerd and then run 'cobbler sync' to apply changes.
设置开机自启
systemctl enable dhcpd
systemctl enable rsyncd.service
systemctl enable tftp.service
systemctl enable httpd.service
systemctl enable cobblerd.service
重启所有服务,防止一些服务没有开启
systemctl restart tftp.service
systemctl restart dhcpd.service
systemctl restart rsyncd.service
systemctl restart httpd.service
systemctl restart cobblerd.service
挂载光盘镜像
[root@n1 ~]# mkdir /iso #创建挂载目录
[root@n1 ~]# mount -t iso9660 -o loop /soft/CentOS-7-x86_64-Minimal-1804.iso /iso/ #这里是CentOS7.5mini镜像
mount: /dev/loop0 is write-protected, mounting read-only
导入镜像
[root@n1 ~]# cobbler import --path=/iso/ --name=CentOS7.5 --arch=x86_64
--path:镜像路径
--name:为安装源定义一个名字
--arch :指定安装源是64位或32位
查看镜像列表
[root@n1 ~]# cobbler distro list
CentOS7.5-x86_64
查看镜像存放目录
[root@n1 ~]# cd /var/www/cobbler/ks_mirror/
[root@n1 ks_mirror]# ls
CentOS7.5-x86_64 config
查看ks文件位置
[root@n1 ~]# cd /var/lib/cobbler/kickstarts/
[root@n1 kickstarts]# ls
default.ks legacy.ks sample_esx4.ks sample.ks
esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed
esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed
install_profiles sample_end.ks (默认使用的ks文件) sample_esxi6.ks
配置自定义ks文件,以sample_end.ks为模板
[root@n1 kickstarts]# cp sample_end.ks CentOS7.5-x86_64.ks
[root@n1 kickstarts]# vim CentOS7.5-x86_64.ks #只修改如下内容
firewall --disable #关闭防火墙
timezone Asia/Shanghai #设置时区
# autopart #把自动分区注释,手动如下设置
part /boot --fstype=ext4 --asprimary --size=200
part swap --asprimary --size=1024
part / --fstype=ext4 --grow --asprimary --size=10240
%packages #安装需要安装的软件包
$SNIPPET('func_install_if_enabled') #这里默认
%end
解释
--asprimary,强迫把分区分配为主分区,否则提示分区失败.
--fstype=,为分区设置文件系统类型.有效的类型为ext2,ext3,swap和vfat
--grow 让分区自动增长利用可用的磁盘空间,或是增长到设置的maxsize值;
--size= 设置分区的最小值,默认单位为M,但是不能写单位;
%packages部分,这部分选择需要安装的软件包.
如想详细了解怎样配置kickstart,可参考 https://blog.csdn.net/taiyang1987912/article/details/42176709
#第一次导入系统镜像后,cobbler会给镜像指定一个默认的kickstart自动安装文件(/var/lib/cobbler/kickstarts/sample_end.ks)
[root@n1 ~]# cobbler list
distros:
CentOS7.5-x86_64
profiles:
CentOS7.5-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
查看安装镜像文件信息
[root@n1 ~]# cobbler distro report --name=CentOS7.5-x86_64
Name : CentOS7.5-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS7.5-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS7.5-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS7.5-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <>
Red Hat Management Server : <>
Template Files : {}
查看镜像的profile设置
更详细信息
[root@n1 ~]# cobbler profile report --name=CentOS7.5-x86_64
Name : CentOS7.5-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS7.5-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <>
Red Hat Management Server : <>
Repos : []
Server Override : <>
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
编辑profile,修改关联的ks文件(指定自定义ks文件)
[root@n1 ~]# cobbler profile edit --name=CentOS7.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7.5-x86_64.ks
查看profile,发现Kickstart关联文件被修改
[root@n1 ~]# cobbler profile report --name=CentOS7.5-x86_64
Name : CentOS7.5-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS7.5-x86_64
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/CentOS7.5-x86_64.ks
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <
Red Hat Management Server : <
Repos : []
Server Override : <
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
同步数据
[root@n1 ~]# cobbler sync
[root@n1 ~]# systemctl restart cobblerd.service
修改PXE默认启动选项
默认情况下PXE启动的是Local(启动后会出现local和自定义CentOS7.5-x86_64两个选项,需手动,要无人工干涉,就需要修改)
修改前
[root@n1 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@n1 pxelinux.cfg]# cat default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
LABEL CentOS7.5-x86_64
kernel /images/CentOS7.5-x86_64/vmlinuz
MENU LABEL CentOS7.5-x86_64
append initrd=/images/CentOS7.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.231.60/cblr/svc/op/ks/profile/CentOS7.5-x86_64
ipappend 2
MENU end
修改后
[root@n1 pxelinux.cfg]# cat default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT CentOS7.5-x86_64
LABEL CentOS7.5-x86_64
kernel /images/CentOS7.5-x86_64/vmlinuz
MENU LABEL CentOS7.5-x86_64
append initrd=/images/CentOS7.5-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://192.168.231.60/cblr/svc/op/ks/profile/CentOS7.5-x86_64
ipappend 2
MENU end
不用cobbler sync,否则会恢复原来的配置
要设置足够的内存,否则会出现如下错误:
用root登录,密码为/etc/cobbler/settings中的default_password_crypted(使用没有加密的密码)
参考:
https://blog.51cto.com/renjunjie622/1782190
https://www.cnblogs.com/kevingrace/p/5685480.html
https://blog.csdn.net/taiyang1987912/article/details/42176709