一、引言与概述

1、说明
本文是紧接上一篇<自动化运维之CentOS7下PXE+Kickstart+DHCP+TFTP+HTTP无人值守安装系统>补充篇,或叫基于上篇相关技术之上构建的cobbler服务;因此省略了部分服务的安装配置;部署也是在之前的基础上进行的;
2、cobbler介绍
cobbler是基于pxe kickstart,tftp-server,httpd,dhcp等综合管理;基于python的包装与二次开发;管理多个(linux)系统安装环境(如通过CentOS7/centos6不同系统镜像(distro) 基于不同kickstart(profile) 安装出不同系统环境(system)),既可以通过命令去操作管理,也可以通过web管理(需要单独安装配置);

3、环境说明
环境基于上文中的测试环境即:
ip:172.16.3.152 (可上网)
内部测试ip(仅主机模式) 192.168.56.254
已经安装好的服务:DHCP,tftp-server,httpd,syslinux

二、安装cobbler服务

cobbler的安装需要基于EPEL扩展仓库因此需要先安装epel
[root@pxe ~]# yum install epel-release -y
1、安装cobbler

[root@pxe ~]# yum install cobbler cobbler-web pykickstart debmirror -y
安装好先启动cobblerd服务
[root@pxe ~]# systemctl start cobblerd
##检查配置信息
[root@pxe yum.repos.d]# 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 251, 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>
解决方法:
御载pxe时的光盘挂载web目录
[root@pxe ~]# umount /var/www/html/centOS/7/x86_64
[root@pxe ~]# systemctl restart cobbler
#再次检查
[root@pxe ~]# 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 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out 'arches' on /etc/debmirror.conf for proper debian support
7 : 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
8 : 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.

此时会发现有很多警告提示信息;不要紧,咱接下来一一解决
2、配置cobbler
a、针对以上第一条解决如下:
需要修改settings中的 server修改为本地的对外ip地址,如下是本次测试修改地址;

[root@pxe ~]# egrep -v '(^$|^#)' |grep "server:" /etc/cobbler/settings
server: 192.168.56.254

b、第二条解决:
修改next_server 即提供tftp-server的地址,由于本机就提供tftp-server故修改如下:

[root@pxe ~]# egrep -v '(^$|^#)' |grep "next_server:" /etc/cobbler/settings
next_server: 192.168.56.254

c、第三条
如果当前节点可以访问互联网,执行“cobbler get-loaders”命令亦可;或安装syslinux程序包,再复制/usr/share/syslinux/{pxelinux.0,menu.c32}等文件至/var/lib/cobbler/loaders/目录中;由于本次已经安装好了syslinux,网速可能比较慢帮直接从syslinux中复制boot-loaders
[root@pxe ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/cobbler/loaders/

d、第四条
添加rsyncd服务开机启动,如果没有安装此包请yum安装
[root@pxe ~]# systemctl enable rsyncd
e、第五条和第六条
修改配置文件/etc/debmirror.conf 注释第28 30行

#@dists="sid";
#@arches="i386";

f、第七条
生成密码再替换到/etc/cobbler/settings配置文件中

[root@pxe ~ ]# openssl passwd -1 redhat
$1$YRGo5nnj$N99AHSP0wu5Y4Zhalrsqu/
大约在101行:
default_password_crypted: "$1$YRGo5nnj$N99AHSP0wu5Y4Zhalrsqu/"

说明:这个密码是通过cobbler默认profile(kickstart)配置文件安装好系统后的root默认密码;

g、第八条
安装相应的程序包即可;
[root@pxe ~ ]# yum install cman fence-agents
最后重启cobblerd服务

[root@pxe ~ ]# systemctl restart cobblerd 
同步配置至cobbler
[root@pxe ~ ]# cobbler sync
再次检查
[root@pxe ~ ]# cobbler check
No configuration problems found.  All systems go.

如果第三条使用cobbler get-loaders命令自动生成loaders文件就会像以上提示一样没有任务提示了;但要是自己复制,可能还会有第三条的警告提示,但不管如何都没有问题了;

三、cobbler配置

通过以上配置cobbler部分基础部分已经配置完成;接下来就是配置cobbler中的distro(可以理解为系统仓库),profile(可以理解为针对distro的kickstart配置文件);基于distro和profile文件我们就可以来定制安装我们的系统环境啦!
1、配置distro
加载CentOS7_x86_64_1511系统光盘

[root@pxe ~ ]# mount /dev/cdrom /media/cdrom
[root@pxe ~ ]# cobbler import --name="CentOS-7_x86_64-1511" --path=/media/cdrom

注意这个过程需要点时间,原因就是把cdrom中的镜像复制到/var/www/cobller的对应目录中
查看生成的distro和针对这个distro默认生成的profile

[root@pxe~ ]# cobbler distro list
   CentOS-7-1511-x86_64
[root@pxe lpxe ~ ]# cobbler profile list
   CentOS-7-1511-x86_64

2、同步配置文件
[root@pxe lpxe ~ ]# cobbler sync

新建一台虚拟机测试:
网络配置和过程同上文中的一样;引导菜单效果如下:
自动化运维之cobbler安装多版本系统
local是默认的本地设备,这里没有用,选择CentOS-7-1511-x86_64 即可安装,这里默认的是字符安装;

3、定制自已的profile文件
由于默认的kickstart profile文件引导安装时是无图形是最小化安装,因此我要定制一个porfile文件
a、先重命令默认profile文件

[root@pxe~ ]# cobbler profile rename --name=CentOS-7-1503-x86_64 --newname=CentOS7-7-1503-x86_64-minimal
[root@pxe~ ]# cobbler profile list
   CentOS7-7-1503-x86_64-minimal

b、定制
复制之前PXE时的kickstart cfg文件并修改url

[root@pxe~ ]# cp /var/www/html/ks/ks.cfg   /var/lib/cobbler/kickstarts/
修改ks中的url如下:
url --url=http://192.168.56.254/cobbler/ks_mirror/CentOS-7_x86_64-1511

#添加新的profile
[root@pxe kickstarts]# cobbler profile add --name=CentOS-7-x86_64-1503-server --distro=CentOS-7-1503-x86_64 --kickstart=/var/lib/cobbler/kickstarts/xx.cfg
#查看profile
[root@pxe kickstarts]# cobbler profile list
   CentOS-7-1511-x86_64-minimal
   CentOS-7-x86-1511-server
#重启与同步cobbler配置
[root@pxe kickstarts]# systemctl restart cobblerd
[root@pxe kickstarts]# cobbler sync

再次新建一台虚拟机网络引导安装测试:
自动化运维之cobbler安装多版本系统
选择CentOS-7-x86-1511-server会自动进入图形化安装界面如图:
自动化运维之cobbler安装多版本系统

以上是针对CentOS7的安装与定制profile,既然cobbler能针对不同linxu发行版提供安装环境;那么接下来我们就加入centOS6的distro与profile安装CentOS6系统
4、添加CentOS6 distro
添加CenOS6.7的distro

[root@pxe kickstarts]# cobbler import --name="CentOS-6_x86_64-7" --path=/media/cdrom
查看distro与profile
[root@pxe ~]# cobbler distro list
   CentOS-6-7-x86_64
   CentOS-7-1511-x86_64
[root@pxe ~]# cobbler profile list
   CentOS-6-7-x86_64
   CentOS-7-1511-x86_64-minimal
   CentOS-7-x86-1511-server
#同步配置文件
[root@pxe ~]# cobbler sync

再次新建一台虚拟机网络引导安装测试时,引导菜单如下:
自动化运维之cobbler安装多版本系统
选择CentOS-6-7-x86_64后自动化安装如下:
自动化运维之cobbler安装多版本系统

总结:

cobbler通过基于PXE Kickstart(profile),dhcp,httpd,系统镜像(distro),tftp-server等服务的包装开发后,能实现多种发行版的统一自动网络安装;主要分三大步:基础配置好cobbler服务;通过光盘导入一个或多个distro,在此过程中会生成默认的profile文件;也可以自行定制profile文件;再基于distro与profile文件来安装具体的生产系统;