基于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

相关推荐

  • LVS

    LVS概述 1.LVS:Linux Virtual Server全称叫做linux虚拟服务器,是一个虚拟的服务器集群系统。本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一。四层路由器(交换),根据请求报文的目标IP和目标协议及端口将其调度转发至后端主机集群中的某台RealServer(真实服务器),根据调度算法来挑选RS; 主要有…

    Linux干货 2016-11-07
  • 文件管理权限

    命令和笔记

    Linux干货 2017-12-03
  • Bash shell 脚本编程全攻略(上篇)

    Bash shell 脚本编程全攻略(上篇)   什么是shell脚本呢? 当命令不在命令行上执行,而是通过一个文件执行时,该文件就称为shell脚本,脚本以非交互的方式运行。Shell脚本把命令通过一些语法组织起来,便能实现特定的功能。   Shell脚本主要运用在系统运维中,主要功能有: 自动化常用命令; 执行系统管理和故障排除; 创…

    Linux干货 2016-08-29
  • N23-第三周博客作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d' ' -f1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 [root@localhost ~]# last -1 | head -1 3、取出当前系统上被用户当…

    Linux干货 2016-12-05
  • 系统自动化安装和SELinux

    一、知识整理 1、anaconda系统安装程序:默认图形启动; 使用光盘启动,在选择模式界面tab键在后面增加text或按下ESC键,输入lnux text进入字符界面安装。 2、创建kickstart文件: 直接手动编辑:依据模板修改,/root目录下的anaconda.cfg 使用创建工具创建:system-config-kickstart,图形化工具:…

    Linux干货 2016-09-26
  • 关于大型网站技术演进的思考(十四)–网站静态化处理—前后端分离—上(6)

    原文出处: 夏天的森林    前文讲到了CSI技术,这就说明网站静态化技术的讲述已经推进到了浏览器端了即真正到了web前端的范畴了,而时下web前端技术的前沿之一就是前后端 分离技术了,那么在这里网站静态化技术和前后端分离技术产生了交集,所以今天我将讨论下前后端分离技术,前后端分离技术讨论完后,下一篇文章我将会以网站 静态化技术…

    Linux干货 2015-03-11

评论列表(1条)

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

    –kickstart 这个把 — 去掉