Cobbler部署centos7
- Cobbler介绍:
Cobbler 可以用来快速建立 Linux 网络安装环境,它已将Linux网络安装的技术门槛,从大专以上文化水平,成功降低到了初中水平,连补鞋匠都能学会。
网络安装服务器套件Cobbler(补鞋匠)从前,我们一直在装机民工这份很有前途的职业。自打若干年前Red Hat推出了 Kickstart,此后我们顿觉身价增倍。不再需要刻了光盘一台一台的安装Linux,只要搞定PXE、DHCP、TFTP,还有那满屏眼花缭乱不知所云的Kickstart脚本,我们就可以像哈利波特一样,轻点魔棒,瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人能够整明白的,没有大专以上的学历,通不过英语四级,根本别想玩转。总而言之,这是一份多么有前途,多么有技术含量的工作啊。很不幸,Red Hat 最新(Cobbler项目最初在2008年左右发布)发布了网络安装服务器套件Cobbler(补鞋匠),它已将Linux网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下水平,连补鞋匠都能学会。
- 应用场景:
运维自动化在生产环境中占据着举足轻重的地位,尤其是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操作系统,如果不通过自动化来完成,根本是不可想象的。面对生产环境中不同服务器的需求,该如何实现批量部署多版本的操作系统呢?Cobbler便可以满足这一实际需求,实现多版本操作系统批量部署
- 对应关系

- 集成服务:
PXE服务支持
DHCP服务管理
DNS服务管理
电源管理
Kickstart服务支持
YUM仓库管理
TFTP
Apache
- 工作原理

1.1 Server端
- 启动
Cobbler服务 - 进行
Cobbler错误检查,执行cobbler check命令 - 进行配置同步,执行
cobbler sync命令 - 复制相关启动文件到
TFTP目录中 - 启动
DHCP服务,提供地址分配 DHCP服务分配IP地址TFTP传输启动文件Server端接收安装信息Server端发送ISO镜像与Kickstart文件
1.2Client端
- 客户端以
PXE模式启动 - 客户端获取
IP地址 - 通过
TFTP服务器获取启动文件 - 进入
Cobbler安装选择界面 - 根据配置信息准备安装系统
- 加载
Kickstart文件 - 传输系统安装的其它文件
- 进行安装系统
1.3cobbler安装
说明:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。
VMware的NAT模式的dhcp服务也关闭,避免干扰。
1.4环境准备
| 主机名 | 系统 | IP |
|
cobbler |
CentOS7.3.1611 |
10.0.0.43 |
1.5安装组件
yum -y install cobolor cbler wb tfp-server pkikstaet hted dhcp xinetd debmirror
cobblor #cobbler安装包
cobblor-web #cobbler的web页面
pkikstaet #cobbler检测kicstart语法错误
httpd #Web服务
dhcp #dhcp服务
tftp #tftp服务
xinetd #守护经常
加入开机自启
[root@ cobbler ~]# systemctl start httpd cobblerd [root@ cobbler ~]# systemctl enable httpd cobblerd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service. [root@ cobbler ~]#
1.6配置
检测cobbler配置 ,首次不修改配置 检测有9个语法错误
[root@ cobbler ~]# 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support 7 : comment out 'arches' on /etc/debmirror.conf for proper debian support 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-phrase-here' '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. [root@ cobbler ~]#
1.6.1动态配置
[root@ cobbler ~]# sed -ri '/allow_dynamic_settings:/c\allow_dynamic_settings: 1' /etc/cobbler/settings [root@ cobbler ~]# grep allow_dynamic_settings /etc/cobbler/settings allow_dynamic_settings: 1 [root@ cobbler ~]# systemctl restart cobblerd [root@ cobbler ~]#
1.6.2配置server地址
[root@ cobbler ~]#cobbler setting edit --name=server --value=10.0.0.43
1.6.3next_server地址
[root@ cobbler ~]# cobbler setting edit --name=next_server --value=10.0.0.43
1.6.4配置xinetd管理tftp
root@ cobbler ~]# sed -ri '/disable/c\disable = no' /etc/xinetd.d/tftp [root@ cobbler ~]# systemctl enable xinetd [root@ cobbler ~]# systemctl restart xinetd
1.6.5boot-loaders
[root@ cobbler ~]# cobbler get-loaders task started: 2020-03-02_230504_get_loaders task started (id=Download Bootloader Content, time=Mon Mar 2 23:05:04 2020) downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi *** TASK COMPLETE ***
1.6.6启动sync
[root@ cobbler ~]# systemctl start rsyncd [root@ cobbler ~]# systemctl enable rsyncd Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
1.6.7修改debian support配置
[root@ cobbler ~]# sed -i 's#@dists="sid";#\#@dists="sid";#gp' /etc/debmirror.conf [root@ cobbler ~]# sed -i 's#@arches="i386";#\#@arches="i386";#g' /etc/debmirror.conf
1.6.8 default_password_crypted
#注意:这里设置的密码是c1bbler安装完系统后,默认root用户初始化登录密码,用openss1生成一串密码后加入到cobbler的配置文件(/etc/cobbler/settings )里,替换default. password_ crypted 字段
[root@ cobbler ~]# openssl passwd -1 -salt `openssl rand -hex 4` '123456' $1$01a8f6d1$VunGSOhdq2oAPplUt8E7I. #随机码 [root@ cobbler ~]# cobbler setting edit --name=default_password_crypted --value='$1$01a8f6d1$VunGSOhdq2oAPplUt8E7I.'
1.6.9 安装fencing tools
yum -y install fence-agents
到此,重启再次检查
[root@ cobbler ~]# systemctl restart cobblerd [root@ cobbler ~]# cobbler sync task started: 2020-03-02_231543_sync task started (id=Sync, time=Mon Mar 2 23:15:43 2020) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/grub/images copying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** [root@ cobbler ~]# cobbler check No configuration problems found. All systems go. #表示配置成功 [root@ cobbler ~]#
1.7配置DHCP
[root@ cobbler ~]# cobbler setting edit --name=manage_dhcp --value=1 [root@ cobbler ~]# vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 { #网段和子网掩码
option routers 10.0.0.254; #网关地址
option domain-name-servers 223.5.5.5; #DNS
option subnet-mask 255.255.255.0; #IP掩码
range dynamic-bootp 10.0.0.100 10.0.0.254; #分片IP范围
1.8同步cobbler配置
[root@ cobbler ~]# cobbler sync

创建一个新的虚拟机试一试cobbler,现在是没有镜像的

看一眼有没有cobbler,然后关机
1.9cobbler安装centos7.3
因为自身的cobbler就在7上部署的,把当前的镜像挂载
自身看着这里的

如果没有添加一个7的镜像
1.9.1 创建挂载点挂载
root@ cobbler ~]# mkdir /centos7.3 [root@ cobbler ~]# mount -o loop /dev/cdrom /centos7.3
1.9.2 导入镜像
[root@ cobbler ~]# cobbler import --path=/centos7.3 --name=centos7.3 --arch=x86_64 #过程消耗点时间
1.9.3导入镜像后信息
[root@ cobbler ~]# cobbler distro report --name=centos7.3-x86_64
Name : centos7.3-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/centos7.3-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/centos7.3-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/centos7.3-x86_64'}
Management Classes : []
OS Version : rhel6
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
1.9.4查看profile信息
[root@ cobbler ~]# cobbler profile report --name=centos7.3-x86_64
Name : centos7.3-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : centos7.3-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 : <<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
19.5编辑centos7.3镜像的kickstart文件
[root@ cobbler ~]# cd /var/lib/cobbler/kickstarts/
[root@ cobbler kickstarts]# cp sample_end.ks centos7.3ks
[root@ cobbler kickstarts]# vim centos7.3ks
# This kickstart file should only be used with EL > 5 and/or Fedora > 7.
# For older versions please use the sample.ks kickstart file.
# Install OS instead of upgrade
install
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# System timezone
timezone Asia/ShangHai
#Root password
rootpw --iscrypted $default_password_crypted
# System authorization information
auth --useshadow --enablemd5
# Firewall configuration
firewall --disabled
# SELinux configuration
selinux --disabled
# Use network installation
url --url=$tree
# Clear the Master Boot Record
zerombr
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
part /boot --fstype=xfs --size=200
part swap --fstype=swap --size=2048
part / --fstype=xfs --grow --size=200 --asprimary
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Do not configure the X Window System
skipx
# Run the Setup Agent on first boot
firstboot --disable
# Reboot after installation
reboot
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
$SNIPPET('func_install_if_enabled')
@core
@base
tree
nmap
wget
lftp
lrzsz
telnet
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config
sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config
%end
1.9.6同步cobbler配置
[root@ cobbler kickstarts]# cobbler sync
1.9.7新建虚拟测试
注意:把内存调整为2G(否则会出现内存不够的问题)

选择centos7.3回车,等就是了
安装了插件

账号:root
密码:123456

自动创建10.0.0.100为IP地址并成功ping通网络

-------------------------最好的偷懒方式,就是把工作认认真真完成-------------------------

浙公网安备 33010602011771号