Cobbler自动化部署
运维自动化在生产环境中占据着举足轻重的地位,尤其是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操作系统,如果不通过自动化来完成,根本是不可想象的。面对生产环境中不同服务器的需求,该如何实现批量部署多版本的操作系统呢?Cobbler便可以满足这一实际需求,实现多版本操作系统批量部署。
1.1 Cobbler简介
Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP、DNS、TFTP、RSYNC以及yum仓库、构造系统ISO镜像。
Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用,Cobbler客户端Koan支持虚拟机安装和操作系统重新安装。
Cobbler原理:
Cobbler加载原理图
Server端:
- 第一步,启动Cobbler服务
- 第二步,进行Cobbler错误检查,执行cobbler check命令
- 第三步,进行配置同步,执行cobbler sync命令
- 第四步,复制相关启动文件文件到TFTP目录中
- 第五步,启动DHCP服务,提供地址分配
- 第六步,DHCP服务分配IP地址
- 第七步,TFTP传输启动文件
- 第八步,Server端接收安装信息
- 第九步,Server端发送ISO镜像与Kickstart文件
Client端:
- 第一步,客户端以PXE模式启动
- 第二步,客户端获取IP地址
- 第三步,通过TFTP服务器获取启动文件
- 第四步,进入Cobbler安装选择界面
- 第五步,客户端确定加载信息
- 第六步,根据配置信息准备安装系统
- 第七步,加载Kickstart文件
- 第八步,传输系统安装的其它文件
- 第九步,进行安装系统
Cobbler各主要组件关系图:
说明:
distro->profile-system(可选)
distro 发行版
面对不同的操作系统
面对同一个操作系统不同的版本
profile
核心特性是通过kickstart来部署
system
主要目的配置网络接口
1.2 Cobbler功能
使用 Cobbler,您无需进行人工干预即可安装机器。Cobbler 设置一个 PXE 引导环境(它还可使用yaboot 支持 PowerPC),并控制与安装相关的所有方面,比如网络引导服务(DHCP 和 TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler 可以:
使用一个以前定义的模板来配置 DHCP 服务(如果启用了管理 DHCP)
将一个存储库(yum 或 rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
在 DHCP 配置文件中为需要安装的机器创建一个条目,并使用您指定的参数(IP 和 MAC 地址)
在 TFTFP 服务目录下创建适当的 PXE 文件
重新启动 DHCP 服务以反映更改
重新启动机器以开始安装(如果电源管理已启用)
Cobbler 支持众多的发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu 和 SuSE。当添加一个操作系统(通常通过使用 ISO 文件)时,Cobbler 知道如何解压缩合适的文件并调整网络服务,以正确引导机器。
Cobbler 可使用 kickstart 模板。基于 Red Hat 或 Fedora 的系统使用 kickstart 文件来自动化安装流程。通过使用模板,您就会拥有基本的 kickstart 模板,然后定义如何针对一种配置文件或机器配置而替换其中的变量。例如,一个模板可能包含两个变量 $domain和 $machine_name。在 Cobbler配置中,一个配置文件指定 domain=mydomain.com,并且每台使用该配置文件的机器在machine_name 变量中指定其名称。该配置文件中的所有机器都使用相同的 kickstart 安装且针对domain=mydomain.com 进行配置,但每台机器拥有其自己的机器名称。您仍然可以使用 kickstart 模板在不同的域中安装其他机器并使用不同的机器名称。
为了协助管理系统,Cobbler 可通过 fence scripts 连接到各种电源管理环境。
Cobbler 支持apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和 wti。要重新安装一台机器,可运行 reboot system foo命令,而且 Cobbler 会使用必要的凭据和信息来为您运行恰当的 fence scripts(比如机器插槽数)。
除了这些特性,还可使用一个配置管理系统 (CMS)。您有两种选择:该工具内的一个内部系统,或者集成一个现有的外部 CMS,比如 Chef 或 Puppet。借助内部系统,您可以指定文件模板,这些模板会依据配置参数进行处理(与 kickstart 模板的处理方式一样),然后复制到您指定的位置。如果必须自动将配置文件部署到特定机器,那么此功能很有用。
使用 koan 客户端,Cobbler 可从客户端配置虚拟机并重新安装系统。我不会讨论配置管理和koan特性,因为它们不属于本文的介绍范畴。但是,它们是值得研究的有用特性。
1.3 基础环境准备
[root@cobbler tools]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@cobbler tools]# uname -r
2.6.32-504.el6.x86_64
#更改主机名称:
hostname cobbler
sed -i 's#HOSTNAME=template.com#HOSTNAME=cobbler#g' /etc/sysconfig/network
#配置域名解析地址
[root@cobbler tools]# echo "cobbler 192.168.30.130" >/etc/hosts
[root@cobbler tools]# tail -1 /etc/hosts
cobbler 192.168.30.130
#关闭iptable
[root@cobbler pxe]# /etc/init.d/iptables stop
[root@cobbler pxe]# getenforce
Disabled
备注:
提示:
虚拟机网卡采用NAT模式,因为我们会搭建DHCP服务器,在同一局域网多个DHCP服务会有冲突,并且导致实践失败。
注意:生产环境单独在交换机上面划分一个专用VLAN,设置不同网段,用来批量安装系统。禁止混用。
1.4安装cobbler
yum install httpd dhcp tftp cobbler cobbler-web -y
软件说明:
cobbler #cobbler程序包 cobbler-web #cobbler的web服务包 pykickstart #cobbler检查kickstart语法错误 httpd #Apache web服务 /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日志
1.5 检测Cobbler
cobbler的运行依赖于dhcp、tftp、rsync及dns服务,其中dhcp可由dhcpd(isc)提供,也可由dnsmasq提供;tftp可由tftp-server程序包提供,也可由cobbler功能提供,rsync有rsync程序包提供,dns可由bind提供,也可由dnsmasq提供
cobbler可自行管理这些服务中的部分甚至是全部,但需要配置/etc/cobbler/settings
文件中的“manange_dhcp”、“manager_tftpd”、“manager_rsync”、“manager_dns”分别来进行定义,另外,由于各种服务都有着不同的实现方式,如若需要进行自定义,需要通过修改/etc/cobbler/modules.conf
配置文件中各服务的模块参数的值来实现。
#别直接start启动,会报错 [root@cobbler tools]# /etc/init.d/httpd restart 停止 httpd:[确定] 正在启动 httpd:httpd: apr_sockaddr_info_get() failed for cobbler httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [确定] #别直接start启动,会报错 [root@cobbler tools]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [确定] Starting cobbler daemon: [确定]
检查配置文件,需要在cobblerd和httpd启动的情况下检查
[root@cobbler-node1 ~]# cobbler check #检查存在的问题,逐一解决
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. 解决办法:
方式一:
sed -i 's/server: 127.0.0.1/server: 192.168.30.130/' /etc/cobbler/settings (其它配置文件方法相同)
方式二: [root@cobbler tools]# vi /etc/cobbler/settings server: 192.168.30.130 #修改384行,把127.0.0.1 修改为本地网卡的ip地址。 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. 解决办法: [root@cobbler tools]# vi /etc/cobbler/settings next_server: 192.168.30.130 #修改271行,把127.0.0.1 修改为本地网卡的ip地址。 3 : change 'disable' to 'no' in /etc/xinetd.d/tftp 解决办法: [root@cobbler tools]# vi /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no #这里需要开启,把yes改成no per_source = 1 cps = 100 2 flags = IPv4 } "/etc/xinetd.d/tftp" 18L, 517C written 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. 解决办法: [root@cobbler tools]# cobbler get-loaders 5 : change 'disable' to 'no' in /etc/xinetd.d/rsync 解决办法: [root@cobbler tools]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no #把yes改成no,意思就是打开rsync flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 6 : file /etc/xinetd.d/rsync does not exist 解决办法: [root@cobbler tools]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no #把yes改成no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 解决办法: [root@cobbler tools]# /etc/init.d/xinetd restart 停止 xinetd:[失败] 正在启动 xinetd:[确定] 7 : debmirror package is not installed, it will be required to manage debian deployments and repositories 提示说debmirror没安装。如果不是安装 debian之类的系统,此提示可以忽略,如果需要安装, 下载地址为: http://rpmfind.net/linux/rpm2html/search.php?query=debmirror 8 : ksvalidator was not found, install pykickstart 解决办法: [root@cobbler tools]# yum install pykickstart -y 9 : 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 解决办法: #先用你的用户名和密码,生成一段加密后的密码: 用户名:root, 密码:1qaz@WSX [root@cobbler ~]# openssl passwd -1 -salt 'root' '1qaz@WSX' $1$root$GW872S0CPJMETAxxvDcsk0 [root@cobbler tools]# vi /etc/cobbler/settings #修改101行 default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" 10 : 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. 解决方法: fencing tools,我们直接使用yum install -y fence-agents命令安装即可。 最后有提示说,相关的东西改了,要重启cobbler并执行cobbler sync才会生效的哦。 我们将系统重启后,安装了fence-agents后,启动cobbler并执行cobbler sync.
解决完错误提示:
重启cobblerd
[root@cobbler tools]# /etc/init.d/cobblerd restart
Stopping cobbler daemon: [确定]
Starting cobbler daemon: [确定]
再检查错误:
[root@cobbler tools]# cobbler check The following are potential configuration items that you may want to fix: 1 : file /etc/xinetd.d/rsync does not exist [root@cobbler tools]# /etc/init.d/xinetd restart 2 : 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 #Centos系统直接忽略这个错误
1.6、配置dhcp
[root@cobbler tools]# vi /etc/cobbler/settings manage_dhcp: 1 #把0改成1 #使用cobbler管理dhcp
快速操作方法:
sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings
#修改dhcp模板文件: [root@cobbler tools]# vi /etc/cobbler/dhcp.template subnet 192.168.30.0 netmask 255.255.255.0 { option routers 192.168.30.2; option domain-name-servers 192.168.30.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.30.10 192.168.30.54; default-lease-time 21600; max-lease-time 43200; next-server $next_server;
1.7 同步Cobbler
[root@cobbler tools]# cobbler sync task started: 2017-05-02_010406_sync task started (id=Sync, time=Tue May 2 01:04:06 2017) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/pxelinux.cfg/default removing: /var/lib/tftpboot/grub/efidefault removing: /var/lib/tftpboot/grub/grub-x86_64.efi removing: /var/lib/tftpboot/grub/images removing: /var/lib/tftpboot/grub/grub-x86.efi removing: /var/lib/tftpboot/s390x/profile_list copying bootloaders trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering DHCP files generating /etc/dhcp/dhcpd.conf 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: dhcpd -t -q received on stdout: received on stderr: running: service dhcpd restart received on stdout: 正在启动 dhcpd:[确定] received on stderr: 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 ***
检查生成的配置文件
[root@cobbler tools]# cat /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Mon May 1 17:04:07 2017) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ddns-update-style interim; allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 192.168.30.0 netmask 255.255.255.0 { option routers 192.168.30.2; option domain-name-servers 192.168.30.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.30.10 192.168.30.54; default-lease-time 21600; max-lease-time 43200; next-server 192.168.30.130; class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } } } # group for Cobbler DHCP tag: default group { }
1.8管理Cobbler
1.8.1管理distro
cobbler变得可用的第一步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。
如果已经有完成的安装树(如os的安装镜像)则推荐使用improt之间导入的方式进行。
#插入一个光盘镜像到光驱中。
[root@cobbler tools]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
# --path 镜像路径
# --name 为安装源定义一个名称
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:Centos-6.6-x86_64。
# 镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/links下的Centos-6.6-x86_64目录下。
因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。
[root@cobbler tools]# cobbler import --path=/mnt/ --name Centos-6.6-x86_64 --arch=x86_64
task started: 2017-05-02_011038_import
task started (id=Media import, time=Tue May 2 01:10:38 2017)
task started (id=Media import, time=Tue May 2 01:10:38 2017)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos-6.6-x86_64:
creating new distro: Centos-6.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-6.6-x86_64 -> /var/www/cobbler/links/Centos-6.6-x86_64
creating new profile: Centos-6.6-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos-6.6-x86_64 for Centos-6.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-6.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-6.6-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-6.6-x86_64/repodata
*** TASK COMPLETE ***
1.8.2 查看导入信息
[root@cobbler tools]# cobbler profile report Name : Centos-6.6-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-6.6-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 #指定kickstarts文件,这里我们用自己做好的模板文件,不用系统默认的。 [root@cobbler kickstarts]# cd /var/lib/cobbler/kickstarts 例如:sample_end.ks ===>系统默认kickstarts模板文件
模板文件:CentOS-6.6-x86_64.cfg
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
#Partition information
part /boot --fstype ext4 --size 1024 --ondisk sda
part swap --size=1500
part / --fstype ext4 --size 1 --grow --ondisk sda
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
#network --bootproto=dhcp --device=em1
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
%packages
@base
@compat-libraries
@debugging
@development
tree
nmap
sysstat
lrzsz
dos2unix
telnet
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%post
%end
#定制开始显示网站
[root@cobbler ~]# cd /etc/cobbler/pxe
[root@cobbler pxe]# cat pxedefault.template
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT $pxe_timeout_profile
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
$pxe_menu_items
MENU end
复制粘贴的,上传到服务器,记得dos2unix处理一下。
1.8.3 管理profile
cobbler使用profile来为特定的需求类别提供锁需要安装的配置,即在distro的基础上通过提供kiskstart文件来生成一个特定的系统安装配置。distro的profile可以出现在pxe的引导菜单中作为安装的选择之一.
[root@cobbler kickstarts]# cobbler profile edit --name=CentOS-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.cfg
查看导入信息
[root@cobbler kickstarts]# cobbler profile report Name : CentOS-6.6-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-6.6-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS-6.6-x86_64.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 : kvm
再同步一下同步Cobbler
[root@cobbler kickstarts]# cobbler sync
task started: 2017-05-02_020005_sync
task started (id=Sync, time=Tue May 2 02:00:05 2017)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/Centos-6.6-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/images/Centos-6.6-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying files for distro: Centos-6.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-6.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-6.6-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: Centos-6.6-x86_64
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-6.6-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/Centos-6.6-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-6.6-x86_64/initrd.img
Writing template files for Centos-6.6-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: Centos-6.6-x86_64
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
received on stdout: 关闭 dhcpd:[确定]
正在启动 dhcpd:[确定]
received on stderr:
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 ***
致此就安装完成啦!
1.9 部署操作系统
新建一台虚拟机,通过网络启动即可。(我这里虚拟机使用的是NAT模式,并且关闭DHCP功能)
选择CentOS-6.6-x86_64,回车就会自动化安装系统。
安装完成系统,登录账号如下:
用户:root
密码:1qaz@WSX
备注:
更多高级用法,参考官方文档
地址:http://cobbler.github.io/manuals/2.8.0/
CentOS7.2版本安装Cobbler
一、系统环境配置
#查看版本号 [root@template ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@template ~]# uname -r 3.10.0-327.el7.x86_64 #关闭防火墙 [root@template ~]# getenforce Disabled [root@template ~]# systemctl stop firewalld #查看本机网卡ip [root@cobbler-server ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}' 192.168.30.131 #设置主机名 [root@template ~]# hostname template.com [root@template ~]# hostname cobbler-server [root@template ~]# hostnamectl set-hostname cobbler-server #添加hosts解析 [root@cobbler-server ~]# echo "cobbler-server 192.168.30.131" >/etc/hosts [root@cobbler-server ~]# tail -1 /etc/hosts cobbler-server 192.168.30.131
二、安装Cobbler
[root@cobbler-node1 ~]# yum install cobbler cobbler-web pykickstart httpd dhcp xinetd -y #cobblerd和httpd启动服务 [root@cobbler-server ~]# systemctl start httpd [root@cobbler-server ~]# systemctl start cobblerd #检查存在的问题,逐一解决 [root@cobbler-server ~]# 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地址或主机名 sed -i 's/server: 127.0.0.1/server: 192.168.30.131/' /etc/cobbler/settings 2、修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址,如 sed -i 's/next_server: 127.0.0.1/next_server: 192.168.30.131/' /etc/cobbler/settings 3、修改/etc/xinetd.d/tftp文件中的disable参数修改为 disable = no , [root@cobbler-server ~]# systemctl restart xinetd.service [root@cobbler-server ~]# netstat -anltup|grep :69 udp 0 0 0.0.0.0:69 0.0.0.0:* 13953/xinetd 4、执行 cobbler get-loaders 命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中; 5、执行 systemctl enable rsyncd命令即可; 6、如果有强迫症可以选择yum install debmirror -y 然后根据错误进行解决,一般错误如下。 注释vi /etc/debmirror.conf文件中的
@dists=”sid”; @arches=”i386”; 7、生成开机用户和加密密码 [root@cobbler-server ~]# openssl passwd -1 -salt 'root' '1qaz@WSX' $1$root$GW872S0CPJMETAxxvDcsk0 #手工修改101行 vi /etc/cobbler/settings default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" #检查修改结果: [root@cobbler-server ~]# grep "default_password_crypted" /etc/cobbler/settings default_password_crypted: "$1$root$GW872S0CPJMETAxxvDcsk0" 8、安装install cman or fence-agents [root@cobbler-server ~]# yum install fence-agents -y 最后重启Cobbler:systemctl restart cobblerd [root@cobbler-server ~]# systemctl restart httpd [root@cobbler-server ~]# systemctl restart cobblerd
三、配置dhcp
#修改配置文件 [root@cobbler-server ~]# sed -i 's#manage_dhcp: 0#manage_dhcp: 1#g' /etc/cobbler/settings #修改dhcp模板文件 vi /etc/cobbler/dhcp.template [root@cobbler-server ~]# cp /etc/cobbler/dhcp.template /etc/cobbler/dhcp.template.backup [root@cobbler-server ~]# ll /etc/cobbler/dhcp.* -rw-r--r-- 1 root root 2946 11月 17 03:09 /etc/cobbler/dhcp.template -rw-r--r-- 1 root root 2946 5月 3 00:11 /etc/cobbler/dhcp.template.backup #修改dhcp配置文件 [root@cobbler-server ~]#vi /etc/cobbler/dhcp.template subnet 192.168.30.0 netmask 255.255.255.0 { option routers 192.168.30.2; option domain-name-servers 192.168.30.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.30.100 192.168.30.254; default-lease-time 21600; max-lease-time 43200; next-server $next_server; [root@cobbler-server cobbler]# cobbler sync task started: 2017-05-03_004727_sync task started (id=Sync, time=Wed May 3 00:47:27 2017) 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 generating PXE menu structure rendering DHCP files generating /etc/dhcp/dhcpd.conf 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: dhcpd -t -q received on stdout: received on stderr: running: service dhcpd restart 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 *** #栓查生成的配置文件 [root@cobbler-server cobbler]# cat /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Tue May 2 16:47:28 2017) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ddns-update-style interim; allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 192.168.30.0 netmask 255.255.255.0 { option routers 192.168.30.2; option domain-name-servers 192.168.30.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.30.100 192.168.30.254; default-lease-time 21600; max-lease-time 43200; next-server 192.168.30.131; #这里会自动生成本机ip地址 class "pxeclients" { match if substring (option vendor-class-identifier, 0, 9) = "PXEClient"; if option pxe-system-type = 00:02 { filename "ia64/elilo.efi"; } else if option pxe-system-type = 00:06 { filename "grub/grub-x86.efi"; } else if option pxe-system-type = 00:07 { filename "grub/grub-x86_64.efi"; } else { filename "pxelinux.0"; } } } # group for Cobbler DHCP tag: default group { } #管理Cobbler [root@cobbler-server cobbler]# mount /dev/cdrom /mnt mount: /dev/sr0 写保护,将以只读方式挂载 [root@cobbler-server cobbler]# cobbler import --path=/mnt/ --name Centos-7.2-x86_64 --arch=x86_64 # --path 镜像路径 # --name 为安装源定义一个名字 # --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64 # 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:Centos-7.2-x86_64。 # 镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的Centos-7.2-x86_64目录下。因此/var/www/cobbler目录必须具有足够容纳安装文件的空间。 task started: 2017-05-03_005108_import task started (id=Media import, time=Wed May 3 00:51:08 2017) Found a candidate signature: breed=redhat, version=rhel6 Found a candidate signature: breed=redhat, version=rhel7 Found a matching signature: breed=redhat, version=rhel7 Adding distros from path /var/www/cobbler/ks_mirror/Centos-7.2-x86_64: creating new distro: Centos-7.2-x86_64 trying symlink: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 -> /var/www/cobbler/links/Centos-7.2-x86_64 creating new profile: Centos-7.2-x86_64 associating repos checking for rsync repo(s) checking for rhn repo(s) checking for yum repo(s) starting descent into /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 for Centos-7.2-x86_64 processing repo at : /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.2-x86_64 looking for /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.2-x86_64/repodata *** TASK COMPLETE *** [root@cobbler-server cobbler]# cobbler distro list Centos-7.2-x86_64 [root@cobbler-server cobbler]# cobbler profile report Name : Centos-7.2-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-7.2-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 #进入存放目录 [root@cobbler-server cobbler]# cd /var/lib/cobbler/kickstarts/ [root@cobbler-server kickstarts]# ls default.ks install_profiles sample_autoyast.xml sample_esxi4.ks sample_old.seed esxi4-ks.cfg legacy.ks sample_end.ks sample_esxi5.ks sample.seed esxi5-ks.cfg pxerescue.ks sample_esx4.ks sample.ks #上传CentOS-7.1-x86_64.cfg配置文件 [root@cobbler-server kickstarts]# rz -y rz waiting to receive. ???a? zmodem ′???£ °′ Ctrl+C ???£ ??′?? CentOS-7.1-x86_64.cfg... 100% 1 KB 1 KB/s 00:00:01 0 ′? #检查配置文件 [root@cobbler-server kickstarts]# ll -rw-r--r-- 1 root root 1450 5月 16 2016 CentOS-7.2-x86_64.cfg #指定kickstarts路径(如果上面是通过上传的配置文件,可以省略这步。) [root@cobbler-server kickstarts]# cobbler profile add --name=CentOS-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.2-x86_64.cfg usage ===== cobbler profile add cobbler profile copy cobbler profile dumpvars cobbler profile edit cobbler profile find cobbler profile getks cobbler profile list cobbler profile remove cobbler profile rename cobbler profile report CentOS7系统网卡名变成eno....这种,为了运维标准化,我们需要修改为我们常用的eth0,使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。 #修改centos7内核 cobbler profile edit --name=CentOS-7.2-x86_64 --kopts='net.ifnames=0 biosdevname=0' 新部署机器安装yum源,并同步。建议使用内网yum源,在这里使用阿里云yum源(如果不配置自己定制的内网yum源,省略这步) [root@cobbler-node1 ~]# cobbler repo add --name=base --mirror=http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/ --arch=x86_64 --breed=yum#添加yum源 [root@cobbler-node1 ~]# cobbler reposync #同步yum源 #每次修改profile都需要同步 [root@cobbler-server ~]# cobbler sync task started: 2017-05-03_011112_sync task started (id=Sync, time=Wed May 3 01:11:12 2017) running pre-sync triggers cleaning trees removing: /var/www/cobbler/images/Centos-7.2-x86_64 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/images/Centos-7.2-x86_64 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 files for distro: Centos-7.2-x86_64 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/Centos-7.2-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/Centos-7.2-x86_64/initrd.img copying images generating PXE configuration files generating PXE menu structure copying files for distro: Centos-7.2-x86_64 trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/Centos-7.2-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/Centos-7.2-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/Centos-7.2-x86_64/initrd.img Writing template files for Centos-7.2-x86_64 rendering DHCP files generating /etc/dhcp/dhcpd.conf rendering TFTPD files generating /etc/xinetd.d/tftp processing boot_files for distro: Centos-7.2-x86_64 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 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 *** 服务端时时查看日志 [root@cobbler-server ~]# tail -f /var/log/messages May 3 01:11:13 template dhcpd: Listening on LPF/eth0/00:0c:29:a5:0c:91/192.168.30.0/24 May 3 01:11:13 template dhcpd: Sending on LPF/eth0/00:0c:29:a5:0c:91/192.168.30.0/24 May 3 01:11:13 template dhcpd: Sending on Socket/fallback/fallback-net May 3 01:11:13 template systemd: Started DHCPv4 Server Daemon. May 3 01:14:31 template dhcpd: DHCPDISCOVER from 00:0c:29:d0:75:ed via eth0 May 3 01:14:32 template dhcpd: DHCPOFFER on 192.168.30.132 to 00:0c:29:d0:75:ed via eth0 May 3 01:14:33 template dhcpd: DHCPREQUEST for 192.168.30.132 (192.168.30.131) from 00:0c:29:d0:75:ed via eth0 May 3 01:14:33 template dhcpd: DHCPACK on 192.168.30.132 to 00:0c:29:d0:75:ed via eth0 May 3 01:15:01 template systemd: Started Session 37 of user root. #服务端安装完毕!
三、新建虚拟机,网络设置为NAT
1、开始安装
![](https://images2015.cnblogs.com/blog/1053682/201705/1053682-20170509171737910-1662927268.png)
2、安装完成,登录系统账号
用户名:root
密码:1qaz@WSX