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

简介:

前言

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

Cobbler

简介

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

组件

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

wKioL1Wbocngi5VoAACtSI3S6b0336.jpg

实现过程

实验拓扑

wKiom1WaDUbDjtmkAAB8XGR99Og008.jpg

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

安装cobbler

1
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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

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

配置cobbler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#检查需要修改的配置,需启动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)

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

wKioL1WaXsSANsEyAAMc6Ac4GSg449.jpg

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

wKioL1Wan77SZxKEAANC2hAwnL8092.jpg

验证是否导入成功

wKioL1WaW9Tz38fwAAHKf9URRM0985.jpg

添加profile

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

wKiom1WaWzjilkXfAAEsKMyiX1o507.jpg

同步数据

1
2
3
4
5
6
[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

wKiom1Wakqqg__O9AAEU5S1fiH0287.jpg

部署测试

设置为网卡启动

wKioL1WalKfD5JWnAADS5JWn4T4453.jpg

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

wKiom1Wak1_xbzKJAADeZ9HRyn0302.jpg

引导成功,开始安装

wKioL1WalVSDSL07AAEr52X9Rn0514.jpg

安装CentOS7

wKiom1WalBSg_ZRSAADvzo9Sn7I046.jpg

引导成功,开始安装

wKioL1Walg3DpBloAAEdnvA4zlg336.jpg

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

CobblerWeb界面

安装cobbler-web

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#修改认证方式
[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  ]

访问测试

wKioL1Wang2CUlhXAAEg_M09REU924.jpg

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

wKiom1WanG6Rxyf7AAJcXqxK-_c479.jpg

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

The end 

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



本文转自 北城书生  51CTO博客,原文链接:http://blog.51cto.com/scholar/1672176

相关文章
|
7月前
|
存储 缓存 NoSQL
Harbor高可用集群设计及部署(基于离线安装方式一)
基于Harbor离线安装方式的高可用方案设计及部署。
155 0
|
7月前
|
关系型数据库 应用服务中间件 数据库
Harbor高可用集群设计及部署(基于离线安装方式二)
基于Harbor离线安装方式的高可用方案设计及部署。
205 0
|
11月前
|
Linux Shell 开发工具
使用PXE工具批量部署服务器
使用PXE工具批量部署服务器
143 0
|
11月前
|
Kubernetes 容器
k8s一键部署脚本(多版本通用版)
k8s一键部署脚本(多版本通用版)
|
缓存 NoSQL Redis
twemproxy安装问题与不支持的操作明细
twemproxy安装问题与不支持的操作明细
75 0
|
网络协议 Linux API
使用cobbler 安装工具批量安装服务器
Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机一,同时还可以管理DHCP,DNS等。
140 0
使用cobbler 安装工具批量安装服务器
|
Linux 开发工具 数据安全/隐私保护