免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5347 | 回复: 13
打印 上一主题 下一主题

在 CentOS Linux 上安装 Cobbler 批量部署系统 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-05-03 21:13 |只看该作者 |倒序浏览
本帖最后由 Mysql2009 于 2012-05-03 21:14 编辑

每次給自己的电脑重装系统都是一件很无聊的事情,如果需要重装上百台虚拟机和服务器不但很无聊而且很耗时,面对现在云时代大量服务器和虚拟机的出现,运维必须要自动化。现在有很多开源工具可以帮助我们实现自动化安装系统,比如 FAI, Cobbler, Spacewalk, Ubuntu Orchestra 等,我们打算把 Cobbler 安装在某台虚拟机上,为我们新购的16台刀片服务器自动安装系统。

什么是 Cobbler?

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/ ... ease-6-5.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/ ... ease-6-5.noarch.rpm
warning: /var/tmp/rpm-tmp.lo2Hd0: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

# 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 ... 07-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.example.com' 'example'
$1$www.example$T5FgCHY2P0NDr6JmbN0Bl0

# vi /etc/cobbler/settings
default_password_crypted: "$1$www.example$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 引导界面如下:



安装完系统后默认的密码是啥呢?根据 sample.ks 的配置提示,这个密码 $default_password_crypted 就是我们上面用 openssl passwd -1 -salt ‘www.example.com’ ‘example’ 生成的密码,所以这里的 root 密码是 example:

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

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
2 [报告]
发表于 2012-05-06 04:18 |只看该作者
闲来无事,拿来试试。

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
3 [报告]
发表于 2012-05-06 16:16 |只看该作者
为什么我把cobbler和dhcp放一台,按照你说的步骤一步步来就是错误呢??
一cobbler check就一大堆错.......

论坛徽章:
0
4 [报告]
发表于 2012-05-06 20:29 |只看该作者
dzminglong 发表于 2012-05-06 16:16
为什么我把cobbler和dhcp放一台,按照你说的步骤一步步来就是错误呢??
一cobbler check就一大堆错..... ...


能将错误的log放上来大家看看吗?

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
5 [报告]
发表于 2012-05-06 21:21 |只看该作者
我装完重启了下,一 cobbler get-loaders就说:httpd does not apper to be running and proxying cobbler,什么问题?搞不懂,我是在一台虚拟机上做的,cobbler跟dhcp在一台上了,怎么修改dhcp主配置文件了?

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
6 [报告]
发表于 2012-05-06 21:22 |只看该作者
对了,我的httpd是已经启用的状态了。

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
7 [报告]
发表于 2012-05-06 21:23 |只看该作者
[root@cobbler ~]# cobbler check
httpd does not appear to be running and proxying cobbler

论坛徽章:
0
8 [报告]
发表于 2012-05-07 09:28 |只看该作者
dzminglong 发表于 2012-05-06 21:23
[root@cobbler ~]# cobbler check
httpd does not appear to be running and proxying cobbler

应该是你的dhcpd没有设置,指定你的请求到你的cobbler服务器

就是这一段:
  1. 修改 DHCP 服务器配置

  2. 使用 Cobbler 最好配合现有局域网上的 DHCP 服务器一起使用,这样不会因为 Cobbler 干扰现有局域网。我们不打算用 Cobbler 来管理整个网络的 DHCP,因为我们已经有了 DHCP 服务器,所以只要在现有的 DHCP 服务器上做以下配置即可,下面记得调整 192.168.2.22 这个 IP 地址指向 Cobbler 服务器:

  3. # for Cobbler setup
  4. host cobbler {
  5.      option host-name "cobbler";
  6.      ddns-hostname "cobbler";
  7.      hardware ethernet 00:0c:29:2d:2c:39; #MAC address of cobbler server
  8.              fixed-address 192.168.2.22; #IP of Cobbler server
  9.              allow booting;
  10.      allow bootp;
  11.      class "PXE" {
  12.          match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
  13.          next-server 192.168.2.22; #IP of Cobbler server
  14.              filename "pxelinux.0";
  15.      }
  16. }
复制代码
如果你是虚拟机的话,比如vmware,你是需要修改他的dhcpd的设置的

论坛徽章:
8
天秤座
日期:2013-09-02 09:10:44CU十二周年纪念徽章
日期:2013-10-24 15:41:34子鼠
日期:2013-11-20 16:38:31巨蟹座
日期:2013-12-18 13:03:34天秤座
日期:2013-12-31 13:28:40卯兔
日期:2014-01-22 17:09:40技术图书徽章
日期:2014-02-27 20:31:47巳蛇
日期:2014-09-22 10:25:32
9 [报告]
发表于 2012-05-07 10:43 |只看该作者
我是放一台了,dhcp和cobbler在一台上,不是这么配置了吧?!

论坛徽章:
0
10 [报告]
发表于 2012-05-07 13:51 |只看该作者
dzminglong 发表于 2012-05-07 10:43
我是放一台了,dhcp和cobbler在一台上,不是这么配置了吧?!


你不是说虚拟机么?

虚拟机的话,你的虚拟机上的dhcpd起来了?可是一般来说,都是用的vmware带的dhcpd的啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP