歡迎您光臨本站 註冊首頁

在 CentOS 6.2 上安裝 Cobbler

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

在 CentOS 6.2 上安裝 Cobbler

每次給自己的電腦重裝系統都是一件很無聊的事情,如果需要重裝上百台虛擬機和伺服器不但很無聊而且很耗時,面對現在雲時代大量伺服器和虛擬機的出現,運維必須要自動化。現在有很多開源工具可以幫助我們實現自動化安裝系統,比如 FAI, Cobbler, Spacewalk, Ubuntu Orchestra 等,我們打算把 Cobbler 安裝在某台虛擬機上,為我們新購的16台刀片伺服器自動安裝系統。

Cobbler 是一個系統啟動服務(boot server),可以通過網路啟動(PXE)的方式用來快速安裝、重裝物理伺服器和虛擬機,支持安裝不同的 Linux 發行版和 Windows. Cobbler 是個輕量級 Python 程序,總共大概1.5萬行代碼,還可以用來管理 DHCP, DNS, yum 源等。Cobbler 使用命令行方式管理,也提供了基於 Web 的界面管理工具(cobbler-web),不過命令行方式已經很方便,實在沒有必要為了不實用的 Web 界面再添加一個 Web 伺服器。
修改 DHCP 伺服器配置

使用 Cobbler 最好配合現有區域網上的 DHCP 伺服器一起使用,這樣不會因為 Cobbler 干擾現有區域網。我們不打算用 Cobbler 來管理整個網路的 DHCP,因為我們已經有了 DHCP 伺服器,所以只要在現有的 DHCP 伺服器上做以下配置即可,下面記得調整 192.168.2.22 這個 IP 地址指向 Cobbler 伺服器:

# for Cobbler setup
host cobbler {
    option host-name "cobbler";
    ddns-hostname "cobbler";
    hardware ethernet 00:0c:29:2d:2c:39; #MAC address of cobbler server
            fixed-address 192.168.2.22; #IP of Cobbler server
            allow booting;
    allow bootp;
    class "PXE" {
        match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
        next-server 192.168.2.22; #IP of Cobbler server
            filename "pxelinux.0";
    }
}

安裝和配置 Cobbler

Cobbler 不在 CentOS 6.2 的基本源中,需要導入 EPEL 源:

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
warning: /var/tmp/rpm-tmp.lo2Hd0: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ###########################################
   1:epel-release           ###########################################

# yum update
# yum upgrade

安裝 cobbler:

# yum install cobbler

修改配置,主要修改 cobbler 伺服器所在的 IP 地址:

# vi /etc/cobbler/settings
...
next_server: 192.168.2.22 #IP of Cobbler server
server: 192.168.2.22 #IP of Cobbler server
...

啟用 httpd, xinetd 和 cobbler 服務並確認已經加到系統自動啟動服務中:

# /etc/init.d/httpd start
# /etc/init.d/xinetd start
# /etc/init.d/cobblerd start

# chkconfig httpd on
# chkconfig xinetd on
# chkconfig cobblerd on

修改 rsync 和 tftp 這兩個服務的 xinetd 配置:

# vi /etc/xinetd.d/rsync
service rsync
{
        disable = no
...
}

# vi /etc/xinetd.d/tftp
service tftp
{
        ...
        disable = no
        ...
}

關閉防火牆和 SELinux 后重啟系統:

# /etc/init.d/iptables stop
# chkconfig iptables off

# vi /etc/sysconfig/selinux
...
SELINUX=disabled
...

# reboot

檢查和修改 Cobbler 配置

系統重啟後用 cobbler check 檢查發現3個配置信息問題,第一個是如果要部署 debian/ubuntu 系統需要 debmirror 軟體包;第二個是需要修改 cobbler 的默認密碼;第三個是可選,想使用電源管理功能的話需要安裝 cman 或 fence-agents:

# cobbler get-loaders

# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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
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.

現在來修復上面三個問題,我們希望能讓這台 cobbler 伺服器能同時部署 CentOS/Fedora 和 Debian/Ubuntu 系統,所以需要安裝 debmirror,安裝 debmirror-20090807-1.el5.noarch.rpm 前需要先安裝依賴包:

# yum install wget
# yum install ed patch perl perl-Compress-Zlib perl-Cwd perl-Digest-MD5 \
perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl

# wget ftp://fr2.rpmfind.net/linux/epel/5/ppc/debmirror-20090807-1.el5.noarch.rpm

# rpm -ivh debmirror-20090807-1.el5.noarch.rpm

修改 /etc/debmirror.conf 配置文件,註釋掉 @dists 和 @arches 兩行:

# vi /etc/debmirror.conf
...
#@dists="sid";
@sections="main,main/debian-installer,contrib,non-free";
#@arches="i386";
...

用 openssl 生成一串密碼后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替換 default_password_crypted 欄位:

# openssl passwd -1 -salt 'www.vpsee.com' 'vpsee'
$1$www.vpsee$T5FgCHY2P0NDr6JmbN0Bl0

# vi /etc/cobbler/settings
default_password_crypted: "$1$www.vpsee$T5FgCHY2P0NDr6JmbN0Bl0"

安裝 cman:

# yum install cman

修復完成,再用 cobbler check 檢查一下,確認沒問題後用 cobbler sync 做同步操作:

# cobbler check
No configuration problems found.  All systems go.

# cobbler sync

導入 ISO

掛載 CentOS-6.2-x86_64-bin-DVD1.iso 安裝光碟然後導入到 cobbler(注意這個 iso 文件有 4GB 多,導入可能需要一段時間),導入成功后 cobbler list 查看一下:

# mount -o loop -t iso9660 CentOS-6.2-x86_64-bin-DVD1.iso /mnt

# cobbler import --path=/mnt --name=CentOS-6.2-x86_64-bin-DVD1 –arch=x86_64

# cobbler sync

# cobbler list
distros:
   CentOS-6.2-bin-DVD1-x86_64

profiles:
   CentOS-6.2-bin-DVD1-x86_64

systems:

repos:

images:

測試

最後創建一台虛擬機測試一下,把虛擬機設置成網路 PXE 啟動(和 cobbler 在同一個網路),啟動后就可以看到 Cobbler 引導界面,看到界面后選擇 CentOS-6.2-bin-DVD1-x86_64 條目就可以順利開始無人工干預安裝系統,Cobbler 引導界面如下:
http://www.vpsee.com/wp-content/uploads/2012/03/boot-from-cobbler-net-pxe.png

boot os from cobbler net pxe

安裝完系統后默認的密碼是啥呢?根據 sample.ks 的配置提示,這個密碼 $default_password_crypted 就是我們上面用 openssl passwd -1 -salt 『www.vpsee.com』 『vpsee』 生成的密碼,所以這裡的 root 密碼是 vpsee:

# cat /var/lib/cobbler/kickstarts/sample.ks
...
#Root password
rootpw --iscrypted $default_password_crypted


http://www.vpsee.com/2012/03/install-cobbler-on-centos-6-2/

[火星人 ] 在 CentOS 6.2 上安裝 Cobbler已經有703次圍觀

http://coctec.com/docs/service/show-post-13206.html