PXE和cobbler實現系統自動化安裝

前言:html

本文主要講解pxe基於ftp服務實現系統自動安裝和cobbler基於httpd服務自動安裝系統python


1、PXE系統自動化安裝linux

配置條件web

PXE(preboot execute environment,預啓動執行環境)是由Intel公司開發的最新技術,工做於Client/Server的網絡模式,支持工做站經過網絡從遠端服務器下載映像,並由此支持經過網絡啓動操做系統,在啓動過程當中,終端要求服務器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)協議下載一個啓動軟件包到本機內存中執行,由這個啓動軟件包完成終端(客戶?)基本軟件設置,從而引導預先安裝在服務器中的終端操做系統。PXE能夠引導多種操做系統,如:Windows95/98/2000/windows2003/windows2008/win7/win8,linux等。
sql


vsftpd 是「very secure FTP daemon」的縮寫,安全性是它的一個最大的特色。
express


TFTPTrivial File Transfer Protocol,簡單文件傳輸協議)是TCP/IP協議族中的一個用來在客戶機與服務器之間進行簡單文件傳輸的協議,提供不復雜、開銷不大的文件傳輸服務端口號爲69
vim


TFTP是一個傳輸文件的簡單協議,它基於UDP協議而實現,可是咱們也不能肯定有些TFTP協議是基於其它傳輸協議完成的。windows


PXE 服務器的工做原理

本主題中

DHCP 受權的工做原理

啓動預啓動執行環境 (PXE) 啓動後,PXE ROM 請求 IP 地址從動態主機配置協議 (DHCP) 服務器,使用普通的 DHCP 發現過程。做爲初始 DHCP 發現請求的一部分,客戶端計算機將自身標識爲啓用 PXE 的指示 PXE 客戶端須要提供服務的服務器。客戶端從 DHCP 服務器得到有效的 IP 地址以後,客戶端將嘗試查找並與下載網絡啓動程序 (NBP) 的 PXE 服務器創建鏈接。

默認狀況下 Windows 部署服務 PXE 服務器不須要受權服務的客戶端計算機。可是,您能夠啓用 DHCP 受權,也被稱做是無管理系統檢測。啓用受權檢查和 PXE 服務器被配置爲偵聽端口 67 時,才發生受權檢查。這意味着受權檢查進行僅在沒有 DHCP 的計算機運行的 Windows 部署服務的方案中。若是在同一臺物理計算機上運行的 Windows 部署服務和 DHCP,這意味着在 DHCP 服務器正在偵聽端口 67 和負責確保受權。

Windows 部署服務將檢查受權後,輪詢機制運行以確保受權狀態已不更改每隔一小時。能夠經過使用註冊表設置的輪詢週期修改值 (請參閱部分中的 DHCP 受權Windows 部署服務註冊表項主題)。或者,您能夠從新啓動 PXE 服務器當即拾取改成受權設置。若是 PXE 服務器就會被視爲未經受權,它不會進行應答客戶端請求。

PXE 服務器和提供程序的交互方式

下面的流程圖概述了與另外一個的 PXE 服務器和 PXE 提供程序的交互方式。

Interaction between PXE server and PXE provider.

TFTP Windows 部署服務中的工做方式

普通文件傳輸協議 (TFTP) 是用於在網絡啓動,包括啓動映像的過程當中下載全部文件的網絡協議。TFTP 是一個緩慢的協議,由於它須要一個 ACK (確認) 數據包對於每一個發送的數據塊。服務器將不會發送下一個塊序列中直到收到 ACK 數據包之前一個塊。所以,在較慢的網絡上的往返時間可能會很長。可是,這改進了 Windows Server 2008 中因爲的 TFTP x11 窗口。TFTP x11 窗口使您可以定義多少填滿一個窗口所需的數據塊。數據塊是發回至回,直到填充窗口,而後發送 ACK 數據包。其結果是更少的 ACK 數據包和更快的下載時間,爲該客戶端。

使用 BCDEdit 命令行工具,能夠更改 TFTP 數據塊的大小和 TFTP 窗口大小以優化您的環境中的性能。有關說明,請參閱如何修改 BCD 存儲區使用 Bcdedit (http://go.microsoft.com/fwlink/?LinkId = 115267).

儘管 TFTP 塊大小配置將使 TFTP 下載速度更快,須要注意的兩項內容:

  • TFTP 實如今操做系統加載程序 (Bootmgr.exe),但發送和接收功能與用戶數據協議 (UDP) 在 BIOS 中實現BIOS 緩衝構成單個 TFTP 塊的網絡數據包。若是使 TFTP 數據塊的大小太大,BIOS 所使用的緩衝區將填滿,被覆蓋,從而致使沒法下載。內存緩衝區行爲是惟一的 BIOS 製造商,而且您不能經過使用 Bootmgr.exe 來調整它。所以,結果可能會極大地根據有所不一樣的品牌和型號的計算機。遺憾的是,沒有辦法來計算的塊大小上限試錯法之外的特定計算機。

  • 已配置的數據塊的大小將應用於全部客戶端。 您能夠設置此值爲網絡上的全部客戶端都支持塊大小達到最高。請注意客戶端沒法回退到默認塊大小是否已配置的數據塊的大小太大。


拓撲

141939477.jpg


配置過程:

# yum install tftp-server dhcp vsftpd syslinux
# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
# vim /etc/dhcp/dhcpd.conf
# cat /etc/dhcp/dhcpd.conf | grep -v ^# | grep -v ^$
option domain-name "qiufengsong.com";
option domain-name-servers 192.168.5.254,172.16.0.1;
default-lease-time 44600;
max-lease-time 723300;
log-facility local7;
subnet 192.168.5.0 netmask 255.255.255.0 {
   range 192.168.5.11 192.168.5.100;
   option routers 192.168.5.254;
}
next-server 192.168.5.254; //指向tftp服務器
filename="pxelinux.0";//tftp根目錄的相對路徑
# service dhcpd start
# mkdir /var/ftp/pub/centos6
# mount /dev/cdrom /var/ftp/pub/centos6
# service vsftpd start
# cp /var/ftp/pub/centos/p_w_picpaths/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
# cp /var/ftp/pub/centos/isolinux/{boot.msg,vesamenu.c32,splash.jpg} /var/lib/tftpboot/
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
# chkconfig tftp on
# service xinetd start
# mkdir /var/lib/tftpboot/pxelinux.cfg
# cp /var/ftp/pub/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
# mkdir /var/ftp/pub/kickstart
# yum -y install system-config-kickstart
# system-config--kickstart

121829606.jpg

121830412.jpg

121830482.jpg


其他按需配置

121852445.jpg

121853394.jpg

# vim anaconda-ks.cfg
複製如下內容到ks.cfg並取消註釋
clearpart --all
#part /boot --fstype=ext4 --size=200
#part pv.008002 --size=61440
#volgroup vg0 --pesize=8192 pv.008002
#logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480
#logvol swap --name=swap --vgname=vg0 --size=2048
#logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240
#logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480
# mv ks.cfg /var/ftp/pub/kickstart
# vim /var/lib/tftpboot/pxelinux.cfg/default
label linux
 menu label ^Install or upgrade an existing system
 menu default
 kernel vmlinuz
 append initrd=initrd.img ks=ftp://192.168.5.254/pub/kickstart/ks.cfg



問題:

121913682.jpg

121914797.jpg


解決辦法,將內網設置爲vmnet3+

121930736.jpg


仍然有問題:


121939845.jpg



解決辦法:


ftp://172.16.5.11/pub/centos6-x86_64/是配置的yum源,發現ftp服務啓動後,下面什麼都沒有。很詭異的問題,這時只有換一臺虛擬機或者將yumcp出來,不要再使用掛載光盤的方式了。


122003499.jpg


2、Cobbler多系統自動化安裝


拓撲

142414473.jpg


Cobbler 能夠用來快速創建 Linux 網絡安裝環境,它已將 Linux 網絡安裝的技術門檻,從大專以上文化水平,成功下降到初中如下,連補鞋匠都能學會。


# yum -y install cobbler httpd cobbler-web debmirror pykickstart
# service cobblerd start
# cobbler check
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
 File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 184, in check_setup
  s.ping()
 File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
  return self.__send(self.__name, args)
 File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
  verbose=self.__verbose
 File "/usr/lib64/python2.6/xmlrpclib.py", line 1235, in request
  self.send_content(h, request_body)
 File "/usr/lib64/python2.6/xmlrpclib.py", line 1349, in send_content
  connection.endheaders()
 File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
  self._send_output()
 File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
  self.send(msg)
 File "/usr/lib64/python2.6/httplib.py", line 739, in send
  self.connect()
 File "/usr/lib64/python2.6/httplib.py", line 720, in connect
  self.timeout)
 File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
  raise error, msg
error: [Errno 111] Connection refused

# service httpd start
# service cobblerd restart


# 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.
///etc/cobbler/settings指定的server不能是localhost,server應該是向外提供服務的地址
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.
//next_server應該是tftp服務器的地址
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.
//缺乏bootloader
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
//啓動rsync
5 : comment 'dists' on /etc/debmirror.conf for proper debian support
//註釋掉dists
6 : comment 'arches' on /etc/debmirror.conf for proper debian support
//註釋掉arches
7 : 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
//須要將cobbler中提供的默認密碼改爲自定義密碼
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
//cobbler支持電源管理,要想使用就裝上cman和fence-agents
Restart cobblerd and then run 'cobbler sync' to apply changes.
//配置完後,重啓cobbler,執行cobbler sync


# cd /etc/cobbler
# vim settings
next_server: 192.168.5.254 # 本身內網網卡的ip,向外提供cobbler服務的ip
server: 192.168.5.254


能夠上網就

# cobbler get-loaders


不能上網,只能


# yum -y install syslinux
# cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
# cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
# chkconfig rsync on
# vim /etc/debmirrors.conf
#@dists="sid";
#@arches="i386";
# openssl passwd -1 -salt 'openssl rand -hex 4'
Password:
$1$openssl $olTLkVxUpXg/ttaF7o3n1/
# vim /etc/cobbler/settings
default_password_crypted: "$1$openssl $olTLkVxUpXg/ttaF7o3n1/"
# yum -y install cman fence-agents
# service cobbler restart



手動管理dhcp


# yum -y install dhcp
# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample ./dhcpd.conf
# vim dhcpd.conf
option domain-name "qiufengsong.com";
option domain-name-servers 192.168.5.254,172.16.0.1;
default-lease-time 33600;
max-lease-time 37200;
log-facility local7;
subnet 192.168.5.0 netmask 255.255.255.0 {
   range 192.168.5.10 192.168.5.100;
   option routers 192.168.5.254;
}
next-server 192.168.5.254;
filename "pxelinux.0";

確保網卡ip已經配好

# service dhcpd start

tftp已經安裝,無需再次安裝

# mount /dev/cdrom /mnt
# cobbler import --name='rhel-6.4-x86-64' --path=/mnt # 導入yum源,時間會有點長
# ls /var/www
cgi-bin cobbler cobbler_webui_content error html icons

//說明cobbler自動進行了重定向,咱們在瀏覽器中就能夠看到導入的內容。


122021183.jpg


導入完成提示

# cobbler import --name='rhel-6.4-x86-64' --path=/mnt
task started: 2013-10-12_022749_import
task started (id=Media import, time=Sat Oct 12 02:27:49 2013)
Found a redhat compatible signature: Packages
adding distros
creating new distro: rhel-6.4-64-i386
creating new profile: rhel-6.4-64-i386
associating repos
traversing distro rhel-6.4-64-i386
descent into /var/www/cobbler/ks_mirror/rhel-6.4-x86-64
processing repo at : /var/www/cobbler/ks_mirror/rhel-6.4-x86-64
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-6.4-x86-64
looking for /var/www/cobbler/ks_mirror/rhel-6.4-x86-64/repodata/*comps*.xml
running: createrepo -c cache -s sha --groupfile /var/www/cobbler/ks_mirror/rhel-6.4-x86-64/repodata/2727fcb43fbe4c1a3588992af8c19e4d97167aee2f6088959221fc285cab6f72-c6-x86_64-comps.xml /var/www/cobbler/ks_mirror/rhel-6.4-x86-64
received on stdout: Spawning worker 0 with 3916 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
received on stderr:
associating kickstarts
*** TASK COMPLETE ***



自定義一個kickstart文件

# vim /root/rhel-6.4-x86-64.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.5.254/cobbler/ks_mirror/rhel-6.4-x86-64/"
# Root password
rootpw --iscrypted $1$iRHppr42$VMesh73wBqhUTjKp6OYOD.
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info --host=172.16.0.1
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part pv.008 --size=61440
volgroup vg0 --pesize=8192 pv.008
logvol / --fstype=ext4 --name=root --vgname=vg0 --size=20480
logvol swap --name=swap --vgname=vg0 --size=2048
logvol /usr --fstype=ext4 --name=usr --vgname=vg0 --size=10240
logvol /var --fstype=ext4 --name=var --vgname=vg0 --size=20480
repo --name="Fedora EPEL" --baseurl=http://172.16.0.1/fedora-epel/6/x86_64/ --cost=1000
%post
sed -i '1,$s@id:[0-9]:initdefault:@id:3:initdefault:@g' /etc/inittab
%end
%packages
@base
@basic-desktop
@chinese-support
@client-mgmt-tools
@core
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@legacy-x
@network-file-system-client
@perl-runtime
@remote-desktop-clients
@x11
puppet
%end

# cobbler profile add --name="rhel-x86.64-basic" --distro=rhel-6.4-64-i386
--kickstart=/root/rhel-6.4-x86-64.cfg
# cobbler profile list
  rhel-6.4-64-i386
  rhel-x86.64-basic
# cobbler sync


以前tftp服務沒啓動,手動啓動


# service xinetd start


啓動一個虛擬機安裝試驗

122039444.jpg

122039542.jpg

選擇第二個耐心等待。。。


122052976.jpg



檢查發現kickstart文件中多了這麼一行,刪除便可

repo --name="Fedora EPEL" --baseurl=http://172.16.0.1/fedora-epel/6/x86_64/ --cost=1000


122319787.jpg

122222951.jpg


好了,等待rpm包裝完了就能夠啓動了。

系統啓動界面


122222742.jpg




一個最小化安裝的anaconda文件

# cat anaconda-ks.cfg | grep -v ^$
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto static --ip 172.16.5.14 --netmask 255.255.0.0 --noipv6 --hostname www.qiufengsong.com
rootpw  --iscrypted $6$iOy2cKshLSXNLROp$VD9oMS4vybDKPrjgyCbluaLMkhpnMPNZtZxLc470WIqGcddJQcNmV9EBC.hY/8D.1Qfl1tfjf9KkT617OFSTn1
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Taipei
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none
#part /boot --fstype=ext4 --size=200
#part pv.008002 --size=80200
#volgroup vg0 --pesize=4096 pv.008002
#logvol /usr --fstype=ext4 --name=LogVol00 --vgname=vg0 --size=20196
#logvol /var --fstype=ext4 --name=LogVol01 --vgname=vg0 --size=20000
#logvol / --fstype=ext4 --name=LogVol02 --vgname=vg0 --size=20000
#logvol /usr/local --fstype=ext4 --name=LogVol03 --vgname=vg0 --size=20000
repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100
%packages
@core
@server-policy
%end
相關文章
相關標籤/搜索