45
PPTV 分分分分分分KenZhu [email protected] 10/9 2012

PPTV 分布式装机系统

  • Upload
    jock

  • View
    309

  • Download
    0

Embed Size (px)

DESCRIPTION

PPTV 分布式装机系统. KenZhu [email protected] 10/9 2012. Agenda. PPTV 分布式装机系统介绍 实际面临的问题 解决方案 系统部署 系统组件介绍 系统实现 Cobbler 配置文件同步 Cobbler 自动部署 应用实例 Cobbler Quick-Start Cobbler 动态 ks file Cobbler Tips 二 次开发. 实际面临的问题. 服务器系统安装处于半手工状态,有些 isp 机房甚至需要现场通过光盘安装,耗费大量人力和时间 - PowerPoint PPT Presentation

Citation preview

Page 1: PPTV 分布式装机系统

PPTV 分布式装机系统

[email protected]

10/9 2012

Page 2: PPTV 分布式装机系统

Agenda• PPTV 分布式装机系统介绍

– 实际面临的问题– 解决方案– 系统部署– 系统组件介绍

• 系统实现– Cobbler – 配置文件同步– Cobbler 自动部署

• 应用实例– Cobbler Quick-Start– Cobbler 动态 ks file– Cobbler Tips

• 二次开发

Page 3: PPTV 分布式装机系统

实际面临的问题• 服务器系统安装处于半手工状态,有些 isp 机房甚至需要现场通过光盘安装,耗费大量人力和时间• 非标准化的系统安装,导致业务部署时遇到这样那样的奇怪问题• 系统安装是瓶颈,由于以上问题导致业务需要快速部署时,无机器可用的现象

Page 4: PPTV 分布式装机系统

实际面临的问题• 众多机房,由于网络互通互联的问题,只在核心机房架设 kickstart server 完全无法解决问题;如采用分布式架构,每个机房部署一台kickstart server ;如何统一配置,安装模板以及安装源等

• 业务众多,每个业务对应静态安装模板,不便于管理• 对于某些机房没有可以独立使用机器,在业务机如何复用的问题

Page 5: PPTV 分布式装机系统

解决方案• Cobbler 开源项目;基于 kickstart ,方便快速的网络安装操作系统• Git 分布式版本控制;静态配置文件的同步• Django 框架;动态配置文件的同步• Rsyncd ;安装源同步• 编译 Cobbler 依赖服务 apache, python 并打包;解决复用的问题• 使用 ControlTie 自动部署

Page 6: PPTV 分布式装机系统

系统部署

Page 7: PPTV 分布式装机系统

系统部署• BGP 机房搭建一台 Cobbler Master ;该服务器管理系统的配置,安装模板以及 cobbler 部署包;并同时作为该机房的 cobbler server 提供安装服务• 所有核心机房部署 Cobbler Secondary ;作为本机房的安装服务器并提供安装源同步• 其他机房的 Cobbler ,由 ControlTie 自动部署,可以复用业务机器

Page 8: PPTV 分布式装机系统

系统组件

Page 9: PPTV 分布式装机系统

系统组件• Cobbler 主要服务,提供 kickstart server• Git Repository 静态配置文件同步源 • Git git 客户端,用于同步源上的配置文件• Django 调用 cobbler API, 同步动态配置文件• Nginx 发布 Git repository & Django

application• Rsync 用于安装源同步• Python 包含 cobbler 依赖模块的 python• Apache 发布 cobbler 安装源

Page 10: PPTV 分布式装机系统

系统实现• Cobbler

– Cobbler 介绍– Cobbler models– Cobbler 动态 KS

• 配置文件同步– Git 静态配置文件同步– Django 动态配置文件同步– 配置文件同步脚本

• Cobbler 自动部署– Cobbler 部署包– ControlTie 部署

Page 11: PPTV 分布式装机系统

Cobbler• 基于 kickstart, linux 系统网络快速安装• 按不同对象组合动态生成 kickstart template, 通过 ksmeta, snippets 实现

• Koan 方便实现重装系统,安装虚拟机• 统一管理 dhcp, tftp, dns 这些网络安装依赖的服务• 支持大部分主流 linux 发行版本, RHEL, Debian, Suse, Ubuntu, Fedora etc.

Page 12: PPTV 分布式装机系统

Cobbler Models

Page 13: PPTV 分布式装机系统

Cobbler Models• Distro 定义安装源, kernel, initrd• Profile 定义 KS file 等信息,可以认为该对象是对应一个业务的 template• System 定义系统信息,比如 hostname, ip地址等信息

Page 14: PPTV 分布式装机系统

Cobbler 动态 KS• KS file 使用 snippet 模块化,便于管理• 通过 cobbler models 中不同参数,动态生成标准化的 ks file• Cheetah 实现模板中变量替换,以及逻辑的运算 ;其中的伪代码通过 python 编译器解析

Page 15: PPTV 分布式装机系统

Git 静态配置文件同步• 所谓静态配置文件是指每台 cobbler server上基本一致的配置文件,比如 kickstart files, snippets 等

• Cobbler Master 上建立 git repository• Cobbler 部署时通过 git clone 同步kickstarts, snippets, triggers 这些静态配置文件

• Crontab 定期从 Master 那里 git pull 回最新的配置

Page 16: PPTV 分布式装机系统

Git• 目前流行的版本控制工具• 分布式版本控制软件• 对比集中式,分布式提供离线版本控制• 为应用提供配置文件的版本控制 & 分布式同步方式

Page 17: PPTV 分布式装机系统

配置文件部署Git clone生成 kickstart, snippets, triggers这些配置文件,并和 git repository上的同步...test -x /var/lib/cobbler && cd /var/lib/cobbler/ || {echo -ne "cobbler directory doesn't exist! \n"exit 0}rm -rf kickstartsrm -rf snippetsrm -rf triggersgit clone http://<cobbler master>/cobbler-git/kickstarts.gitgit clone http://<cobbler master>/cobbler-git/snippets.gitgit clone http://<cobbler master>/cobbler-git/triggers.git...

Page 18: PPTV 分布式装机系统

同步脚本使用 git pull 命令从 git repository 拉取配置更新echo -ne "Kickstarts sync "cd $CB_DATA_PATH/kickstartsgit pull && echo -ne "[OK]\n" || echo -ne "[FAILED]\n"

echo -ne "Snippets sync "cd $CB_DATA_PATH/snippetsgit pull && echo -ne "[OK]\n" || echo -ne "[FAILED]\n"

echo -ne "Triggers sync "cd $CB_DATA_PATH/triggersgit pull && echo -ne "[OK]\n" || echo -ne "[FAILED]\n"

Page 19: PPTV 分布式装机系统

Django 动态配置文件同步• 所谓动态配置文件是指由于不同 cobbler 配置,而产生的配置文件;比如每台 cobbler 上的profile 对象,由所在 cobbler server 的distro 对象决定

• 通过 django 调用 cobbler api• 使用 nginx 发布 django 应用,可通过 http远程调用• Crontab 定期调用,通过传入参数,获取配置文件列表并同步

Page 20: PPTV 分布式装机系统

Profile 对象查询接口...from cobbler.api import BootAPI #cobbler api

#传入 distro参数,返回 profile配置文件列表def profile_list(request, distro): cb_api = BootAPI() profiles = cb_api.find_profile(return_list=True, distro=distro) data = [] for profile in profiles: profile_url = "%s/%s.json" % (settings.PROFILES_URL, profile.name) data.append(profile_url) return HttpResponse("|".join(data), 'text/html')...

Page 21: PPTV 分布式装机系统

同步脚本...DISTROS=$(cobbler distro list) #取得此 cobbler的所有 distro对象for distro in $DISTROSdo PROFILES=$(curl http://<cobbler master>/profile_list/$distro/ 2>/dev/null | tr ‘\|’ ‘ ’) #访问 Profile对象查询接口 for profile in $PROFILES do echo -ne "Download $profile \t\t" wget -q $profile && echo -ne "[OK]\n" || echo -ne "[FAILED]\n" donedone...

Page 22: PPTV 分布式装机系统

Cobbler 自动部署• Cobbler 部署包• ControlTie Task – Cobbler 部署– Cobbler 配置– Cobbler 安装源同步

Page 23: PPTV 分布式装机系统

Cobbler 部署包• 自动部署时包含 cobbler 源码以及依赖模块,服务的包• Cobbler 源码• Apache2.2.21 编译时必须包含wsgi_module 模块

• Python2.7• Cheetah, yaml, pykickstart 相应python 模块

Page 24: PPTV 分布式装机系统

CT - Cobbler 部署步骤• 设置相应环境变量,系统设置(关闭 iptables, selinux, yum 设置)

• 通过 yum 安装所需服务的 rpm 包• 下载 cobbler 部署包,并在本机进行编译安装• 同步配置文件• 部署完成

Page 25: PPTV 分布式装机系统

CT – Cobbler 部署#install required rpmsyum install createrepo dhcp curl-devel tftp-server yum-utils mkisofs git -y

#fetch cobbler packagecd /tmpwget http://<cobbler master>/packages/cobbler_proxy-2.2.0.tar.bz2 --output-document=cobbler_proxy-2.2.0.tar.bz2

#cobbler installationcd /home/toolstar jxvf /tmp/cobbler_proxy-2.2.0.tar.bz2cd /home/tools/package; rpm -ihv *.rpmcd /home/tools/cobbler-2.2.0; make; make install;grep "tools" /etc/ld.so.conf || sed -i 'a/\/home\/tools\/python\/lib/' /etc/ld.so.conf && echo -ne ""

Page 26: PPTV 分布式装机系统

CT – Cobbler 设置• 对于 cobbler 参数进行设置 Cobbler server , next_server

• dhcp 参数设置 ;• 这些参数通过 ControlTie 传入

Page 27: PPTV 分布式装机系统

CT – Cobbler 设置...COBBLER_SETTING=/etc/cobbler/settingsDHCP_SETTING=/etc/cobbler/dhcp.template

#Cobbler settingssed -i '/^server:/ cserver: ${option.server_ip}' $COBBLER_SETTINGsed -i '/^next_server:/ cnext_server: ${option.server_ip}' $COBBLER_SETTING

#DHCP settingssed -i '/^subnet.*/ csubnet ${option.netid} netmask ${option.netmask} {' $DHCP_SETTINGsed -i '/option domain-name-servers/ coption domain-name-servers 8.8.8.8;' $DHCP_SETTINGsed -i '/option subnet-mask/ coption subnet-mask ${option.netmask};' $DHCP_SETTINGsed -i '/range dynamic-bootp/ crange dynamic-bootp ${option.pool_range};' $DHCP_SETTINGsed -i '/option routers/ coption routers ${option.gateway};' $DHCP_SETTING...

Page 28: PPTV 分布式装机系统

CT – 安装源同步• 选择 ISP 和所需同步的系统版本

Page 29: PPTV 分布式装机系统

CT – 安装源同步if [ ${option.isp} = "C1" ]then case ${option.release} in "5.4") echo -ne "sync 5.4 from T1 \n" cobbler import --path=rsync://<cobbler master>/RHEL5.4 --name=RHEL_Server_5.4_PPLive --arch=x86_64 ;; "5.8") echo -ne "sync 5.8 from T1 \n" cobbler import --path=rsync://<cobbler master>/RHEL5.8 --name=RHEL_Server_5.8_PPLive --arch=x86_64 ;; esac

Page 30: PPTV 分布式装机系统

应用实例• Cobbler Quick-Start– 物理机安装– 物理机重装– 虚拟机安装

• Cobbler 动态 ks file 实例– YUM configuration snippet

• Cobbler tips

Page 31: PPTV 分布式装机系统

Machine without OS• Access idrac interface with web browser J2EE

installed• Start remote console• Reboot or startup machine via idrac• Press “F12” to enter PXE mode when machine

booting• Choose 1 profile you want to apply on this

machine in cobbler menu• Starting unattended installation• Configure network interface on the machine when

installation finished

Page 32: PPTV 分布式装机系统

Cobbler Menu

Page 33: PPTV 分布式装机系统

Machine with OS1. Use koan to reinstallyum install koan –y

2. Create a new system on cobbler servercobbler system add --name=JA03469D1201 --profile=cob_5.4_base --ip-address=<ip address> --gateway=<gw ip> --static=true --subnet=255.255.0.0

3. Execute koan on this machine to replace itself koan --server=<cobbler server> --system=JA03469D1201 --replace-self

Page 34: PPTV 分布式装机系统

Xen Virtual-machine installationCobbler server: <cobbler server ip>

1. 首先在 cmdb 中通过 IP确认宿主机资产编号,然后生成虚拟机资产编号,并在cobbler server 生成 system 信息。以 <host> 这台机器为例,宿主机为 <xen host> ,资产编号 JA03469D1201 ,由于该机器为 D1 ,故该虚拟机资产编号为JA03469D1201-1 , cobbler system name 和资产编号一致。

2. 在 cobbler server输入如下命令,添加 systemcobbler system add --name=JA03469D1201-1 --profile=vs_5.4 --ip-address=<ip> --gateway=<gw ip> --static=true –subnet =255.255.255.0

3. 安装 koanYum install koan –y

Page 35: PPTV 分布式装机系统

Xen Virtual-machine installation4. 在宿主机上,执行命令安装虚拟机koan --server=<cobbler server> --virt --system=JA03469D1201-1 --virt-name=D1 --virt-path=/dev/sdb --virt-bridge=xenbr0 -=–nogfx

• server: cobbler server• virt-system: system name you appended before• virt-name: xen virtual server name• virt-path: disk device • virt-bridge: network bridge

Page 36: PPTV 分布式装机系统

动态 ks file 实例RHEL5.4 KS file - distro:RHEL5.4 profile:vs_5.4#[SNIPPET] yum_configuration$SNIPPET('pptv/yum_configuration')

RHEL5.8 KS file - distro:RHEL5.8 profile:vs_5.8#[SNIPPET] yum_configuration$SNIPPET('pptv/yum_configuration')

Page 37: PPTV 分布式装机系统

Snippet/yum_confiuration#set distro=$getVar(‘distro_name’,‘’) 定义 distro 变量,该变量值为该机器所属 distro 的 name

#if ‘5.4’ in $distro 判断是否 distro 为 5.4 ,为真则写入相应配置##Start of YUM Configuration##End of YUM Configurationcat > /etc/yum.repos.d/PPLive.repo << "EOF"[RHEL 5.4 YUM source]EOF#else if '5.8' in $distro 判断是否 distro 为 5.8 ,为真则写入相应配置##Start of YUM Configurationcat > /etc/yum.repos.d/PPLive.repo << "EOF"[RHEL 5.8 YUM source]EOF#else if '6.2' in $distro##Start of 6.2 YUM Configurationcat > /etc/yum.repos.d/PPLive.repo << "EOF"[RHEL 6.2 YUM source]EOF##End of 6.2 YUM Configuration#end if

Page 38: PPTV 分布式装机系统

生成 ks file• 访问 Cobbler Server 的相应 URL, 可以验证生成的 ks file• Profile:/cblr/svc/op/ks/profile/<profile name>

• System: :/cblr/svc/op/ks/system/<system name>

Page 39: PPTV 分布式装机系统

Cobbler tips – dhcp 设置subnet 10.x.0.0 netmask 255.255.0.0 { pool { allow members of "pxe"; allow members of "etherboot"; allow members of "anaconda"; option routers 10.x.1.1; option domain-name-servers 8.8.8.8; option subnet-mask 255.255.0.0; range dynamic-bootp 10.x.250.2 10.x.250.100; filename "/pxelinux.0"; default-lease-time 600; max-lease-time 600; next-server x.x.x.x; }}

Page 40: PPTV 分布式装机系统

Base OS kernel options# kernel options that should be present in every cobbler installation.# kernel options can also be applied at the distro/profile/system# level.kernel_options: ksdevice: bootif dhcpclass: Anaconda # 对应 dchp 中的 tag 设置 lang: 'en_US' text: ~ sshd: ~ vnc: ~ vncpassword: 'cobblervnc' noipv6: ~

Page 41: PPTV 分布式装机系统

二次开发• Cobbler API• Cobbler xmlrpc 远程调用• PPTV 虚拟机自动安装应用

Page 42: PPTV 分布式装机系统

Cobbler API• 通过 Cobbler.api 模块可以操作 cobbler 里所有对象• 研究 cli.py 这个命令接口模块,可以很快了解API 的使用

Page 43: PPTV 分布式装机系统

Cobbler xmlrpc 远程调用• 默认 cobbler xmlrpc 服务绑定在localhost:25151

• 通过修改 utils.py 模块,可以绑定在外部借口,远程进行 cobbler 对象的操作• 也可通过方向代理工具,转发至该端口;对外开放该服务

Page 44: PPTV 分布式装机系统

PPTV 虚拟机自动安装应用

Page 45: PPTV 分布式装机系统

The End