Cobbler简介
运维自动化包括标准化、工具化、Web化、服务化、智能化等几个不同的层级,在一家规模稍大、拥有服务器上千台甚至是几万台的生产环境中,想要真正实现运维自动化,工具化系统安装流程、统一系统安装规范,是其中最不能忽略的重要环节。普通的自动化部署可以采用pxe+dhcp+tftp配合kickstart实现,但是面对多版本、多部署需求的情况下,这种普通的部署方式可能达不到我们的要求;这时候就需要借助cobbler开源自动化部署工具来实现。
Cobbler是一款快速的网络系统部署工具,其最大的特点是集合了所有系统部署所需服务,如DHCP、DNS、TFTP,这样你在部署一台操作系统的时候不需要在各个服务之前协调切换,Cobbler都可以替你来管理,Cobbler内部集成了一个镜像版本仓库,你可以自定义相关配置文件,实现不同系统不同安装需求的选择;当然,Cobbler还提供了包括yum源管理、Web界面管理、API接口、电源管理等功能,方便你自定义开发管理
发行版:表示一个操作系统。它承载了内核和 initrd 的信息,以及内核参数等其他数据
配置文件:包含一个发行版、一个 kickstart 文件以及可能的存储库,还包含更多特定的内核参数等其他数据
系统:表示要配给的机器。它包含一个配置文件或一个镜像,还包含 IP 和 MAC 地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息
存储库:保存一个 yum 或 rsync 存储库的镜像信息
镜像:可替换一个包含不属于此类别的文件的发行版对象(例如,无法分为内核和 initrd 的对象)
Cobbler部署
实验环境(网段192.168.1.0/24)
[root@cobbler ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@cobbler ~]# uname -r
3.10.0-327.el7.x86_64
环境要求
关闭防火墙 systemctl stop firewalld.service
systemctl enable firewalld.service
关闭selinux setenforce 0
vim /etc/sysconfig/selinux
SELINUX=enforcing 修改成 SELINUX=disabled
添加中文:echo "export LANG=zh_CN" >>/etc/profile
source /etc/profile
1)安装epel源
[root@cobbler ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
获取http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
警告:/var/tmp/rpm-tmp.NdKVNp: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:epel-release-7-9 ################################# [100%]
2)安装相关服务组件
yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xinetd
systemctl start cobblerd
systemctl start httpd
systemctl start xinetd
#############################################################################
安装完成后启动服务,我们先来看看cobbler的一些重要文件目录
/etc/cobbler # 配置文件目录
/etc/cobbler/settings # cobbler主配置文件
/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/images # 导入的系统镜像启动文件
/var/www/cobbler/repo_mirror # yum源存储目录
/var/log/cobbler # 日志目录
/var/log/cobbler/install.log # 客户端系统安装日志
/var/log/cobbler/cobbler.log # cobbler日志
/etc/cobbler/settings中几个比较重要的参数设置
manage_dhcp:1
manage_dns:1
manage_tftpd:1
restart_dhcp:1
restart_dns:1
pxe_just_once:1
next_server:<服务器的 IP 地址>
server:<服务器的 IP 地址>
#选项 next_server 用在 DHCP 配置文件中,向机器告知提供引导文件的服务器地址。选项 server 在机器
安装期间用于引用 Cobbler 服务器地址。最后,选项 pxe_just_once 预防将机器中的安装循环配置为始终从网络引导。
激活此选项时,机器告诉 Cobbler 安装已完成。Cobbler 将系统对象的 netboot 标志更改为 false,这会强制机器从本地磁盘引导
###################################################################################################
3)初始化cobbler
cobbler check
[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 : 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 : enable and start rsyncd.service with systemctl
7 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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.
上面是告诉我们要对cobbler做的一些初始化设置,接下来一步步设置即可
①修改/etc/cobbler/settings配置文件
272 next_server: 192.168.1.161 #如果配置过kickstart知道,这里是告诉启动文件服务器下载地址
②修改/etc/cobbler/settings cobbler主机地址
384 server: 192.168.1.161 #cobbler主机服务器地址
③开启TFTP服务
[root@linux-node1 ~]# vim /etc/xinetd.d/tftp
disable = no
④运行cobbler get-loaders下载一些网络引导文件
[root@linux-node1 ~]# cobbler get-loaders
⑤开启rsyncd服务
[root@linux-node1 ~]# systemctl start rsyncd
⑥debian库服务,这里我们可以忽略
⑦创建系统初始化后的root密码
[root@linux-node1 ~]# openssl passwd -1 -salt 'cobbler' 'cobbler'
$1$cobler$XJnisBweZJlhL651HxAM00
[root@linux-node1 ~]# vim /etc/cobbler/settings
101 default_password_crypted: "$1$cobler$XJnisBweZJlhL651HxAM00"
⑧电源模块支持,我们暂时不需要,忽略
再次执行检查结果
systemctl restart cobblerd
cobbler check
########################################################################################################################################
[root@cobbler ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : 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
2 : enable and start rsyncd.service with systemctl
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : 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.
#########################################################################################################################################
systemctl start rsyncd.service
systemctl restart rsyncd.service
4)让cobbler管理DHCP
如果我们需要让cobbler替我们管理DHCP服务器,需要修改以下配置
[root@linux-node1 ~]# vim /etc/cobbler/settings
242 manage_dhcp: 1 #改为数字1
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template #重启cobbler后,cobbler会生成一个模板文件
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.161; #路由地址
option domain-name-servers 192.168.1.161; #DHCP服务器地址
option subnet-mask 255.255.255.0; #掩码
range dynamic-bootp 192.168.1.130 192.168.1.140; #DHCP地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
5)重启cobbler,并sync生成各种新的配置文件
[root@linux-node1 ~]# systemctl restart cobblerd
[root@linux-node1 ~]# cobbler sync
######################################################################################################
task started: 2016-08-25_114015_sync
task started (id=Sync, time=Thu Aug 25 11:40:15 2016)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders #拷贝自身引导文件
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 #启动PXE程序
generating PXE menu structure
rendering DHCP files #配置DHCP服务
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files #配置TFTP服务
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: dhcpd -t -q
received on stdout:
received on stderr:
running: service dhcpd restart #重启DHCP
received on stdout:
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE *** #完成
##################################################################################################
6)接下来,我们就可以在cobbler中加入一个完成的系统安装镜像
########################################################################################################################
[root@linux-node1 ~]# mount /dev/cdrom /mnt #在光驱中加载一个完成的centos7 ISO文件 #如果需要,如果不需要这一步可以不用
mount: /dev/sr0 is write-protected, mounting read-only
########################################################################################################################
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=/CentOS-7-x86_64 --arch=x86_64 #使用import导入
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=/CentOS-6-x86_64 --arch=x86_64
#同样方式导入一个centos6镜像
[root@linux-node1 ~]# cobbler profile list #查看镜像目录
CentOS-6-x86_64
CentOS-7-x86_64
[root@linux-node1 ~]# cobbler profile report #查看cobbler系统仓库中的版本信息
Name : CentOS-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7-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文件
7)上传相关的kickstart文件,修改cobbler默认KS配置
[root@linux-node1 ~]# cd /var/lib/cobbler/kickstarts/
[root@linux-node1 kickstarts]# ll
total 60
-rw-r--r-- 1 root root 3701 Aug 25 21:55 CentOS-6-x86_64.cfg
-rw-r--r-- 1 root root 1467 Aug 26 02:07 CentOS-7-x86_64.cfg
[root@linux-node1 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg #上传完成后修改成我们自己的ks文件
[root@linux-node1 kickstarts]# cobbler profile edit --name=CentOS-6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6-x86_64.cfg
[root@linux-node1 ~]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0
8)修改配置文件记得重启cobbler并执行sync
[root@linux-node1 ~]# systemctl restart xinetd
[root@linux-node1 ~]# systemctl restart cobblerd.service
[root@linux-node1 ~]# cobbler sync
9)网络启动一台新主机,测试cobbler
10、Web管理Cobbler
[root@linux-node1 cobbler]# cat users.conf
#配置web界面用户文件,生成密码
[root@linux-node1 cobbler]# htdigest /etc/cobbler/users.digest "cobbler" cobbler
Changing password for user cobbler in realm Cobbler
New password:
Re-type new password:
[root@linux-node1 ~]# cat /etc/cobbler/pxe/pxedefault.template #自定义cobbler安装界面
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | tongxianlei@foorich.com
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
[root@linux-node1 ~]# cobbler sync
web 页面如下
#############################################################################
centos6.8 安装中文桌面版
[root@cobbler kickstarts]# more Centos6.8-x86_64.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password
rootpw --iscrypted $1$PcPZqkWe$YWlduc9tTPcmM2dxCKbSg0
# System authorization information
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.140.129/cdrom"
# Root password
rootpw --iscrypted $1$PcPZqkWe$YWlduc9tTPcmM2dxCKbSg0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
reboot
# System timezone
timezone Africa/Abidjan
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --size=2048
part /boot --fstype="ext4" --size=200
part / --fstype="ext4" --grow --size=1
%packages
@base
@chinese-support
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@workstation-policy
@x11
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisoimage
device-mapper-persistent-data
abrt-gui
samba-winbind
certmonger
pam_krb5
krb5-workstation
libXmu
%end
#############################################################################
Centos7 中文桌面版
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Root password
rootpw --iscrypted $1$8xPsaxh6$GKFeybI8yHUV0poC57x/k1
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN.UTF-8
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --grow --size=1
%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
#############################################################################