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
相关文章
相关标签/搜索