您的位置:首页 > 运维架构 > Linux

CentOS 6.4 部署 Cobbler

2013-11-06 10:36 1186 查看
CentOS 6.4 部署 Cobbler

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

Cobbler命令说明
命令名称 命令用途
cobbler check 核对当前设置是否有问题
cobbler list 列出所有的cobbler元素
cobbler report 详细的列出个元素
cobbler sync 同步配置到dhcp/pxe和数据目录
cobbler reposync 同步yum仓库

Cobbler配置文件说明
Cobbler配置文件存放在/etc/cobbler下。

配置文件名称 用 途

/etc/cobbler/settings cobbler 主配置文件
/etc/cobbler dhcp、dns、pxe、dnsmasq的模板配置文件
/etc/cobbler/users.digest 用于web访问的用户名密码配置文件
/etc/cobbler/modules.conf 模块配置文件
/etc/cobbler/users.conf Cobbler WebUI/Web service授权配置文件

Cobbler数据目录/var/lib/cobbler,此目录存储和Cobbler profiles、systems、distros相关的配置。
configs/ - 此目录用于存储distros、repos、systems和profiles相关信息
backup/ - 备份目录
snippets/ - 用于放置一些可以在kickstarts导入的脚本小片段
triggers/ - 此目录用来放置一些可执行脚本
kickstarts/ - 此目录用来放置kickstart模板文件

1.安装配置DHCP服务
#yum install dhcpd

#vim /etc/dhcp/dhcpd.conf
# for Cobbler setup
[root@cobbler ~]# cat /etc/dhcp/dhcpd.conf
subnet 192.168.7.0 netmask 255.255.255.0 {
range 192.168.7.210 192.168.7.215;
default-lease-time 600;
max-lease-time 7200;
}
host cobbler {
option host-name "cobbler";
ddns-hostname "cobbler";
hardware ethernet 00:0C:29:49:11:D8; #MAC address of cobbler server
fixed-address 192.168.7.181; #IP of Cobbler server
allow booting;
allow bootp;
class "PXE" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.7.181; #IP of Cobbler server
filename "pxelinux.0";
}
}

2.安装和配置 Cobbler
Cobbler 不在 CentOS 6.4 的基本源中,需要导入 EPEL 源:
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install cobbler
修改配置,主要修改 cobbler 服务器所在的 IP 地址:
# vi /etc/cobbler/settings
...
next_server: 192.168.7.181 #IP of tftp server
server: 192.168.7.181 #IP of Cobbler server
...
3.启用 httpd, xinetd 和 cobbler 服务并确认已经加到系统自动启动服务中
#yum install -y tftp-server rsync

# chkconfig tftp on
# chkconfig rsync on
# chkconfig cobblerd on

# service xinetd restart
# service cobblerd restart

4.关闭防火墙和 SELinux 后重启系统:

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

# vi /etc/sysconfig/selinux
...
SELINUX=disabled
...
# reboot
5.检查和修改 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 系统,

# yum install wget ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl debmirror

pykickstart fence-agents cman

修改 /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.csdn.net' 'csdn'
$1$www.csdn$.qB5TQxW86xMqYAWPdkri.

# vi /etc/cobbler/settings
default_password_crypted: "$1$www.csdn$.qB5TQxW86xMqYAWPdkri."

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

# cobbler sync

6.导入 ISO
挂载 CentOS-6.4-x86_64-bin-DVD1.iso 安装光盘然后导入到 cobbler
注:导入成功后 cobbler list 查看一下

# mount -o loop -t iso9660 CentOS-6.4-x86_64-bin-DVD1.iso /mnt
# cobbler import --path=/mnt --name=CentOS-6.4-x86_64-bin-DVD1 –arch=x86_64
# cobbler sync
# cobbler list
distros:
CentOS-6.4-bin-DVD1-x86_64
profiles:
CentOS-6.4-bin-DVD1-x86_64

systems:

repos:

images:
7.测试

8.扩展:
ks文件存放位置
# cat /var/lib/cobbler/kickstarts/sample.ks
...
#Root password

=====================扩展===========================
问题集:

1.[root@puppet-master xinetd.d]# cobbler get-loaders
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:

解决方法:
yum install -y httpd
service httpd restart

命令行来编辑配置(2.4版本以后)

cobbler setting report
cobbler setting report [--name=option]
查看所有可编辑的参数
cobbler setting edit --name=option --value=value
修改seting文件
cobbler登陆服务器地址
cobbler setting edit --name=server --value=192.168.7.181
ks脚本关闭pxe,这样就不会重复安装
cobbler setting edit --name=pxe_just_once --value=1
TFTP服务器 IP地址
cobbler setting edit --name=next_server --value=192.168.7.181
cobbler管理rsync,dhcp,dns
cobbler setting edit --name=manage_rsync --value=1
cobbler setting edit --name=manage_dhcp --value=1
cobbler setting edit --name=manage_dns --value=1

设置Cobbler web界面

Cobbler web界面是一个很好的前端,非常容易管理很多Cobbler操作。可以用它列出和编辑distros, profiles, subprofiles, systems,repos and kickstart文件。
安装Cobbler web:
yum install cobbler-web
Cobbler web界面访问地址: http://192.168.7.181/cobbler_web/ 注:192.168.7.181为Cobbler web server地址
web可以登陆认证
sed -i 's/authn_denyall/authn_configfile/g' /etc/cobbler/modules.conf
设置cobbler web登陆,用户登陆密码
htdigest /etc/cobbler/users.digest "Cobbler" cobbler

koan重装系统

重装节点的系统,你可以在cobbler上设置,无论web还是命令行。不过你还有一种选择,就是直接在客户机上进行。
koan:kickstart over a network。就可以实现这个功能。需要在客户端安装koan,就可以。
要使用koan,有一个前提,就是需要你网络里有dhcp。
yum -y install koan
koan的命令使用
# koan --server=192.168.7.181 --list=systems
你可以查看 systems, profiles.还可以查看根据具体的设置
# koan --server=192.168.7.181 --display --system=server
重装
# koan --server=192.168.7.181 --replace-self --system=server
这个时候,你重启系统,不需要通过pxe,他就会自动开始重装。
# reboot

本文出自 “成功来源于分享” 博客,请务必保留此出处http://linuxchina.blog.51cto.com/938835/1320708
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: