在 CentOS 6.2 上安装 Cobbler
<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>修改 DHCP 服务器配置</li><li>安装和配置 Cobbler</li><li>检查和修改 Cobbler 配置</li><li>导入 ISO</li><li>测试</li></ul></div><div class="entry"><p>每次給自己的电脑重装系统都是一件很无聊的事情,如果需要重装上百台虚拟机和服务器不但很无聊而且很耗时,面对现在云时代大量服务器和虚拟机的出现,运维必须要自动化。现在有很多开源工具可以帮助我们实现自动化安装系统,比如 FAI, Cobbler, Spacewalk, Ubuntu Orchestra 等,我们打算把 Cobbler 安装在某台虚拟机上,为我们新购的16台刀片服务器自动安装系统。</p>
<p>Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows. Cobbler 是个轻量级 Python 程序,总共大概1.5万行代码,还可以用来管理 DHCP, DNS, yum 源等。Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),不过命令行方式已经很方便,实在没有必要为了不实用的 Web 界面再添加一个 Web 服务器。</p>
<p class="maodian"></p><h2>修改 DHCP 服务器配置</h2>
<p>使用 Cobbler 最好配合现有局域网上的 DHCP 服务器一起使用,这样不会因为 Cobbler 干扰现有局域网。我们不打算用 Cobbler 来管理整个网络的 DHCP,因为我们已经有了 DHCP 服务器,所以只要在现有的 DHCP 服务器上做以下配置即可,下面记得调整 192.168.2.22 这个 IP 地址指向 Cobbler 服务器:</p><pre class="brush:bash;toolbar:false"># 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";
}
}</pre><p></p>
<p class="maodian"></p><h2>安装和配置 Cobbler</h2>
<p>Cobbler 不在 CentOS 6.2 的基本源中,需要导入 EPEL 源:</p><pre class="brush:bash;toolbar:false"># 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</pre><p>安装 cobbler:</p><pre class="brush:bash;toolbar:false"># yum install cobbler</pre><p>修改配置,主要修改 cobbler 服务器所在的 IP 地址:</p><pre class="brush:bash;toolbar:false"># vi /etc/cobbler/settings
...
next_server: 192.168.2.22 #IP of Cobbler server
server: 192.168.2.22 #IP of Cobbler server
...</pre><p>启用 httpd, xinetd 和 cobbler 服务并确认已经加到系统自动启动服务中:</p><pre class="brush:bash;toolbar:false"># /etc/init.d/httpd start
# /etc/init.d/xinetd start
# /etc/init.d/cobblerd start
# chkconfig httpd on
# chkconfig xinetd on
# chkconfig cobblerd on</pre><p>修改 rsync 和 tftp 这两个服务的 xinetd 配置:</p><pre class="brush:bash;toolbar:false"># vi /etc/xinetd.d/rsync
service rsync
{
disable = no
...
}
# vi /etc/xinetd.d/tftp
service tftp
{
...
disable = no
...
}</pre><p>关闭防火墙和 SELinux 后重启系统:</p><pre class="brush:bash;toolbar:false"># /etc/init.d/iptables stop
# chkconfig iptables off
# vi /etc/sysconfig/selinux
...
SELINUX=disabled
...
# reboot</pre><p></p>
<p class="maodian"></p><h2>检查和修改 Cobbler 配置</h2>
<p>系统重启后用 cobbler check 检查发现3个配置信息问题,第一个是如果要部署 debian/ubuntu 系统需要 debmirror 软件包;第二个是需要修改 cobbler 的默认密码;第三个是可选,想使用电源管理功能的话需要安装 cman 或 fence-agents:</p><pre class="brush:bash;toolbar:false"># 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.</pre><p>现在来修复上面三个问题,我们希望能让这台 cobbler 服务器能同时部署 CentOS/Fedora 和 Debian/Ubuntu 系统,所以需要安装 debmirror,安装 debmirror-20090807-1.el5.noarch.rpm 前需要先安装依赖包:</p><pre class="brush:bash;toolbar:false"># 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</pre><p>修改 /etc/debmirror.conf 配置文件,注释掉 @dists 和 @arches 两行:</p><pre class="brush:bash;toolbar:false"># vi /etc/debmirror.conf
...
#@dists="sid";
@sections="main,main/debian-installer,contrib,non-free";
#@arches="i386";
...</pre><p>用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypted 字段:</p><pre class="brush:bash;toolbar:false"># openssl passwd -1 -salt 'www.vpsee.com' 'vpsee'
$1$www.vpsee$T5FgCHY2P0NDr6JmbN0Bl0
# vi /etc/cobbler/settings
default_password_crypted: "$1$www.vpsee$T5FgCHY2P0NDr6JmbN0Bl0"</pre><p>安装 cman:</p><pre class="brush:bash;toolbar:false"># yum install cman</pre><p>修复完成,再用 cobbler check 检查一下,确认没问题后用 cobbler sync 做同步操作:</p><pre class="brush:bash;toolbar:false"># cobbler check
No configuration problems found.All systems go.
# cobbler sync</pre><p></p>
<p class="maodian"></p><h2>导入 ISO</h2>
<p>挂载 CentOS-6.2-x86_64-bin-DVD1.iso 安装光盘然后导入到 cobbler(注意这个 iso 文件有 4GB 多,导入可能需要一段时间),导入成功后 cobbler list 查看一下:</p><pre class="brush:bash;toolbar:false"># 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:</pre><p></p>
<p class="maodian"></p><h2>测试</h2>
<p>最后创建一台虚拟机测试一下,把虚拟机设置成网络 PXE 启动(和 cobbler 在同一个网络),启动后就可以看到 Cobbler 引导界面,看到界面后选择 CentOS-6.2-bin-DVD1-x86_64 条目就可以顺利开始无人工干预安装系统,Cobbler 引导界面如下:</p>
<p><img src="https://zhuji.jb51.net/uploads/img/20230517/b6ae3f5a4dc1cb91ff17013db3796990.jpg" width="559" height="258"></p>
<p>安装完系统后默认的密码是啥呢?根据 sample.ks 的配置提示,这个密码 $default_password_crypted 就是我们上面用 openssl passwd -1 -salt ‘www.vpsee.com’ ‘vpsee’ 生成的密码,所以这里的 root 密码是 vpsee:</p><pre class="brush:bash;toolbar:false"># cat /var/lib/cobbler/kickstarts/sample.ks
...
#Root password
rootpw --iscrypted $default_password_crypted</pre><p>
</p>
</div>
頁:
[1]