cobbler環境搭建+IPMI/PXE遠程裝機

   Red Hat發佈的網絡安裝服務器套件Cobbler(在2008年左右發佈),它已將 Linux網絡安裝的技術門檻,從大專以上文化水平,成功下降到初中如下,連補鞋匠都能學會。對於咱們這些在裝機領域浸淫多年,經驗豐富,老驥伏櫪,志在千里的民工兄弟們來講,不啻爲一個晴天霹靂,杯具的是之前我居然不會,話很少說,直接開始試驗... html

    實驗環境:cobbler server 10.1.6.234 (DELL 610 ubuntu12.04) linux

              待安裝服務器 *2 (DELL 410) git

              關於網絡環境,都在同一個交換機下,同一vlan中,由於要用IPMI遠程安裝,網絡環境仍是要設置好的。 github

    實驗結果:ubuntu12.0四、centos6.3安裝成功,debian六、ubuntu12.10安裝失敗,下面開始部署cobbler環境。 web

1 安裝cobbler shell

#安裝cobbler
apt-get install cobbler
#在安裝debian系列時會用到的一個軟件包
apt-get install debmirror 
#安裝cobbler的web管理界面
apt-get install cobbler-web
    使用到的相關環境包tftpd-hpa、dhcp3-server會自動安裝。web界面能夠經過http://10.1.6.234/cobbler_web查看,不過目前你還沒法查看,由於相關用戶尚未設置,爲cobbler用戶重置密碼:


#回車後會讓你重置密碼
htdigest /etc/cobbler/users.digest "Cobbler" cobbler


2 配置基本安裝環境 ubuntu

  A 關於tftpd-hpa的配置:/etc/default/tftpd-hpa(默認無需修改,你能夠根據本身的環境定製) centos

# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

   經過/etc/init.d/tftpd-hpa 腳本管理 服務器

  B 關於dhcp的配置:/etc/dhcp/dhcpd.conf(須要根據你的環境進行設置,我所在的是10.1.6.x網段),不過爲了使用腳本管理dhcp的運行,咱們先設置/etc/default/isc-dhcp-server 網絡

    /etc/default/isc-dhcp-server:由於個人cobbler server只啓動了eth0網卡,因此dhcp監聽在eth0接口上

# Defaults for dhcp initscript
# sourced by /etc/init.d/dhcp
# installed at /etc/default/isc-dhcp-server by the maintainer scripts
# This is a POSIX shell fragment
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
INTERFACES="eth0"
    /etc/dhcp/dhcpd.conf:

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.1.6.0 netmask 255.255.255.0 {
  range 10.1.6.1 10.1.6.245;
  option routers 10.1.6.254;
  option broadcast-address 10.1.6.255;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 10.1.6.234;
  filename  "pxelinux.0";
}

      過/etc/init.d/isc-dhcp-server 腳本管理

  C 關於cobbler的配置,cobbler安裝完成後,仍是有不少目錄要使用的,主要用到的解釋以下:

     /var/lib/cobbler 存儲導入的鏡像的配置信息,kickstarts目錄存放kickstarts腳本,snippets目錄存放在kickstat配置文件中能夠執行的腳本,config目錄提供配置信息,還有其餘目錄基本上無需配置。
     /var/www/cobbler 是導入發行版的操做系統的數據目錄,ks_mirror裏面是導入的發行版系統,images裏面是全部發行版的kernel和initrd,用於遠程網絡啓動。
     /var/log/cobbler 是日誌目錄
     /etc/cobbler 是cobbler的配置文件目錄,settings是主配置文件,裏面還有一些相關配置模版,users.conf是用戶,users.digest是用戶及密碼

      別看這麼多目錄,其實安裝cobbler完成後,基本配置也是不須要咱們修改的,settings配置文件是主配置文件,有不少參數能夠配置,詳細的選項信息能夠查看:http://cobbler.github.com/manuals/2.2.3/4/2_-_Cobbler_Settings.html

 D  關於IPMI的配置,由於要遠程安裝,在DELL服務器中,IPMI這個工具仍是很給力的,三臺機器都須要設置IPMI,由於cobbler server有操做系統,因此能夠在系統中經過ipmitool命令進行設置,而兩臺客戶機由於尚未操做系統,因此要提早設置好ipmi,兩臺客戶機以下設置:

     設置IPMI地址及用戶密碼,開機按照提示按crtl+E進入IPMI配置界面


    選擇LAN Parameters,設置該客戶機的IPMI地址是172.16.6.200

    而後選擇LAN User Configuration,設置root密碼,而後保存退出。

   爲了在遠程能抓到客戶端的啓動過程,還須要設置BIOS,開機按F2進入BIOS進行設置


   選擇Integrated Devices,由於只有一塊網卡,因此設置從NIC1 啓動PXE

   選擇Serial Communication,設置串口,而後保存退出。

3 初始化cobbler安裝環境

  前面說了我實驗了四個發行版,成功兩個,失敗兩個,爲了快速安裝都是導入相關iso做爲安裝源的,因此第一步是準備相關iso發行版,個人以下:

/opt
├── CentOS-6.3-x86_64-bin-DVD1.iso
├── debian-6.0.2.1-amd64-CD-1.iso
├── ubuntu-12.04-server-amd64.iso
└── ubuntu-12.10-server-amd64.iso
  以ubuntu12.04爲例進行講解,由於用這個iso能夠成功安裝客戶機


  A 導入iso鏡像

mount -o loop ubuntu-12.04-server-amd64.iso /mnt
cobbler import --path=/mnt --name=ubuntu12.04
     B 查看導入的結果:cobbler list,也可使用cobbler profile/distro list查看

cobbler list
###顯示結果以下
distros:
   ubuntu12.04-x86_64
profiles:
   ubuntu12.04-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
     很惋惜ubuntu12.04默認導入的 profile/distro配置有問題,因此咱們必須修改。


    修改distro

cobbler distro edit --name=ubuntu12.04-x86_64 \
--kernel=/var/www/cobbler/ks_mirror/ubuntu12.04/install/netboot/ubuntu-installer/amd64/linux \
--initrd=/var/www/cobbler/ks_mirror/ubuntu12.04/install/netboot/ubuntu-installer/amd64/initrd.gz --arch=x86_64 \
--breed=ubuntu --os-version=precise
      建立/var/lib/cobbler/kickstarts/ubuntu12.04.preseed,該文件爲ubuntu12.04的preseed文件。

touch /var/lib/cobbler/kickstarts/ubuntu12.04.preseed
#######文件內容以下########
### Localization
d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i localechooser/supported-locales zh_CN.UTF-8

### Network configuration
d-i netcfg/enable boolean false
d-i netcfg/choose_interface select auto
d-i netcfg/disable_autoconfig boolean true
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Do not configure the network at this time

### Mirror settings
d-i mirror/country string manual
d-i mirror/http/hostname string 10.1.6.234
d-i mirror/http/directory string /ubuntu12.04
d-i mirror/http/proxy string
d-i mirror/udeb/components multiselect main, restricted
#d-i mirror/http/mirror select mirrors.163.com
#d-i mirror/suite string quantal

### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string 10.1.1.2
d-i time/zone string Asia/Shanghai

### Partitioning
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
#d-i partman-auto/choose_recipe select atomic
d-i partman-auto/expert_recipe string      \
    boot-root ::                           \
           50000  50000  50000  ext4       \
                 $primary{ }               \
	          $bootable{ }	       \
                 method{ format }          \
		  format{ }   	              \
                 use_filesystem{ }         \
	         filesystem{ ext4 }	       \
                 mountpoint{ / }	       \
	      .                             \
            8000  8000 8000 linux-swap     \
	         method{ swap }             \
		  format{ }                  \
	      .                             \
	    10000 1000 1000000 ext4         \
                  method{ format }         \
	          format{ }   		\
                  use_filesystem{ }        \
		  filesystem{ ext4 }   	\
                  mountpoint{ /opt }	\
	      .                             \	
d-i partman/default_filesystem string ext4

d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/mount_style select uuid

### Base system installation
#d-i base-installer/install-recommends boolean true
#d-i base-installer/kernel/image     string linux-generic
d-i base-installer/kernel/image     string linux-server

### Account setup
d-i passwd/root-login boolean true
d-i passwd/root-password password 123456
d-i passwd/root-password-again password 123456
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i passwd/make-user boolean false

### Package selection
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server 
d-i pkgsel/upgrade select none
d-i pkgsel/language-packs multiselect de, en, zh
d-i pkgsel/update-policy select none
d-i pkgsel/updatedb boolean true

### Boot loader installation
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true

### Finishing up the installation
d-i finish-install/reboot_in_progress note

 preseed解釋可見:https://help.ubuntu.com/12.04/installation-guide/example-preseed.txt

   修改profile

cobbler profile edit --name=ubuntu12.04-x86_64 \
--kickstart=/var/lib/cobbler/kickstarts/ubuntu12.04.preseed

   cobbler命令有不少參數可使用:

cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version> [options|--help]

   經常使用的有:distro相似於發行版,profile相似於該發行版的一些配置,system對安裝的機器作具體配置,是根據mac地址生效的。 

   cobbler check  檢查配置是否正確
   cobbler list  列出全部的cobbler元素
   cobbler distro/profile list  單獨列出該信息
   cobbler sync  同步信息 在修改完cobbler配置後,都須要同步信息
   cobbler report  顯示詳細的元素信息

 C 設置本地源,在ubuntu12.04.preseed配置文件中有用

cd /var/www
ln -s /var/www/cobbler/ks_mirror/ubuntu12.04 ubuntu12.04

   D  修改pxelinux.cfg配置,由於使用dell的機器,若是啓動時沒有設置速率,在遠程安裝的時候,抓不到屏幕,對於410以上的機器速率是115200,2950之類是57600

    /var/lib/tftpboot/pxelinux.cfg/default,在append行末添加console=ttyS1,115200

DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://fedorahosted.org/cobbler
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
    MENU LABEL (local)
    MENU DEFAULT
    LOCALBOOT -1
LABEL ubuntu12.04-x86_64
     kernel /images/ubuntu12.04-x86_64/linux
     MENU LABEL ubuntu12.04-x86_64
     append initrd=/images/ubuntu12.04-x86_64/initrd.gz  locale=  locale=en_US priority=critical text  auto url=http://10.1.6.234/cblr/svc/op/ks/profile/ubuntu12.04-x86_64 hostname=ubuntu12.04-x86-64 domain=local.lan suite=precise console=ttyS1,115200
     ipappend 2
MENU end

 E  在安裝過程當中會彈出相似的xxx/binary-amd64/Packages was corrupt,這是由於在相關目錄下沒有Packages這個文件,只要進入該目錄建立Packages文件就能夠

 F  開始安裝遠程客戶機,在cobbler server的eth0上綁定IPMI的網段地址。

ifconfig eth0:1 172.16.6.252 netmask 255.255.255.0
####結果以下
eth0:1    Link encap:Ethernet  HWaddr 18:03:73:f0:a7:03  
          inet addr:172.16.6.252  Bcast:172.16.6.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:36 Memory:d6000000-d6012800 
#####ping到客戶端ipmi地址,發現是通的
    而後開兩個窗口分別執行以下IPMI命令

##1窗口,經過ipmi鏈接到客戶機
ipmitool -I lanplus -H 172.16.6.200 -U root -P 123456  sol activate
##2窗口,設置需哦那個pxe引導
ipmitool -I lanplus -H 172.16.6.200 -U root -P 123456  chassis bootdev pxe
##2窗口,設置重啓客戶機
ipmitool -I lanplus -H 172.16.6.200 -U root -P 123456  chassis power reset
 G 享受過程吧...


  如下是個人配置文件設置的小問題,須要手動敲兩下回車:

  這個我配置文件(preseed)設置的不配置網卡,不知道爲何出現這個,後面再研究一下配置文件


   這一步不須要設置,不然安裝過程會比較慢...


  兩個回車後,就能夠坐等系統重啓了...


 H Centos6.3安裝

  步驟的設置和ubuntu12.04的安裝過程同樣,不過不須要修改distro/profile,直接import便可。

下面是centos6.3.ks的配置文件

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr --driveorder=sda
# 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=http://10.1.6.234/cblr/links/CentOS6.3-x86_64  
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
#repo --name=source-1 --baseurl=http://10.1.6.234/cobbler/ks_mirror/CentOS6.3
$yum_repo_stanza
# Network information
#network --bootproto=dhcp --device=em1 --onboot=on
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw 123456
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# make partion
partition / --fstype="ext4" --asprimary   --size=50000
part swap  --size=8192
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%packages
$SNIPPET('func_install_if_enabled')
$SNIPPET('puppet_install_if_enabled')
%post
$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('puppet_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
       此次沒有出現ubuntu12.04須要手動干預的狀況,IPMI從PXE啓動後,直接坐等客戶機系統安裝完成後重啓...



相關設置preseed/kickstarts資料:

http://www.debian.org/releases/stable/example-preseed.txt
https://help.ubuntu.com/12.10/installation-guide/example-preseed.txt
https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html


收集已經安裝完成系統的preseed信息:

    獲取你的Kickstarts配置文件,在Red Hat系列中system-config-kickstart能夠幫助你生成一個kickstart文件,或者查看/root/anaconda-ks.cfg,關於debian系統則能夠apt-get install debconf-utils而後debconf-get-selections --installer > preseed.cfg

相關文章
相關標籤/搜索