一 、Cobbler简介
python
Cobbler是一个快速网络安装linux的服务,并且在通过调整也能够支持网络安装windows。该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令便可完成PXE网络安装环境的配置,同时还能够管理DHCP、DNS、yum仓库、构造系统ISO镜像。linux
Cobbler支持命令行管理,web界面管理,还提供了API接口,方便二次开发web
Cobbler客户端Koan支持虚拟机安装和操做系统从新安装,使重装系统更便捷。sql
Cobbler提供的功能
shell
使用Cobbler,您无需进行人工干预便可安装机器。Cobbler设置一个PXE引导环境(它还可使用yaboot支持PowerPC),并控制与安装相关的全部方面,好比网络引导服务(DHCP和TFTP)与存储库镜像。当但愿安装一台新机器时,Cobbler能够:vim
1)使用一个之前定义的模板来配置DHCP服务(若是启用了管理DHCP)windows
2)将一个存储库(yum或rsync)创建镜像或解压缩一个媒介,以注册一个新操做系统centos
3)在DHCP配置文件中为须要安装的机器建立一个条目,并使用指定的参数(IP和MAC)bash
4)在TFTP服务目录下建立适当的PXE文件网络
5)从新启动DHCP服务以反应更改
6)从新启动机器以开始安装(若是电源管理已启动)
Cobbler支持众多的发行版:RedHat、Fedora、CentOS、Debian、Ubuntu和SuSE。当添加一个操做系统(一般经过使用ISO文件)时,Cobbler知道如何解压缩合适的文件并调整网络服务,以正确引导机器。
Cobbler可使用kickstart模板。基于Red Hat或Fedora的系统使用kickstart文件来自动化安装流程。经过使用模板,就会拥有基本的kickstart模板,而后定义如何针对一种配置文件或机器配置而替换其中的变量。例如,一个模板可能包含两个变量$domain和$machine_name.在Cobbler配置中,一个配置文件指定domain=mydomain.com,而且每台使用该配置文件的机器在machine_name变量中指定其名称。该配置文件的全部机器都使用相同的kickstart安装且针对domain=mydomain.com进行配置,但每台机器拥有其本身的机器名称。您仍然可使用kickstart模板在不一样的域中安装其余机器并使用不一样的机器名称。
为了协助管理系统,Cobbler可经过fence scripts链接到各个电源管理环境。Cobbler支持apc_snmp、bladecenter、bullpap、drac、ether_wake、ilo、integrity、ipmilan、ipmitool、lpar、rsa、virsh和wti。要从新安装一台机器,可运行reboot system foo命令,并且Cobbler会使用必要的 和信息来为您运行恰当的fence scripts(好比机器插槽数)。
除了这些特性,还可使用一个配置管理系统(CMS)。你有两种选择:该工具内的一个内部系统,或者现成的外部CMS,好比Chef或Puppet。借助内部系统,你能够指定文件模板,这些模板会依据配置参数进行处理(与kickstart模板的处理方式同样),而后复制到你指定的位置。若是必须自动将配置文件部署到特定机器,那么此功能颇有用
使用koan客户端,Cobbler可从客户端配置虚拟机并从新安装系统。
2、Cobbler的设计方式
Cobbler的配置结构基于一组注册的对象。每一个对象表示一个与另外一个实体相关联的实体(该对象指向另外一个对象,或者另外一个对象指向该对象)。当一个对象指向另外一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。如下对象类型的定义
Distros(发行版):表示一个操做系统,它承载了内核和initrd的信息,以及内核参数等其余数据 Profile(配置文件):包含一个发行版、一个kickstart文件以及可能的存储库,还包含更多特定的内核参数等其余数据 Systems(系统):表示要配给的额机器。它包含一个配置文件或一个景象,还包含IP和MAC地址、电源管理(地址、凭据、类型)、(网卡绑定、设置valn等) Repository(镜像):保存一个yum或rsync存储库的镜像信息 Image(存储库):可替换一个包含不属于此类比的额文件的发行版对象(例如,没法分为内核和initrd的对象)。
基于注册的对象以及各个对象之间的关联,Cobbler知道如何更改文件系统以反应具体配置。由于系统配置的内部是抽象的,因此您能够仅关注想要执行的操做。
3、Cobbler各个组件的关系
经过cobbler管理的或者手动管理的服务
TFTP
rsync
DHCP
DNS
4、安装配置Cobbler
一、安装方式
cobbler能够手动编译安装,也能够基于yum源的安装,若是使用yum源安装,则须要配置epel源epel源能够经过下载官网的epel源的目录来实现https://fedoraproject.org/wiki/EPEL
# yum -y install cobbler cobbler-web pykickstart debmirror
二、检查配置文件,须要在启动cobblerd和httpd服务的前提下检查
[root@c3 ~]# service httpd start [root@c3 ~]# service cobblerd start [root@c3 ~]# 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync 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.
以上8个问题的解决方法
1.修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机对应的ip地址
server: 192.168.13.8
2.修改/etc/cobbler/settings文件的next_server参数的值为提供PXE服务的主机的ip
next_server: 192.168.13.8
3.若是当前节点能够访问互联网,执行“cobbler get-loaders”命令下载pxelinux.0,menu.c32,elibo.efi,yaboot文件,不然则须要安装syslinux程序包,复制/usr/share/syslinux/中的pxelinux.0,menu.c32等文件至/var/lib/cobbler/loaders目录中
4.将/etc/xinetd.d/rsync 中的disable改成no,或者执行 chkconfig rsync on
5.注释/etc/debmirror.conf文件中的“@dists="sid";”一行
6.注释/etc/debmirror.conf文件中的“@arches="i386";”一行
7.执行“openssl passwd -1 -salt `pensshl rand -hex 4`”生成密码,并将密码串替换掉/etc/cobbler/settings中的default_password_crypted
default_password_crypted: "$1$6a385fbf$iOHgbfJ0BJRQh78yAMA2L1"
8.安装cam和fence-agents来实现电源管理
同步数据
[root@c3 cobbler]# cobbler sync task started: 2014-04-06_224909_sync task started (id=Sync, time=Sun Apr 6 22:49:09 2014) running pre-sync triggers cleaning trees mkdir: /var/lib/tftpboot/pxelinux.cfg mkdir: /var/lib/tftpboot/grub mkdir: /var/lib/tftpboot/s390x mkdir: /var/lib/tftpboot/ppc mkdir: /var/lib/tftpboot/etc removing: /var/lib/tftpboot/grub/p_w_picpaths copying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk copying distros to tftpboot copying p_w_picpaths generating PXE configuration files generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE ***
5、配置cobbler依赖的服务
cobbler的运行以来dhcp、tftp、rsync、dns服务
cobbler可行管理这些服务中的部分甚至所有,但须要配置/etc/cobbler/settings文件中的“manager_dhcp”、“manage_tftpd”、“manage_rsync”、“manage_dns”来定义,同时各类服务都有着不一样的实现方式,若是进行自定义,须要经过修改/etc/cobbler/modules.conf配置文件中各个服务的模块参数的值来实现
咱们经过独立管理,不经过cobbler管理这些服务。
一、配置dhcp服务
[root@c3 ~]# yum -y install dhcp [root@c3 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf [root@c3 ~]# vim /etc/dhcp/dhcpd.conf option domain-name "jungege.com"; option domain-name-servers 192.168.13.8; default-lease-time 43200; max-lease-time 86400; log-facility local7; subnet 192.168.13.0 netmask 255.255.255.0 { range 192.168.13.2 192.168.13.100; option routers 192.168.13.8; } filename "pxelinux.0"; next-server 192.168.13.8;
启动服务测试
# service dhcpd start # ss -ntlup | grep 67 udp UNCONN 0 0 *:67 *:* users:(("dhcpd",2766,7))
二、配置tftpd服务
[root@c3 ~]# yum -y install tftp-server [root@c3 ~]# chkconfig tftp on
6、配置Cobbler
一、定义distro
实现coobler的第一步就是定义distro,能够经过其指定外部的安装引导内核及ramdisk文件的方式实现。而若是已经有现成的安装树(如OS的安装镜像)则使用import导入的方式
挂载安装光盘 # mount /dev/cdrom /media 导入系统镜像 # cobbler import --name=centos6.5-x86-64 --path=/media/ 导入过程以下 task started: 2014-04-06_230831_import task started (id=Media import, time=Sun Apr 6 23:08:31 2014) Found a candidate signature: breed=redhat, version=rhel6 Found a matching signature: breed=redhat, version=rhel6 Adding distros from path /var/www/cobbler/ks_mirror/centos6.5-x86-64: creating new distro: centos6.5-64-x86_64 trying symlink: /var/www/cobbler/ks_mirror/centos6.5-x86-64 -> /var/www/cobbler/links/centos6.5-64-x86_64 creating new profile: centos6.5-64-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/centos6.5-x86-64 for centos6.5-64-x86_64 processing repo at : /var/www/cobbler/ks_mirror/centos6.5-x86-64 need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.5-x86-64 looking for /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/*comps*.xml running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/centos6.5-x86-64/repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/centos6.5-x86-64 received on stdout: Spawning worker 0 with 3995 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete received on stderr: *** TASK COMPLETE ***
列出全部的distro
[root@c3 ~]# cobbler distro list centos6.5-64-x86_64
二、管理profile
cobbler使用profile来为特定的需求类别提供所须要安装的配置,即在distro的基础上经过提供kickstart文件来生成一个特定的系统安装配置。distro的profile能够出如今pxe的引导菜单中做为安装的选择之一。
关于kickstart的文件制做请参照个人上篇博客
添加profile
# cobbler profile add --name=centos6.5-x86_64 --distro=centos6.5-64-x86_64 --kickstart=/root/anaconda-ks.cfg 列出当前系统上的profile # cobbler profile list centos6.5-64-x86_64 centos6.5-x86_64 删除掉一个profile # cobbler profile remove --name=centos6.5-64-x86_64 # cobbler profile list centos6.5-x86_64
三、重启cobblerd服务并同步数据到相应目录
# service cobblerd restart # cobbler sync
四、系统安装测试
7、配置cobbler_web
cobbler_web支持多种认证方式,如authn_configfil、authn_ldap或 authn_pam等,默认为authn_denyall拒接全部。
下面咱们使用authn_pam模块认证cobbler_web用户
# vim /etc/cobbler/modules.conf module = authn_pam # useradd zxj # passwd zxj 输入密码 # vim /etc/cobbler/users.conf [admins] admin = "zxj"
访问:https://172.16.13.8/cobbler_web (注意我使用的虚拟机是双网卡172.16.13.8与192.168.13.8两个ip地址)
此时咱们能够手动的添加删除配置,更灵活的对distro 、profile等组件的管理!
PS: 水平有限,有错误请指出!