Cobbler介紹
Cobbler官網(wǎng)
Cobbler是一個Linux服務器安裝的服務,可以通過網(wǎng)絡啟動(PXE)的方式來快速安裝、重裝物理服務器和虛擬機,同時還可以管理DHCP、DNS等,是用來實現(xiàn)運維自動化的必備神器。Cobbler可用使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),還提供了API接口,可用方便二次開發(fā)使用。Cobbler是較早前的kickstart的升級版,優(yōu)點是比較容易配置,還自帶web界面易于管理。Cobbler內(nèi)置了一個輕量級配置管理系統(tǒng),但它也支持和其他配置管理系統(tǒng)集成,如puppet,暫時不支持saltstack。
環(huán)境部署準備
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@linux-node1 ~]# getenforce
Disabled
[root@linux-node1 ~]# systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[root@linux-node1 ~]# hostname
linux-node1.example.com
[root@linux-node1 ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2{print $3}'
192.168.56.11
安裝配置Cobbler
[root@linux-node1 ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd -y
[root@linux-node1 ~]# systemctl restart httpd
[root@linux-node1 ~]# systemctl restart cobblerd
[root@linux-node1 ~]# 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.
看上面的結(jié)果,一個一個解決
第1、2、6個問題,順便修改其他功能:
[root@linux-node1 ~]# sed -i 's/server: 127.0.0.1/server: 192.168.56.11/' /etc/cobbler/settings
[root@linux-node1 ~]# sed -i 's/server: 127.0.0.1/server: 192.168.56.11/' /etc/cobbler/settings
[root@linux-node1 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
[root@linux-node1 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
[root@linux-node1 ~]# openssl passwd -1 -salt '91guoxin' '123456'
$1$91guoxin$prqpocNRfiZKPDgyIW4851
[root@linux-node1 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$91guoxin$prqpocNRfiZKPDgyIW4851"
第3個問題:
[root@linux-node1 ~]# cobbler get-loaders
[root@linux-node1 ~]# ls /var/lib/cobbler/loaders/
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
[root@linux-node1 ~]# vim /etc/xinetd.d/tftp
disable = no
[root@linux-node1 ~]# systemctl restart tftp
[root@linux-node1 ~]# systemctl restart cobblerd
修改Cobbler的dhcp模板,不要直接修改dhcp本身的配置文件,因為Cobbler會覆蓋
[root@linux-node1 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.56.0 netmask 255.255.255.0 {
option routers 192.168.56.2;
option domain-name-servers 192.168.56.2;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.56.100 192.168.56.254;
執(zhí)行cobbler sync
[root@linux-node1 ~]# cobbler sync
task started: 2016-05-23_080450_sync
task started (id=Sync, time=Mon May 23 08:04:50 2016)
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 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 ***
再次執(zhí)行cobbler check
[root@linux-node1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : enable and start rsyncd.service with systemctl
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.可用不用理會,因為我們不用rsync同步ISO
- 2.和debian系統(tǒng)相關(guān),不需要
- 3.fence設備相關(guān),不需要
設置開機自啟動:
[root@linux-node1 ~]# systemctl enable httpd.service
[root@linux-node1 ~]# systemctl enable tftp.service
[root@linux-node1 ~]# systemctl enable cobblerd.service
[root@linux-node1 ~]# systemctl enable dhcpd.service
Cobbler的命令行管理
查看命令幫助
[root@linux-node1 ~]# 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@linux-node1 ~]# cobbler import --help
Usage: cobbler [options]
Options:
-h, --help show this help message and exit
--arch=ARCH OS architecture being imported
--breed=BREED the breed being imported
--os-version=OS_VERSION
the version being imported
--path=PATH local path or rsync location
--name=NAME name, ex 'RHEL-5'
--available-as=AVAILABLE_AS
tree is here, don't mirror
--kickstart=KICKSTART_FILE
assign this kickstart file
--rsync-flags=RSYNC_FLAGS
pass additional flags to rsync
Cobbler命令小結(jié):
cobbler check # 核對當前設置是否有問題
cobbler list # 列出所有的cobbler元素
cobbler report # 列出元素的詳細信息
cobbler sync # 同步配置到數(shù)據(jù)目錄,更改配置最好都要執(zhí)行一下
cobbler reposync # 同步y(tǒng)um倉庫
cobbler distro # 查看導入的發(fā)行版系統(tǒng)信息
cobbler system # 查看添加的系統(tǒng)信息
cobbler profile # 查看配置信息
導入鏡像
[root@linux-node1 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
# 掛載CentOS 7.2的系統(tǒng)鏡像,光盤掛載的方式傳輸效率較低,此處僅為實驗
[root@linux-node1 ~]# cobbler import --path=/mnt/ --name=CentOS-7.2-x86_64 --arch=x86_64
task started: 2016-05-23_082109_import
task started (id=Media import, time=Mon May 23 08:21:09 2016)
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 ***
--path 鏡像路徑
--name 為安裝源定義一個名字
--arch 執(zhí)行安裝源是32位、64位、ia64,目前支持的選項有:x86 | x86_64 | ia64
[root@linux-node1 ~]# cobbler distro list
CentOS-7.2-x86_64
[root@linux-node1 ~]# ls /var/www/cobbler/ks_mirror/
CentOS-7.2-x86_64 config
# 鏡像存放目錄,Cobbler會將鏡像中的所有安裝文件拷貝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7.2-x86_64目錄下
指定ks.cfg文件及調(diào)整內(nèi)核參數(shù)
[root@linux-node1 ~]# ls /var/lib/cobbler/kickstarts/
default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample_old.seed
esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks sample_esxi4.ks sample.ks sample.seed
# 自帶很多
[root@linux-node1 ~]# cd /var/lib/cobbler/kickstarts/
[root@linux-node1 kickstarts]# rz -y
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring Cobbler-CentOS-7.1-x86_64.cfg...
100% 1 KB 1 KB/sec 00:00:01 0 Errors
# 上傳準備好的ks文件
[root@linux-node1 kickstarts]# mv Cobbler-CentOS-7.1-x86_64.cfg CentOS-7.2-x86_64.cfg
[root@linux-node1 kickstarts]# cobbler list
distros:
CentOS-7.2-x86_64
profiles:
CentOS-7.2-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
[root@linux-node1 kickstarts]# cobbler distro report --name=CentOS-7.2-X86_64
Name : CentOS-7.2-x86_64
Architecture : x86_64
TFTP Boot Files : {}
Breed : redhat
Comment :
Fetchable Files : {}
Initrd : /var/www/cobbler/ks_mirror/CentOS-7.2-x86_64/images/pxeboot/initrd.img
Kernel : /var/www/cobbler/ks_mirror/CentOS-7.2-x86_64/images/pxeboot/vmlinuz
Kernel Options : {}
Kernel Options (Post Install) : {}
Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS-7.2-x86_64'}
Management Classes : []
OS Version : rhel7
Owners : ['admin']
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Template Files : {}
編輯profile,修改關(guān)聯(lián)的ks文件
[root@linux-node1 kickstarts]# cobbler profile edit --name=CentOS-7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7.2-x86_64.cfg
安裝系統(tǒng)
新建一臺虛擬機:

修改Cobbler提示
[root@linux-node1 ~]# vim /etc/cobbler/pxe/pxedefault.template
MENU TITLE Cobbler | http://www.wanyuetian.com
[root@linux-node1 ~]# cobbler sync
定制化安裝
可能有人想kickstart怎樣能夠指定某臺服務器使用指定ks文件,kickstart實現(xiàn)這功能可能比較復雜,但是Cobbler就很簡單了。區(qū)分一臺服務器的最簡單的方法就是物理MAC地址。物理服務器的MAC地址在服務器上的標簽上寫了。
[root@linux-node1 ~]# cobbler system add --name=cobblertest --mac=00:0C:29:76:73:2D --profile=CentOS-7.2-x86_64 --ip-address=192.168.56.100 --subnet=255.255.255.0 --gateway=192.168.56.2 --interface=eth0 --static=1 --hostname=cobblertest.example.com --name-servers="192.168.56.2"
[root@linux-node1 ~]# cobbler sync
再次開機,如下圖所示:

Cobblerd的web管理界面
https://192.168.56.11/cobbler_web
默認用戶名:cobbler
默認密碼:cobbler
/etc/cobbler/users.conf # Web服務授權(quán)配置文件
/etc/cobbler/users.digest # 用于web訪問的用戶名密碼配置文件
[root@cobbler loaders]# cat /etc/cobbler/users.digest
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3
# 設置Cobbler web用戶登陸密碼
# 在Cobbler組添加cobbler用戶,提示輸入2遍密碼確認
[root@linux-node1 ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler
Changing password for user cobbler in realm Cobbler
New password:
Re-type new password:
[root@linux-node1 ~]# cobbler sync
[root@linux-node1 ~]# systemctl restart httpd
[root@linux-node1 ~]# systemctl restart cobblerd