基于Cobbler实现多版本操作系统自动部署

前言

    在生产环境中,当需要批量部署几十甚至上百台服务器时,实现自动化安装操作系统尤为重要,按照传统的光盘引导安装是不可想象的;此前我们通过pxe+kickstart简单实现了自动化安装,但只能实现单一版本安装,当需要部署不同版本或不同引导模式(BIOS、EFI)时,此种方式就不够灵活。而Cobbler正是为了解决此问题而设计的,本文以CentOS为例简单介绍Cobbler的安装配置及使用。

简介

    Cobbler是一个免费开源系统安装部署软件,用于自动化网络安装操作系统。Cobbler 集成了 DNS, DHCP, 软件包更新,带外管理以及配置管理,方便操作系统安装自动化。Cobbler 可以支持PXE启动, 操作系统重新安装,以及虚拟化客户机创建,包括Xen, KVM or VMware. Cobbler透过koan程序以支持虚拟化客户机安装。Cobbler可以支持管理复杂网路环境,如建立在链路聚合以太网的桥接环境。

Cobbler组件结构图

091321HX-0.png

安装配置过程:

① 安装cobbler、dhcp、rsync

② 配置cobbler

③ 导入操作系统,配置profile

④ 配置本地yum仓库

⑤ 配置dhcp、tftp、http

安装cobbler

#安装cobbler会把依赖的服务一并安装,如tftp-server、httpd
[root@localhost ~]# yum  install cobbler
[root@localhost ~]# yum -y install dhcp rsync
#设置开机启动
[root@localhost ~]# chkconfig tftp on
[root@localhost ~]# chkconfig rsync on

配置cobbler

[root@localhost ~]# service xinetd restart
[root@localhost ~]# service cobblerd start
[root@localhost ~]# 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 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5 : ksvalidator was not found, install pykickstart
6 : 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
7 : 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.
#解决办法
1,2:
[root@localhost ~]# vim /etc/cobbler/settings 
server: 192.168.18.45
next_server: 192.168.18.45
3:
[root@localhost ~]# cobbler get-loaders
4:可忽略
5:
[root@localhost ~]# yum -y install pykickstart
6:
[root@localhost ~]# openssl passwd -1 -salt 345223 123456
$1$345223$/jb8Mdzzy3SRfwM5RbG3D.
[root@localhost ~]# vim /etc/cobbler/settings 
default_password_crypted: "$1$345223$/jb8Mdzzy3SRfwM5RbG3D."
7:可忽略

同步cobbler配置,再检查有无报错

[root@localhost ~]# cobbler sync
[root@localhost ~]# service cobblerd restart
[root@localhost ~]# cobbler check
The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.
#配置成功

准备kickstart文件

[root@localhost ~]# cp /var/lib/cobbler/kickstarts/sample_end.ks /var/lib/cobbler/kickstarts/basic.ks
[root@localhost ~]# vim /var/lib/cobbler/kickstarts/basic.ks 
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot

#Root password
rootpw --iscrypted $default_password_crypted   #md5加密的密码串,默认保存在/etc/cobbler/settings
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Chongqing
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
part pv.01 --grow --size=1            
part /boot --fstype=ext4 --size=400
part /boot/efi --fstype=efi --size 200   #EFI模式需要创建该分区
volgroup VolGroup --pesize=4096 pv.01
logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
logvol swap --name=lv_swap --vgname=VolGroup --grow --size=1984 --maxsize=4096


%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end

%packages
@base
@development
@server-platform-devel
samba-client
lftp
openssh-clients
epel-release
#$SNIPPET('func_install_if_enabled')
%end

%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end

%post
echo -e "alias net-pf-10 off\noptions ipv6 disable=1" >/etc/modprobe.d/ipv6.conf
echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network
chkconfig ip6tables off
cat >> /etc/security/limits.conf <<EOF
*           soft    nproc           65535
*           hard    nproc           65535
*           soft    nofile          102400
*           hard    nofile          204800
EOF
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end

导入操作系统到cobbler,添加profile

[root@localhost ~]# mount /dev/sr0 /mnt  #挂载光驱
[root@localhost ~]# cobbler import --name=CentOS-6.6-x86_64 --path=/mnt  #导入操作系统
[root@localhost ~]# ll /var/www/cobbler/ks_mirror/  #验证一下是否导成功
[root@localhost ~]# cobbler profile add --name=CentOS-6.6-basic --distro=CentOS-6.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/basic.ks
[root@localhost ~]# cobbler profile list  #验证一下
[root@localhost ~]# cobbler sync  #同步一下

配置本地yum仓库

#配置本地yum仓库
[root@localhost ~]# mkdir /tmp/rpms
[root@localhost ~]# createrepo /tmp/rpms  #放入rpm包,执行此步骤
[root@localhost ~]# cobbler repo add --mirror=/tmp/rpms --name=local
[root@localhost ~]# cobbler reposync
#配置本地epel仓库
[root@localhost ~]# cobbler repo add --mirror=http://mirrors.aliyun.com/epel/6/x86_64/ --name=epel
[root@localhost ~]# cobbler reposync --tries=3 --no-fail  #同步epel仓库到本地,需要较长时间
#查看已添加的repo
[root@localhost ~]# cobbler repo list
   epel
   local
#添加repo到profile
[root@localhost ~]# cobbler profile edit --name=CentOS-6.6-basic --repos="epel local"
[root@localhost ~]# cobbler sync

配置dhcp服务器

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf   #BIOS或EFI模式网络启动都能引导
option arch code 93 = unsigned integer 16; # RFC4578
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.18.0 netmask 255.255.255.0 {
    range 192.168.18.150 192.168.18.230;
    option domain-name "example.org";
    option domain-name-servers 114.114.114.114,8.8.8.8;
    option routers 192.168.18.1;
          class "pxeclients" {
                  match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
                  next-server 192.168.18.45;

                  if option arch = 00:06 {
                          filename "grub/grub-x86.efi";
                  } else if option arch = 00:07 {
                          filename "grub/grub-x86_64.efi";
                  } else {
                          filename "pxelinux.0";
                  }
        }
}

重新启动服务

[root@localhost ~]# service dhcpd restart
[root@localhost ~]# service xinetd restart
[root@localhost ~]# service httpd restart
[root@localhost ~]# service cobblerd restart

客户端安装测试

EFI模式。注意:某些服务器可能不兼容

122.png

BIOS模式

123.png

222.png

客户端验证,可以看到生成了一个repo文件,指向cobbler服务器

[root@localhost ~]# cat /etc/yum.repos.d/cobbler-config.repo 
[core-0]
name=core-0
baseurl=http://192.168.18.45/cobbler/ks_mirror/CentOS-6.6-x86_64
enabled=1
gpgcheck=0
priority=1

[local]
name=local
baseurl=http://192.168.18.45/cobbler/repo_mirror/local
enabled=1
priority=99
gpgcheck=0

至此安装完成,本文只简要介绍了cobbler的安装及配置

可登陆官网 http://cobbler.github.io/ 获取帮助

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

(0)
秦
上一篇 2015-08-11
下一篇 2015-08-11

相关推荐

  • 标准I/O和管道

    程序包含指令和数据,经常需要读入数据和输出数据 打开的文件都有一个fd:file descriptor(文件描述符) 用nano打开一个文件,查看其PID  0,1,2就是所谓的文件描述符。 在Linux里输入输出和错误都由这三个描述符来表示 标准输入(STDIN) -0 默认接受来自键盘的输入 标准输出(STDOUT)-1 默认输出到终端窗口 标…

    Linux干货 2016-08-08
  • 系统基础之vim工具详解

    vim工具详解 作为运维人员,每天要面对大量的文件操作,如何使用一个功能强大,操作快捷的文本编辑器,就至关重要.那天,今天给大家详细的介绍下vim这款编辑器,完全符合我们的要求,下面让我们一起来看看吧! 概论:  文本编辑器:  文本:纯文本信息,   ASCII text:  纯粹的,不加修饰的文字  文本…

    Linux干货 2016-08-10
  • 磁盘管理之文件系统

    一,概述 文件系统是操作系统用于明确存储设备或分区上的文件的方 法和数据结构;即在存储设备上组织文件的方法。操作系统 中负责管理和存储文件信息的软件结构称为文件管理系统, 简称文件系统。  从系统角度来看,文件系统是对文件存储设备的空间进行组 织和分配,负责文件存储并对存入的文件进行保护和检索的 系统。具体地说,它负责为用户建立文件,存入、读出、修…

    Linux干货 2016-09-05
  • LVM work!!!

    1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录.     (1)查看分区大小 [root@localhost ~]# lsblk NAME   MAJ…

    Linux干货 2016-09-01
  • Linux程序包管理(一)RPM使用

    Linux程序包管理 在早期我们使用源代码的方式安装软件时,都需要先把源程序代码编译成可执行的二进制应用程序,然后进行安装。意味着每次安装软件都需要经过 预处理 –> 编译 –> 汇编–> 链接, 这个复杂的过程。为简化安装步骤,程序提供商就在特定的系统上面编译好相关程序的安装文件并进行打包,提…

    Linux干货 2016-06-01
  • Http实践

    练习:搭建虚拟主机     (1)基于主机名实现三个虚拟主机     (2) 每虚拟主机使用独立的访问日志和错误日志     (3) 第三个虚拟主机的/admin要进行用户访问认证     (4) 在…

    Linux干货 2016-09-30