基于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.www58058.com/6891

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

相關推薦

  • 我的第一篇博客

        第二天,很早的來到,不知道做些什么,未來也l許很忙碌,希望能夠一直堅持,不管是難吃的飯菜,還是不良的作息,起碼做個對得起這四個半月的人吧…

    Linux干貨 2017-07-11
  • Linux sed命令詳則

    sed命令 sed是一種流編輯器,它是文本處理中非常好的工具,能夠完美的配合正則表達式使用,功能不同凡響。處理時,把當前的行儲存在臨時緩存區中,稱為“模式空間”(pattern space),接著用sed命令處理緩存區中的內容,處理完成后,把緩存區的內容送往屏幕。接著處理下一行,這樣不斷重復,直到文件末尾。文件內容并沒有改變,除非你使用重定向存儲輸出。Sed…

    2017-08-11
  • htop使用詳解

        在管理進程時通常要借助一些工具,比較常用的就是ps和top了;不過CentOS還為我們提供了一個更加強大的工具htop,下面就來了解一下此工具的使用方法。 一、安裝htop         htop工具在epel源中提供,請自行配置epel源,也可以直…

    Linux干貨 2015-05-18
  • OpenStack Icehouse私有云實戰部署

    前言 相信你一定對“云主機”一詞并不陌生吧,通過在Web頁面選擇所需主機配置,即可快速定制一臺屬于自己的虛擬主機,并實現登陸操作,大大節省了物理資源。但這一過程是如何實現的呢?本文帶來OpenStack Icehouse私有云實戰部署。 OpenStack 簡介 OpenStack是由網絡主機服務商Rackspace和美國宇航局聯合推出的一個開源項目,Ope…

    Linux干貨 2015-07-29
  • 發送mail的幾種方法

    mail,顧名思義就是郵件。在這兩天上課中,接觸了發送mail的一些用法,課下自己在網上又查詢補充了一下,總結出來,增加印像。 為了顯示清晰,首先我們分別使用兩個用戶在不同的終端下登錄,一個超級管理員root,一個是剛剛創建的用戶zhangsan,看下圖: 首先先來看一下發送mail用到什么選項:  -s<郵件主題>:指定郵件的主題; …

    2017-07-20
  • Linux Sysadmin–part2

    1、寫一個腳本,使用ping命令探測192.168.4.1-192.168.4.254之間的所有主機的在線狀態; 在線的主機使用綠色顯示; 不在線的主使用紅色顯示; #!/bin/bash #description: #date: #Author: for i in {1..254}; do if ping -c 3 192.168.4.$i &&g…

    2017-09-19
欧美性久久久久