CentOS 6.5上安装部署 Cobbler

作者: seamus 分类: 一般应用 发布时间: 2018-05-07 00:09

Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows. Cobbler 是个轻量级 Python 程序,总共大概1.5万行代码,还可以用来管理 DHCP, DNS, yum 源等。Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web)。

一.安装和配置 cobbler

1,导入epel源

Cobbler 不在?CentOS?6.5 的基本源中,需要导入 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…??????????? ????########################################### [100%]

1:epel-release?????????? ########################################### [100%]

 

# yum update

2,安装cobbler以及其需要的服务软件

# yum install –y cobbler dhcp ?tftp rsync xinetd httpd

3,修改cobbler配置

修改配置,主要修改 cobbler 服务器所在的 IP 地址,以及开启dhcp管理(详见第3步)

# vi /etc/cobbler/settings

next_server: 192.168.0.158 #cobbler服务器的IP

server: 192.168.0.158 ?# cobbler服务器的IP

manage_dhcp: 1?? # (*可选)

 

4,启动服务并添加启动服务

启用 httpd, xinetd 和 cobbler 服务并确认已经加到系统自动启动服务中:

# /etc/init.d/httpd start

# /etc/init.d/xinetd start

# /etc/init.d/cobblerd start? (可能需要先禁用selinux)

 

# chkconfig httpd on

# chkconfig xinetd on

# chkconfig cobblerd on

5,修改xinetd,防火墙以及selinux配置

修改 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

若是selinux本身是关闭的,则不需要重启系统。

# reboot

二. 检查和修改Cobbler配置(每台机器有可能不同)

# cobbler check

这是cobbler自带的检测命令,提供cobbler必须的一些设置的检查,运行之后根据不同的环境,检测出来的结果也是不同的,不过所有的检测中我们都可以按照他的提示,一步步的来完善配置。

若出现如下报错

解决:

[root@node3 ~]# service cobblerd restart

Stopping cobbler daemon:?????????????????????????????????? [? OK? ]

Starting cobbler daemon:?????????????????????????????????? [? OK? ]

[root@node3 ~]# cobbler get-loaders

task started: 2014-10-23_131316_get_loaders

task started (id=Download Bootloader Content, time=Thu Oct 23 13:13:16 2014)

downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README

downloading http://www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo

downloading http://www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot

downloading http://www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux

downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi

downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot

downloading http://www.cobblerd.org/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0

downloading http://www.cobblerd.org/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32

downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi

downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi

*** TASK COMPLETE ***

 

运行 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 : ksvalidator was not found, install pykickstart
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : 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
5 : 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:

# cobbler get-loader
即可获取各ios的bootloader

修复问题2:

安装ksvalidator
# yum install pykickstart

修复问题3:(debian/fedoora系统需要部署)

cobbler服务器能同时部署CentOS/Fedora/Debian/Ubuntu系统,所以需要安装debmirror,安装debmirror-20090807-1.el5.noarch.rpm,在此之前,需要先安装一些其他的依赖包:

# yum install debmirror

修改/etc/debmirror.conf 配置文件,注释掉 @dists 和 @arches 两行

# vim /etc/debmirror.conf

#@dists=”sid”;
@sections=”main,main/debian-installer,contrib,non-free”;
#@arches=”x86_64″;

修复问题4:

修改默认系统密码用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypted 字段:

# openssl passwd -1 -salt ‘zhang’ ‘abcd1234′
$1$zhang$9ZUK/6ZK0WPa/L5/9UHgj1
# vi /etc/cobbler/settings

修改内容如下:

default_password_crypted: “$1$bihan$9ZUK/6ZK0WPa/L5/9UHgj1″

修复问题5:

这属于电源管理的选项,根据提示安装cman即可。
# yum install cman

所有修复都结束之后,重新运行 cobbler check 检查一下,之后,运行cobbler sync来同步配置信息,如果没有发现问题,应该显示是这样的:

# cobbler check

此为debian系统所需要的,可以忽略。

# cobbler sync

三.配置DHCP

Cobbler整个环境中需要一台能提供DHCP功能的机器,如果外部有这样的服务器那么就不用新建一个DHCP服务器,当然一般机房中应该肯定不是DHCP来提供服务的吧,每台服务器都应该是个固定的静态Ip,则我们需要在Cobbler中增加dhcp选项。

Cobbler的dhcp我们在之前已经在/etc/cobbler/settings中开启了,如果你的环境中已经有DHCP服务器,请忽视,并且请关闭。

Cobbler的dhcp配置文件为 /etc/cobbler/dhcp.template,我们只需要修改它即可。

subnet 192.168.0.0 netmask 255.255.255.0 {? ? ? ? ? ? ? ? # 子网范围
option routers? ? ? ? ? ? 192.168.0.1;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 网关地址
option domain-name-servers 192.168.0.1;
option subnet-mask? ? ? ? 255.255.255.0;
range dynamic-bootp? ? ? ? 192.168.0.160 192.168.0.180;? ? ? # ip段
filename? ? ? ? ? ? ? ? ? “pxelinux.0″;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 启动文件
default-lease-time? ? ? ? 21600;
max-lease-time? ? ? ? ? ? 43200;
next-server? ? ? ? ? ? ? ? 192.168.0.158;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # TFTP服务器地址
}

所有配置配置完之后

# service cobblerd restart
# cobbler sync

四.导入iso

1,下载镜像到本地

下载我们需要的版本的iso文件到cobbler的服务器上,然后挂载到一个我们可识别的位置。这里我们使用CentOS6.2.iso来作为例子:

# mkdir /mnt /Centos6.5
# wget?http://mirrors.163.com/centos/6.2/isos/x86_64/CentOS-6.2-x86_64-bin-DVD1.iso
# mount –o loop –t iso9660 ./CentOS-6.2-x86_64-bin-DVD1.iso /mnt/ Centos6.5

2,挂载光盘到本地

#mkdir /mnt/centos6.5

#mount /dev/cdrom1 /mnt/centos6.5/

3,将挂载好的系统读取到cobbler内

cobbler import –path=/mnt/centos6.5/ –name=Centos6.5 –arch=x86_64

4,查看list

#coller list

5,cobbler 同步

#cobbler sync

看到TASK COMPLETE 即可
至此,cobbler已经配置完成。

6,测试

需要安装的机器选择网卡启动,既可以看到

五,修改默认逻辑卷安装并自定义分区

1,查找cobbler启动的ks文件

Ks文件太多了,不知道默认使用哪个。所以配置web端指定ks配置文件。

2,安装cobbler-web并配置

[root@node3 kickstarts]# yum install cobbler-web

#vi /etc/cobbler/modules.conf

module = authn_configfile /修改认证方式为密码文件类型

#htdigest /etc/cobbler/users.digest “Cobbler” cobbler? 添加cobbler用户,提示输入2遍密码确认

# cobbler sync /输出*** TASK COMPLETE ***?表示配置无错误

# /etc/init.d/httpd restart

# /etc/init.d/cobblerd restart

3,登入web端

1,访问web页面

https://192.168.0.158/cobbler_web /使用刚才创建的用户登录

2,编辑指定ks文件

3,调整ks文件为sample.ks并保存

4,切换至服务器修改sample.ks文件指定分区信息

这部分是分区,如下定义:

Swap 分区采用系统推荐值,在创建swap分区时,若RAM<2G,则分区大小为2*RAM;若RAM>=2G时,分区大小为RAM+2G,boot分区设置为200M;剩余空间全部分配给/分区。

重启cobbler

Service cobbler restart