Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支援網絡安裝windows。該工具使用python開發,小巧輕便,使用簡單的指令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP,DNS,以及yum包鏡像。Cobbler支援指令行管理,web界面管理,還提供了API接口,可以友善二次開發使用。和Kickstart不同的是,使用cobbler不會因為在區域網路中啟動了dhcp而導緻有些機器因為預設從pxe啟動在重新開機伺服器後加載tftp内容導緻啟動終止。
http://www.cobblerd.org/
安裝阿裡雲的源
vim /etc/yum.repos.d/aliyun.repo
[aliyun]
name=http://mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos//os/x86_64/
enabled=
gpgcheck=
gpgkey=http://mirrors.aliyun.com/centos//os/x86_64/RPM-GPG-KEY-CentOS-
yum clean all
yum list
cobbler-2.6.3-1.el6.noarch.rpm
cobbler-web-2.6.3-1.el6.noarch.rpm
–這裡的依賴性最後的PyYAML在rhel6.5的iso裡不是自帶的,是以要先手動上網下載下傳并安裝;上面兩個依賴性在rhel6.5的iso裡就有,是以可以直接使用yum來安裝
PyYAML這個依賴性的rpm包在rhel6.5的iso裡沒有,epel源裡沒有,163源沒有,centos源等等都沒有,它的官方網站沒有rpm包.可以嘗試去www.rpmfind.net或rpm.pbone.net網站下載下傳
# rpm -qa |grep cobbler
cobbler--el6.noarch
cobbler-web--el6.noarch
安裝完cobbler,把下面這些元件服務也安裝上
#yum install tftp* rsync xinetd httpd syslinux dhcp* pykickstart
--------------------------------
第二大步:基本配置
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 : 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.
4 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : 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
7 : 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.
–說明:上面我這裡是有7個需求(不同的機器和環境可能會不一樣,按照它的說明去解決就可以了)
解決需求1,需求2,需求6:
# openssl passwd - -salt 'werwqerwqr' '123456' --為密碼(這是自動安裝用戶端系統成功後的root登入密碼),werwqerwqr為幹擾碼(随便寫)
$1$werwqerw$.prcfrYFbwuvkD8XspayN.
# vim /etc/cobbler/settings
server: --換成cobbler伺服器端的IP
next_server: --同上
default_password_crypted: "$1$werwqerw$.prcfrYFbwuvkD8XspayN." --把密碼字元串換成你上面産生的字元串
# /etc/init.d/cobblerd restart --修改後重新開機
解決需求4:
cobbler檢測到你的iptables是開啟狀态,它需要iptables不要禁止69,80,443,25151端口就可以了。你也可以關閉iptables
iptables -F
iptables -t nat -F
/etc/init.d/iptables stop
chkconfig iptables off
解決需求7
解決了上面的問題後,再次cobbler check
The following are potential configuration items that you may want to fix:
1 : 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.
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.
---------------------------------------
第三大步:導入鏡像
以下是相關配置路徑(預設安裝) :
Cobbler 配置主要位置:/var/lib/cobbler/
snippets 代碼 位置:/var/lib/cobbler/snippets/
Kickstart 模闆 位置 : /var/lib/cobbler/kickstarts/
預設使用的ks檔案: /var/lib/cobbler/kickstarts/default.ks
安裝源鏡像 位置 : /var/www/cobbler/ks_mirror/
# ls /var/www/cobbler/ks_mirror/
config
# cobbler import --path=/yum/ --name=rhel-server-6.5-x86_64 --arch=x86_64 --将挂載的鏡像目錄/yum位置導入到cobbler
。。。。。。
*** TASK COMPLETE ***
# ls /var/www/cobbler/ks_mirror/ --導入完後,這裡會多了剛導入的鏡像目錄
config rhel-server--x86_64
# cobbler distro list --清單你cobbler導入的鏡像
rhel-server--x86_64
# cobbler profile list --清單你的cobbler自動安裝方案(從這裡看到你導入一個鏡像會預設做一個與它同名的安裝方案)
rhel-server--x86_64
----------------------------------
第四大步:
修改dhcp,讓cobbler來管理dhcp,并進行cobbler配置同步
修改/etc/cobbler/dhcp.template,此檔案是cobbler管理dhcp的模闆(不需要象kickstart那樣去修改/etc/dhcp/dhcpd.conf,修改了也沒用,它會在後面做cobbler sync時把/etc/cobbler/dhcp.template拷過去覆寫/etc/dhcp/dhcpd.conf檔案,并啟動dhcp)
隻修改下面這一段,改成你自己對應的IP和網段就可以了
subnet netmask {
option routers ;
option domain-name-servers ;
option subnet-mask ;
range dynamic-bootp ;
default-lease-time ;
max-lease-time ;
next-server $next_server;
class "pxeclients" {
match if substring (option vendor-class-identifier, , ) = "PXEClient";
if option pxe-system-type = : {
filename "ia64/elilo.efi";
} else if option pxe-system-type = : {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = : {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
# vim /etc/cobbler/settings --再去修改這個配置檔案,改成dhcp服務由cobbler來管理
242 manage_dhcp: 1 --把0改為1
# cobbler sync --同步cobbler配置,并初始化,幫你啟動dhcp等
。。。。。。
*** TASK COMPLETE ***
# /etc/init.d/xinetd restart --把xinetd服務重新開機一下
第五大步:
測試驗證:建立一個vmnet1網段(因為我前面配置的是這個網段)的虛拟機,然後啟動,會出現cobbler的引導安裝界面,選擇并自動安裝
======================================================================
補充1:
cobbler的web管理
web管理路徑
# /etc/init.d/httpd restart --先最好重新開機一下httpd服務
重新開機時如果報端口被占用,解決方法:
# /etc/init.d/vmware-workstation-server stop
# chkconfig vmware-workstation-server off
然後通過firefox通路下面的路徑
http://IP/cobbler_web –預設使用者名cobbler,密碼cobbler
# htdigest /etc/cobbler/users.digest "Cobbler" abc --增加一個abc使用者
Adding user abc in realm Cobbler
New password:
Re-type new password:
# cat /etc/cobbler/users.digest
cobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3
abc:Cobbler:de5b9d396aa51c6710e62e555a2986ec
=============================================================
補充二:
關于cobbler使用ks檔案的讨論
rhel-server-6.5-x86_64
設定profile(了解為在伺服器端對每一個安裝鏡像做角色分類,如安裝名與ks檔案的關聯)
distro代表導入的鏡像
profile代表安裝方案。一個distro可以對應一個或多個profile
# cobbler profile help --檢視幫助
# cobbler profile list --檢視有哪些profile,預設會有一個和先前導入鏡像同名的profile
rhel-server--x86_64
# cobbler profile report --name rhel-server-6.5-x86_64 |grep "^Kickstart" |head -1 --通過report報告檢視名為rhel-server-6.5-x86_64的安裝鏡像預設使用的ks檔案為/var/lib/cobbler/kickstarts/sample_end.ks
Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks
# cobbler profile add --name=my_ks1 --distro=rhel-server-6.5-x86_64 --kickstart=/ks/ks.cfg
--把名為rhel-server--x86_64的安裝鏡像再加一個名為my_ks1的安裝profile,使用的是/ks/ks.cfg檔案(這是上次課講kickstart時用的,你也可以自己再準備一個都行;但這裡并不建議使用kickstart使用的ks檔案,如果你要自己自定義,最好是去修改cobbler裡的ks模版)
# cobbler profile list --經過上面的操作,最終我導入的rhel-server-6.5-x86_64鏡像擁有兩種安裝方案(一個是同名的安裝方案,使用/var/lib/cobbler/kickstarts/sample_end.ks自動安裝檔案;一個是剛自己加的安裝方案名為my_ks1,使用/ks/ks.cfg自動安裝檔案)
my_ks1
rhel-server--x86_64
再次使用用戶端去安裝驗證,會出現兩種安裝方案給你選擇
對上面操作的擴充(僅供參考)
# cobbler profile edit --name=my_ks1 --kickstart=/ks/ks2.cfg --将my_ks1這個profile修改一個新的ks檔案
# cobbler profile remove --name=my_ks1 --删除my_ks1這個profile
=============================================================
補充三:
針對ks檔案的修改的讨論
上面在補充二時提到,最好不要完全照搬kickstart使用的ks檔案(因為你照搬過來後,很多功能和配置和cobbler不好連接配接)
以上面的名字為rhel-server-6.5-x86_64的profile使用的ks檔案/var/lib/cobbler/kickstarts/sample_end.ks為例來實驗ks檔案的修改
vim /var/lib/cobbler/kickstarts/sample_end.ks
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled
# 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')
# 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 America/New_York
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
part /boot --asprimary --fstype="ext4" --size=
part swap --asprimary --fstype="swap" --size=
part / --asprimary --fstype="ext4" --grow --size= --這裡是把原來的一句autopart改成自己想要的分區形式(原來是分lvm,現在我定義了三個分區)
%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')
%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
touch /root/
touch /tmp/ --在這裡又加了兩句安裝後的腳本,touch了兩個檔案
%end
儲存後,用用戶端安裝rhel-server-6.5-x86_64來進行測試,最後發現分區和上面修改的一緻,并且/root/123和/tmp/123這兩個檔案也都存在,說明上面的修改成功
–總結:在生産環境,你可以按這種方式把cobbler的ks檔案模版,按你的需求改成幾種不同的方案,再使用補充2部分裡講的cobbler profile add把這些ks檔案和安裝鏡像對應起來做成不同的profile
========================================
補充4:
用戶端使用koan與伺服器的cobbler聯系,實作自動重裝系統
在用戶端安裝koan-2.6.9-1.el6.noarch.rpm軟體包
# koan --server=1.1.1.2 --list=profiles --1.1.1.2為cobbler伺服器IP,得到的結果和在cobbler伺服器上cobbler profile list指令得到的結果一樣
my_ks1
rhel-server-6.5-x86_64
# koan --replace-self --server=1.1.1.2 --profile=rhel-server-6.5-x86_64 --指定本用戶端按照名為rhel-server-6.5-x86_64的profile重裝系統
# reboot --敲完上面的指令,使用reboot,就會重裝了(沒敲上面的指令那reboot就是重新開機)
=====================================================================
**假設你的公司有各種linux的安裝需求(rhel,centos,ubuntu,suse,debian等)
你現在要為公司設計所有的自動安裝方案,怎麼做?**