基于Cobbler实现多版本系统批量部署

前言

运维自动化在生产环境中占据着举足轻重的地位,尤其是面对几百台,几千台甚至几万台的服务器时,仅仅是安装操作系统,如果不通过自动化来完成,根本是不可想象的。记得前面我们探究了基于PXE实现系统全自动安装,但PXE同时只能提供单一操作系统的批量部署,面对生产环境中不同服务器的需求,该如何实现批量部署多版本的操作系统呢?Cobbler便可以的满足这一实际需求,本文带来的是基于Cobbler实现多版本操作系统批量部署。

Cobbler

简介

Cobbler是一款自动化操作系统部署的实现工具,由Python语言开发,是对PXE的二次封装。融合多种特性,提供了CLI和Web的管理形式。同时,Cobbler也提供了API接口,方便二次开发使用。它不仅可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。另外,它还能结合Puppet等集中化管理软件,实现自动化管理。

组件

Cobbler的各主要组件间关系如图所示

cobbler组件关系图.jpg

实现过程

实验拓扑

基于Cobbler实现多版本系统批量部署.jpg

#注意事项:请确保selinux关闭,防火墙放行相关端口或关闭防火墙

安装cobbler

[root@scholar ~]# yum install cobbler -y #需epel及updates支持

cobbler的运行依赖于dhcp、tftp、rsync及dns服务,其中dhcp可由dhcpd提供,也可由dnsmasq提供,tftp可由tftp-server程序包提供,也可由cobbler功能提供,rsync有rsync程序包提供,dns可由bind提供,也可由dnsmasq提供,此处独立管理,即不通过cobbler来管理这些服务。

配置dhcp

#cobbler在安装时会将依赖包tftp-server和xinetd安装,dns服务非必需,所以还要手动安装dhcp
[root@scholar ~]# yum install dhcp -y
[root@scholar ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf 
cp: overwrite `/etc/dhcp/dhcpd.conf'? y
[root@scholar ~]# vim /etc/dhcp/dhcpd.conf 

option domain-name "scholar.com";
option domain-name-servers 172.16.0.1;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 172.16.0.0 netmask 255.255.0.0 {
  range 172.16.10.60 172.16.10.70;
  option routers 172.16.0.1;
  next-server 172.16.10.125;
  filename "pxelinux.0";
}

[root@scholar ~]# service dhcpd start

配置rsync和tftp

[root@scholar ~]# chkconfig tftp on
[root@scholar ~]# chkconfig rsync on
[root@scholar ~]# service xinetd start

配置cobbler

#检查需要修改的配置,需启动httpd服务及cobblerd
[root@scholar ~]# service cobblerd start
[root@scholar ~]# service httpd start
[root@scholar ~]# 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 loc
alhost, or kickstarting features will not work.  This should be a resolvable hostname o
r 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 th
e PXE network.
3 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'c
obbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netboot
ing, 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 wa
nt to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and ya
boot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
4 : debmirror package is not installed, it will be required to manage debian deployment
s and repositories
5 : ksvalidator was not found, install pykickstart
6 : The default password used by the sample templates for newly installed machines (def
ault_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 g
enerate new one
7 : fencing tools were not found, and are required to use the (optional) power manageme
nt features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

#解决方法
1:# vim /etc/cobbler/settings 
server: 172.16.10.125
2:# vim /etc/cobbler/settings
next_server: 172.16.10.125
3:# cobbler get-loaders  #需要可访问互联网,尝试此法返回404错误,只好手动复制文件
# yum install syslinux -y
# cp -r /usr/share/syslinux/* /var/lib/cobbler/loaders/
4:忽略即可
5:# yum install pykickstart -y
6:]# openssl passwd -1 -salt `openssl rand -hex 4`
Password: 
$1$ebcbf370$s8C9mNday5b.lE5nh4.7N1
  # vim /etc/cobbler/settings 
default_password_crypted: "$1$ebcbf370$s8C9mNday5b.lE5nh4.7N1"
7:安装cman或fence-agents   #可忽略

[root@scholar ~]# service cobblerd restart

添加distro(distribution)

#挂载光盘镜像,每换一个系统镜像都需重新挂载
[root@scholar ~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
#导入CentOS6镜像文件

11.jpg

#导入CentOS7镜像文件,请确保已重新挂载镜像

12.jpg

验证是否导入成功

13.jpg

添加profile

#kickstart文件可按实际需要制作,这里直接修改/root/anaconda-ks.cfg,添加关键配置项如下:
url --url=http://172.16.10.125/cobbler/ks_mirror/CentOS-7.0-x86_64  #指定repo位置
#注:CentOS6与CentOS7文件系统不同,千万不能用相同kickstart文件

14.jpg

同步数据

[root@scholar ~]# cobbler sync

#CentOS7与CentOS6安装过程略有区别,CentOS7在数据同步完成后需要再次指定安装源
[root@scholar ~]# vim /var/lib/tftpboot/pxelinux.cfg/default 
#将此项加入CentOS7的append行内
inst.repo=http://172.16.10.125/cobbler/ks_mirror/CentOS-7.0-x86_64

instrepo.jpg

部署测试

设置为网卡启动

15.jpg

保存重启后进入引导界面,我们先安装CentOS6

16.jpg

引导成功,开始安装

17.jpg

安装CentOS7

18.jpg

引导成功,开始安装

19.jpg

至此,基于Cobbler实现多版本系统批量部署已成功实现,其实以上配置过程可以使用web界面配置,这样就可以不再刻意的去记繁琐的命令,下面我们就来简单看一下

CobblerWeb界面

安装cobbler-web

[root@scholar ~]#  yum install cobbler-web -y

cobbler-web支持多种认证方式,如authn_configfil、authn_ldap或authn_pam等,下面我们基于authn_pam做认证

#修改认证方式
[root@scholar ~]# vim /etc/cobbler/modules.conf

[authentication]
module = authn_pam

#添加系统用户
[root@scholar ~]# useradd cobuser
[root@scholar ~]# echo 'cobpass' | passwd --stdin cobuser
#添加用户至管理组
[root@scholar ~]# vim /etc/cobbler/users.conf 
[admins]
admin = "cobuser"

[root@scholar ~]# service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
[root@scholar ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

访问测试

20.jpg

登陆成功便可配置根据选项来配置了

21.jpg

简单介绍一下,就不做深入演示了,有兴趣的朋友可以完整的通过web界面配置一下试试

The end 

好了,以上便是基于Cobbler实现多版本系统批量部署的整个过程,部署过程中遇到问题可留言交流。以上仅为个人学习整理,如有错漏,大神勿喷~~

原创文章,作者:书生,如若转载,请注明出处:http://www.178linux.com/6163

(0)
书生书生
上一篇 2015-07-09 14:15
下一篇 2015-07-10 23:06

相关推荐

  • vsftp简单应用

    vsftp配置详解 前言 FTP(File Transfer Protocol)是文件传输协议的简称。它能让用户 连接上一个远程计算机(运行着 FTP 服务器程序)查看远程 计算机上有哪些文件,然后把文件从远程计算机上下载到 本地计算机,或把本地计算机文件上传到远程计算机。但是ftp是一种古老的文件传输协议,是明文传输,特别的不安全所以就有了vsftp。 一…

    Linux干货 2016-12-18
  • LVM逻辑卷管理相关命令的用法

    前提:创建分区,文件或添加硬盘作为LVM的物理卷 pv(物理卷) 命令用法 1、pvcreate创建pv pvcreate -s    指定PE大小,默认为4M 2、pvremove删除pv 3、pvs,pvdisplay显示pv pvs 显示pv摘要 pvdisplay 详细显示pv 4、pvmove:把卷组中一个物…

    Linux干货 2016-08-30
  • 配置正、反向解析域,主从配置,子域授权

    配置解析一个正向区域:     1、定义区域        在主配置文件中(/etc/named.conf)或主配置文件辅助配置文件(/etc/named.rfc1912.conf)中实现:     (1) 在/etc/…

    Linux干货 2017-05-31
  • 网络及TCP

    为什么要使用分层网络模型     降低复杂性     标准化接口     简化模块化设计     确保技术的互操作性     加快发展速度  &nbs…

    2017-05-08
  • MBR与GPT分区结构的不同及磁盘分区命令总结

    一、MBR分区结构 主引导记录(Master Boot Record,缩写:MBR),又叫做主引导扇区,是目前比较流行的一种分区结构。磁盘的0磁道0扇区称为MBR,它的大小是512字节,这个区域被分为三个部分: 第一部分为boot loader(主引导程序),占446字节; 第二部分为Partition table(分区表),即DPT,占64字节,每个分区项…

    Linux干货 2016-08-29
  • alias——Linux基本命令(4)

    1.     alias别名 (1)查看、设置别名 Linux系统提供了一个有用的工具叫alias,可以让我们将一些需要频繁使用的但又过于冗长的命令设置一个别名,这样一来,以后只需输入一个简短的别名就可以达到同样的作用。 alias显看当前已定义的别名   使用aliasaliname=’comm…

    2017-07-13

评论列表(1条)

  • 胡三刀
    胡三刀 2015-07-30 10:40

    –kickstart 这个把 — 去掉