Cobbler批量安装Ubuntu/CentOS系统

一、安装和修改cobbler配置
1. Cobbler不在CentOS的基本源中,需要导入EPEL源升级软件包, 确保epel-release包的版本为最新,当前最新版本为6-8:
# rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2. yum安装cobbler包
# yum -y install cobbler

3. 【可选】新版的Fedora安装系统存放在“testing”存储库中一段时间来检查有没有bug,如果你想通过EPEL安装最新版的cobbler(未通过生产环境验证有没有bug),可在安装或升级时启动-testing模式。
# sudo yum -y install --enablerepo=epel-testing cobbler
or
# sudo yum -y update --enablerepo=epel-testing cobbler

4. 安装dhcp服务
# yum -y install dhcp

5. 其他服务的安装
额外需要的服务还有httpd rsync tftp-server xinetd,如果系统没有装上的话,可以执行以下执行安装。
# yum -y install httpd rsync tftp-server xinetd

6. 开启cobbler服务,重启Apache服务,设置各个服务开机自启动
# service httpd start
# service cobblerd start
# service xinetd start

# /sbin/chkconfig httpd on
# /sbin/chkconfig dhcpd on
# /sbin/chkconfig xinetd on
# /sbin/chkconfig tftp on
# /sbin/chkconfig cobblerd on

7. 关闭SELinux和防火墙
# vi /etc/sysconfig/selinux
SELINUX=enforcing更改为SELINUX=disabled
设置SELinux 成为permissive模式
# setenforce 0
关闭防火墙功能
# /etc/init.d/iptables stop
# chkconfig  --del iptables
重启cobbler服务
# service cobbler restart

8. 修改cobbler配置
# vi /etc/cobbler/setting
'next_server: 127.0.0.1' 替换本机IP地址 (DHCP服务地址)
'server: 127.0.0.1' 替换本机IP地址(cobbler服务地址)
'manage_dhcp: 0' 替换为 1(cobbler管理dhcp,后面用于同步更新配置信息[cobbler sync])
'manage_rsync: 0' 替换为 1 (cobbler管理rsync功能)

9. 加载部分缺失的网络boot-loaders
# cobbler get-loaders

10. 启动tftp和rsync服务
# vi /etc/xinetd.d/tftp
修改成:disable=no
# vi /etc/xinetd.d/rsync
修改成:disable=no

11. 修改DHCP模板,确保DHCP分配的地址和Cobbler在同一网段
# vi /etc/cobbler/dhcp.template

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;
 
#需要修改192.168.0.0为自己网段
subnet 192.168.0.0 netmask 255.255.255.0 {
#修改自己的路由
     option routers             192.168.0.1;
#域名服务器地址
     option domain-name-servers 202.106.0.20;
#子网掩码
     option subnet-mask         255.255.255.0;
#分配IP地址段
     range dynamic-bootp        192.168.0.100 192.168.0.254;
     filename                   "/pxelinux.0";
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
}


12. 如果要部署Debian/ubuntu系统则需要debmirror软件包

# 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";
...

13. 修改cobbler的默认密码
用 openssl 生成一串密码后加入到 cobbler 的配置文件(/etc/cobbler/settings)里,替换 default_password_crypted 字段:
#   openssl passwd -1 -salt 'random-phrase-here' '1234567890'
$1$random-p$RkqDMTpuNlZZhJ7moLn3Q.
#   vi /etc/cobbler/settings

default_password_crypted: "$1$random-p$RkqDMTpuNlZZhJ7moLn3Q." 
注意:这里保存的密码,将会用于批量部署机器中,root账户的登录密码。

14. 安装cman启动电源管理功能
# yum install cman

15. 检查cobbler安装环境
# cobbler check
No configuration problems found.  All systems go.
注意,一定要修复完全部的configuration problems,否则tftp会出现连接超时,cobbler无法通过PXE进行系统批量安装的操作。
# cobbler sync

二、导入ISO文件

1. 上传ISO镜像至服务器

2. 创建文件夹
# mkdir -p /system/ubuntu12.04

3. 挂载ISO镜像到/system /ubuntu12.04 目录

# mount -o loop ~/Downloads/ubuntu-12.04-server-amd64.iso /system/ubuntu12.04/

4. 从iso中导入客户端的OS。这将自动设置了“x86_64”,并将其命名为ubuntu12.04。
# cobbler import --path=/system/ubuntu12.04/ --name=ubuntu12.04 --arch=x86_64
这需要一点时间,不要急。可查看/var/www/cobbler/ks_mirror/ubuntu12.04-x86_64/目录文件生成情况。
# cobbler sync
# cobbler list

distros: 
   ubuntu12.04-x86_64 
profiles: 
   ubuntu12.04-x86_64 
systems: 
repos: 
   ubuntu12.04-x86_64 
images: 
mgmtclasses: 
packages:
 
files: 


三、部署测试
创建一台虚拟机测试一下,把虚拟机设置成网络 PXE 启动(和 cobbler 在同一个网络),启动后就可以看到 Cobbler 引导界面,看到界面后选择 ubuntu12.04-x86_64 条目就可以顺利开始无人工干预安装系统,Cobbler 引导界面如下: 

Cobbler批量安装Ubuntu/CentOS系统_第1张图片

完成自动化安装后,使用root用户账号登录,密码为之前在配置文件中写入的值(本文为1234567890)

Cobbler批量安装Ubuntu/CentOS系统_第2张图片


四、配置文件
cobbler有许多的配置文件,但是只有少部分基本功能需要修改。 

  • Settings File
  • Modules Configuration
Cobbler最主要的setting file就是/etc/cobbler/settings。Cobbler2.4.0开始引入动态修改模式(Dynamic Settings),我们只需启动这一模式,便不用再手动修改这个文件了。该文件是YAML格式的,如果直接修改setting文件,则必须重启cobbler服务才会生效,但如果是通过CLI命令或者是Web GUI进行修改的话,改动会立即生效,无需重启服务。


五、常见问题
1、cobblerd校验错误:
cobblerd does not appear to be running/accessible
解决方法:
service cobblerd start
service httpd start

2、重启httpd错误:
Starting httpd: Syntax error on line 10 of /etc/httpd/conf.d/cobbler.conf:
Invalid command 'WSGIScriptAliasMatch', perhaps misspelled or defined by a module not included in the server configuration
解决方法:
 vi /etc/httpd/conf.d/wsgi.conf
 #LoadModule wsgi_module modules/mod_wsgi.so 去掉#号,使之成为:LoadModule wsgi_module modules/mod_wsgi.so。

3、httpd、SELinux未运行:
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
解决方法:
service httpd start
vi /etc/sysconfig/selinux
SELINUX=enforcing更改为SELINUX=disabled,重启使之生效。

4、较验cobbler check出错
 Traceback (most recent call last):
  File "/usr/bin/cobbler", line 35, in ?
    sys.exit(app.main())
  File "/usr/lib/python2.4/site-packages/cobbler/cli.py", line 558, in main
    rc = cli.run(sys.argv)
  File "/usr/lib/python2.4/site-packages/cobbler/cli.py", line 202, in run
    self.token         = self.remote.login("", self.shared_secret)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1096, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1383, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1147, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1286, in _parse_response
    return u.close()
  File "/usr/lib64/python2.4/xmlrpclib.py", line 744, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "cobbler.cexceptions.CX:'login failed'">
解决方法:此为BUG,按下方操作执行即可。
service cobblerd restart
cobbler get-loaders

参考文献:
http://bbs.chinaunix.net/thread-3731875-1-1.html
http://cwtea.blog.51cto.com/4500217/1047410/
http://www.vpsee.com/2012/03/install-cobbler-on-centos-6-2/
http://www.chenshake.com/installation-and-configuration-centos-6-3-cobbler-1/

你可能感兴趣的:(安装,centos,自动化,批量,cobbler)