cobbler使用手册

上一期我们说到了使用PXE通过网络引导的方式来安装centos,但是使用pxe是有缺陷的,比如pxe只能拥有一个模板(ks文件)和一个操作系统的安装。如果需要更换模板!需要手动自己对ks文件进行互换。对于在企业环境中还是相当麻烦的!那么有没有更高好的解决方案呢?

答案是必须有的,我们可以使用cobbler程序来解决这个问题!那么什么是cobbler?

什么是cobbler?

二次方转的PXE,比PXE更高级(高级封装)。可以有多安装树的PXE环境同时,Cobbler也提供了API接口,方便二次开发使用。它不仅可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。另外,它还能结合Puppet等集中化管理软件,实现自动化管理。

cobbler的三个重要组件:

repository 提供安装树→可指mirror与import
distribution 用来指明安装哪个系统
profile 用来组合repository与distrioution还能用来自定义安装环境与位置

下图是主要的组建结构图:

cobbler01

那么cobbler说的这么好听,功能这么强大,接下来我得说说如何安装和配置实用了!

安装cobbler:

安装的时候需要fedora epel源才能安装,安装使用yum install cobbler 但是在安装之前还得安装dhcp tftp-server tftp syslinux httpd,不过对于这些安装包的配置与安装我在上一期已经讲过了,如果又需要可以再次回过头看看!cobbler还提供web管理如果又需要可以安装cobbler-web。

配置依赖程序配置文件:

配置依赖的程序的配置文件,只需要配置dhcp和tftp即可。关于配置我在上一期已经讲过了(与pxe相同即可)。但是注意的是:tftp无需复制文件到/var/lib/tftpboot!

[root@localhost lib] tar -czf tftpboot-back.tar.gz tftpboot 
#上一期我写完的pxe我把这么文件打包放到其他地方
[root@localhost tftpboot] yum install cobbler
#安装cobbler

启动与调试cobbler:

安装完毕cobbler之后首先启动它;使用systemctl start cobblerd(如果你是centos6系统使用service cobblerd start)

在配置cobbler之前我们还得首先调试一下cobbler;执行cobbler check 查看:(但是遇到报错了!)

httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
File “/usr/lib/python2.7/site-packages/cobbler/cli.py”, line 252, in check_setup
s.ping()
File “/usr/lib64/python2.7/xmlrpclib.py”, line 1233, in __call__
return self.__send(self.__name, args)
File “/usr/lib64/python2.7/xmlrpclib.py”, line 1587, in __request
verbose=self.__verbose
File “/usr/lib64/python2.7/xmlrpclib.py”, line 1273, in request
return self.single_request(host, handler, request_body, verbose)
File “/usr/lib64/python2.7/xmlrpclib.py”, line 1321, in single_request
response.msg,
ProtocolError: <ProtocolError for 127.0.0.1:80/cobbler_api: 404 Not Found>

如果遇到上述的错误请将httpd中的配置文件中的DocumentRoot字段注释掉,随后重启httpd即可。因为httpd的默认网站根目录会与cobbler冲突!

如果遇到下面是这个错误:<ProtocolError for 127.0.0.1:80/cobbler_api: 503 Service Unavailable>直接将selinux关闭即可!

接下来继续执行cobbler check会遇到这种错误:

The following are potential configuration items that you may want to fix:

1 : The ‘server’ field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work. This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the ‘next_server’ field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : 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.
4 : enable and start rsyncd.service with systemctl
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : 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
7 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

一共7个错误…看来还挺多的。我来一个一个完成吧!

第一个错误:因为没有提供服务的IP地址或主机名所以报错,解决方案:修改/etc/cobbler/settings 查找server参数并且提供监听地址或主机名即可!具体地方在这里:
# this is the address of the cobbler server — as it is used
# by systems during the install process, it must be the address
# or hostname of the system as those systems can see the server.
# if you have a server that appears differently to different subnets
# (dual homed, etc), you need to read the –server-override section
# of the manpage for how that works.
server: 172.16.1.30 #建议从下往上查找!因为很靠后

第二个错误:主要是没有提供pxe服务的主机地址所导致,还是在/etc/cobbler/settings中查找next_server字段将其修改,不过我写的和server一样!
# if using cobbler with manage_dhcp, put the IP address
# of the cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
next_server: 172.16.1.30

第三个错误:这个原因是缺少pxelinux.0,memu.c32等文件导致,如果你能联互联网的话,执行cobbler get-loaders即可,如果不能联网,需要安装syslinux程序包,而后复制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目录中。

第四个错误:缺少rsyncd程序,或者该程序未启动导致。所以先安装这个包:yum install rsync如果安装过了,那么请启动服务systemctl start rsyncd

第五个错误:这个问题是debmirror包没有安装所导致的,如果你不打算安装debian系列的操作系统可以忽略如果需要在这个网站:http://rpmfind.net/linux/rpm2html/search.php?query=debmirror进行下载!完毕之后安装即可!注意:安装时候会安装其他大量的依赖包,以perl为主!

第六个错误:这个是配置文件密钥的问题,让你重新生成一个密钥。执行“openssl passwd -1 -salt $(openssl rand -hex 4)”输入一些随机乱码生成密钥,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值。

第七个错误:安装cman 或者fence-agents即可,两个都安装也可以:yum install cman fence-agents

7个错误分别都处理完毕,接下来再执行cobbler check:

1 : enable and start rsyncd.service with systemctl
2 : comment out ‘dists’ on /etc/debmirror.conf for proper debian support
3 : comment out ‘arches’ on /etc/debmirror.conf for proper debian support

我擦刚处理好错误…又来三个?

第一个错误:安装和启动还是不行,原因是还得添加为启动项:执行命令:chkconfig rsyncd on

第二个第三个错误都是关于新安装的debmirror的问题,首先我们进入/etc/debmirror.conf中分别注释@dists=”sid”和@arches=”i386″即可。

最后再次检查是否有错:

[root@localhost ~]# cobbler check
No configuration problems found. All systems go.
#出现上述话语说明已经没有问题了可以正常使用了!

使用cobbler:

1、首先定义distro
让cobbler变得可用的第一步为定义distro,其可以通过为其指定外部的安装引导内核及ramdisk文件的方式实现。而如果已经有完整的系统安装树(如CentOS6的安装镜像)则推荐使用import直接导入的方式进行。(类似于导入镜像ISO文件)

现在我将/dev/cdrom中的centos7 iso镜像挂载到/media随后执行:

[root@localhost ~]# cobbler import --name=CentOS-7.0-x86_64 --path=/var/www/centos7/
task started: 2016-10-17_145028_import
task started (id=Media import, time=Mon Oct 17 14:50:28 2016)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64:
creating new distro: CentOS-7.0-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64 -&gt; /var/www/cobbler/links/CentOS-7.0-x86_64
creating new profile: CentOS-7.0-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64 for CentOS-7.0-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7.0-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7.0-x86_64/repodata
*** TASK COMPLETE ***
#这样就算拷贝完毕,记住--name是自己起的名字而--path是iso路径!
[root@localhost ~]# cobbler distro list #使用这个命令可以查看所有distro!
 CentOS-7.0-x86_64

2、定义profile

cobbler使用profile来为特定的需求类别提供所需要安装配置,即在distro的基础上通过提供kickstart文件来生成一个特定的系统安装配置。distro的profile可以出现在PXE的引导菜单中作为安装的选择之一。(使用distro定义的iso文件只需更改ks文件就算一个profile)
如果需要为前面创建的centos7这个distro提供一个可引导安装条目,其用到的kickstart文件为/tmp/centos7-test1.cfg(自动安装后的IP为172.16.1.50),则可通过如下命令实现:

[root@localhost cobbler] cobbler profile add --name=centos-7.0-test1 --distro=CentOS-7.0-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7-test1.cfg
#注意如果你没有吧ks文件放到/var/lib/cobbler/kickstarts中会出现:
#exception on server: 'Invalid kickstart template file location /tmp/XXXXX.cfg, it is not inside /var/lib/cobbler/kickstarts/'
#如果需要查看profile可以使用:
[root@localhost kickstarts]# cobbler profile list
 CentOS-7.0-x86_64 #没有ks文件
 centos-7.0-test1
 centos-7.0-test2 #这个我设置的IP为51

注:distro和profile的子命令除了list列出详细信息还可以使用:

[root@localhost kickstarts]# cobbler profile -h #查看帮助
usage
=====
cobbler profile add
cobbler profile copy
cobbler profile dumpvars
cobbler profile edit
cobbler profile find
cobbler profile getks
cobbler profile list
cobbler profile remove
cobbler profile rename
cobbler profile report
[root@localhost kickstarts]# cobbler distro -h
usage
=====
cobbler distro add
cobbler distro copy
cobbler distro edit
cobbler distro find
cobbler distro list
cobbler distro remove
cobbler distro rename
cobbler distro report

上述的英文看上去这么简单字如其义,我就不介绍啦!

测试cobbler:

和pxe一样自己创建一个虚拟机使用pxe引导即可!

开机之后出现这个问题:提示找不到文件:cobbler02开机便遇到失败,遇到这个问题首相就是想到拿到dhcp以后未能加载到pxelinux.0。原因是刚刚我们在执行cobbler get-loaders的时候将文件加载到/var/lib/cobbler/loaders中,不是在/var/lib/tftpboot/中所以我们要吧里面的文件无脑先复制到/var/lib/tftpboot之中,执行:
[root@localhost loaders]# cp * /var/lib/tftpboot/

然后我们遇到我们喜欢的界面了,首先看看选择第二个:

cobbler03

就这样系统给我自动安装了,连新建root密码的机会都不给我…

cobbler04

看来要执行上一期B方案还得稍作修改才行哇!按照上一次的经验,这次我还是瞄准了pxelinux.cfg/default文件,进入编辑模式:

cobbler05

上图是原来的文档,我将LABEL CentOS-7.0-x86_64 append稍作修改:append initrd=/images/CentOS-7.0-x86_64/initrd.img inst.repo=http://172.16.1.30/cobbler/ks_mirror/CentOS-7.0-x86_64/ #注意请别无脑复制结合上一期内容修改寻找文件的网络URL。随后开启测试机:

cobbler06

终于是我想要的界面了!接下来就能自由发挥安装了!

对了还有两个ks文件并未测试,这个我就不详细截图给大家介绍了。不过可以自行测试!关于这一期cobbler使用手册就介绍完毕了。

Comments

Leave a Reply

Your email address will not be published. Name and email are required