PXE
CentOS 6.7:准备环境:


pxe简介:

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/winXP/win7/win8,linux等。


1.dhcp主机安装服务:


1.安装后默认dhcpd.conf没有配置信息,所以之际复制一份模板:

安装dhcpyum -y install dhcp

cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf


首先修改配置文件:


pxe 简介以及 cobbler安装配置自动化_black


range ip:地址池配置范围

option routers路由网关

next-server:告诉dhcptftp服务器地址

filename:请求获取的文件


2.准备镜像资源,本机直接挂载光盘资源。

mount -r /dev/cdrom /mnt

pxe 简介以及 cobbler安装配置自动化_black_02

p_w_picpathsisolinux目录里面复制以下文件:


复制:

[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/
[root@localhost isolinux]# cp isolinux.cfg vesamenu.c32 splash.jpg boot.msg /var/lib/tftpboot/


创建文件:

[root@localhost isolinux]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost isolinux]# cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

至此基本配置完成。


2.新建虚拟机

pxe 简介以及 cobbler安装配置自动化_black_03

网络模式为dhcp主机地址段:ok完成pxe


3.创建文件树

[root@localhost ~]# mkdir /var/www/html/centos6


将光盘文件卸载,并挂载到

[root@localhost ~]# mount -r /dev/cdrom /var/www/html/centos6/



pxe 简介以及 cobbler安装配置自动化_black_04


pxe 简介以及 cobbler安装配置自动化_color_05

地址填写为:http//10.0.10.1/centos6  也就是管盘文件挂载的地方

至此已经完成。可以安装了。


pxe 简介以及 cobbler安装配置自动化_style_06



2.cobbler

1.Cobbler 概述

Cobbler由python语言开发,是对PXE和Kickstart以及DHCP的封装。融合很多特性,提供了CLI和Web的管理形式。更加方便的实行网络安装。同时,Cobbler也提供了API接口,使用其它语言也很容易做扩展。它不紧可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。更多的是它还能结合Puppet等集中化管理软件,实现自动化的管理。


pxe 简介以及 cobbler安装配置自动化_color_07

下面我们来简单的说明一下,

Server端:

  • 第一步,启动Cobbler服务

  • 第二步,进行Cobbler错误检查,执行cobbler check命令

  • 第三步,进行配置同步,执行cobbler sync命令

  • 第四步,复制相关启动文件文件到TFTP目录中

  • 第五步,启动DHCP服务,提供地址分配

  • 第六步,DHCP服务分配IP地址

  • 第七步,TFTP传输启动文件

  • 第八步,Server端接收安装信息

  • 第九步,Server端发送ISO镜像与Kickstart文件

Client端:

  • 第一步,客户端以PXE模式启动

  • 第二步,客户端获取IP地址

  • 第三步,通过TFTP服务器获取启动文件

  • 第四步,进入Cobbler安装选择界面

  • 第五步,客户端确定加载信息

  • 第六步,根据配置信息准备安装系统

  • 第七步,加载Kickstart文件

  • 第八步,传输系统安装的其它文件

  • 第九步,进行安装系统


支持多安装树的pxe。

            PXE:yum repository, (vmlinuz+initrd.img) Distribution

                  单个系统安装:

                        特定系统:(pxeboot) vmlinuz, initrd.img

                        特定系统安装源:yum repository

 

三个核心组件:

      1.repository

               mirror

               import

       2.    distribution

       3.   profile


1.安装cobbler

需要安装epel源:wget http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm


yum安装软件:

[root@localhost ~]# yum install cobblercobbler-web pykickstart debmirror httpdsyslinux
[root@localhost ~]# yum install dhcptftp-server


启动cobblerhttpdtftpdhcp等程序。

 

tftp,httpd,dhcp,还包括DNS这些服务都可以由cobbler代为管理,也可以独立管理。这里都将这些服务设置为单独管理。



配置cobbler

[root@localhost tftpboot]# vim/etc/cobbler/settings 
 
#this is the address of the cobbler server -- as it is used
# bysystems during the install process, it must be the address
# orhostname of the system as those systems can see the server.
# ifyou have a server that appears differently to different subnets
#(dual homed, etc), you need to read the --server-override section
# ofthe manpage for how that works.
server:10.0.10.1


 

启动cobbler服务,运行cobbler check

servicecobbler start


运行check后出现如下一堆问题,下面逐个解决:

[root@localhost tftpboot]# cobbler check
The following are potential configuration items that you maywant to fix:
 
1 : 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 shouldmatch the IP of the boot server on the PXE network.
2 : SELinux is enabled. Please review the following wiki pagefor details on ensuring cobbler works correctly in your SELinux environment:
    https://github.com/cobbler/cobbler/wiki/Selinux
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 youhave installed a *recent* version of the syslinux package installed and canignore this message entirely.  Files in this directory, should you want tosupport all architectures, should include pxelinux.0, menu.c32, elilo.efi, andyaboot. The 'cobbler get-loaders' command is the easiest way to resolve theserequirements.
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : reposync is not installed, need for cobbler reposync,install/upgrade yum-utils?
6 : comment out 'dists' on /etc/debmirror.conf for properdebian support
7 : comment out 'arches' on /etc/debmirror.conf for properdebian support
8 : The default password used by the sample templates for newlyinstalled machines (default_password_crypted in /etc/cobbler/settings) is stillset to 'cobbler' and should be changed, try: "openssl passwd -1 -salt'random-phrase-here' 'your-password-here'" to generate new one
9 : 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)修改next server

# ifusing cobbler with manage_dhcp, put the IP address
# ofthe cobbler server here so that PXE booting guests can find it
# ifyou do not set this correctly, this will be manifested in TFTP open timeouts.
next_server:10.0.10.1

 

2)若仅为x86/x86_64架构的服务器提供服务,安装syslinux即可

#yum install syslinux


3)修改rsync的选项为启用:

[root@localhost tftpboot]# chkconfig rsync on

 

5)安装ksvalidator

# yum install -y pykickstart


 

67)注释掉一下两行/etc/debmirror.conf 

#@dists="sid";
#@arches="i386";


8)添加修改一个新的密码:

[root@localhost ~]# vim /etc/cobbler/settings
[root@localhost tftpboot]# openssl passwd -1 -salt 'opensslrand -hex 4'
Password: 
$1$openssl $yjM9zoJu5exGoBYrfY.9C.
[root@localhost tftpboot]# 
 
default_password_crypted: "$1$openssl$yjM9zoJu5exGoBYrfY.9C."


配置完成后

cobbler sync
service cobbler restart


检查目录已经生成:

[root@localhost tftpboot]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
boot  etc  grub  p_w_picpaths  memdisk menu.c32  ppc  pxelinux.0  pxelinux.cfg  s390x
[root@localhost tftpboot]#


挂载光盘:

[root@localhost ~]# umount /dev/cdrom 
[root@localhost ~]# mount /dev/cdrom /media/ -r

 

cobbler import 加载光盘自动生成distro,时间比较长

[root@localhost ~]# cobbler import --path=/media/--name=centos6.7-x86_64


查看已经生成:

[root@localhost ~]# cd /var/www/cobbler
[root@localhost cobbler]# ls
aux  p_w_picpaths  ks_mirror  links  localmirror pub  rendered  repo_mirror  svc


 

制作ks.cfg文件

首先安装system-config-kickstart

yum install system-config-kickstart


执行system-config-kickstart启用图形界面进行配置

 system-config-kickstart

pxe 简介以及 cobbler安装配置自动化_color_08


将制作好的文件保存在本机上

 

将文件导入到以下地方并且添加profile:

[root@localhost ~]# cp ks.cfg /var/lib/cobbler/kickstarts/
cp: overwrite `/var/lib/cobbler/kickstarts/ks.cfg'? y
[root@localhost ~]# cobbler distro list
   centos6.7-x86_64


即为某个distro提供kickstart文件来生成一个特定的系统安装配置。

[root@localhost ~]# cobbler profile add--name="centos6.-x86_64-web" --distro=centos6.7-x86_64--kickstart=/var/lib/cobbler/kickstarts/ks.cfg
[root@localhost ~]#


查看一下:

[root@localhost ~]# cobbler profile list
   centos6.6-x86_64-web
   centos6.7-x86_64
[root@localhost ~]# 
 
[root@localhost ~]# cobbler sync   ####注意每一次修改配置都要执行一下sync

pxe 简介以及 cobbler安装配置自动化_color_09

测试完成,已经可以自动化安装了。


3.cobbler web界面

pxe 简介以及 cobbler安装配置自动化_color_10

cobbler_web支持多种认证方式,如authn_configfile、authn_ldap或authn_pam等,这里使用authn_pam模块实现认证。

 
[root@node1 ~]# vim/etc/cobbler/modules.conf
[authentication]
module = authn_pam


添加系统用户:

[root@node1 ~]# useradd baby
[root@node1 ~]# echo"baby" | passwd --stdin baby
Changing password for user baby.
passwd: all authentication tokensupdated successfully.


添加该系统用户至/etc/cobbler/users.conf文件

 

[root@node1 ~]# vim/etc/cobbler/users.conf
[admins]
admin = "baby"


配置完成重启cobbler服务:

 

[root@node1 ~]# service cobblerdrestart
Stopping cobblerdaemon:                                  [  OK  ]
Starting cobblerdaemon:                                  [  OK  ]


如果用默认验证方式:

需要[root@localhost cobbler]#  htdigest/etc/cobbler/users.digest "Cobbler" cobbler

Adding user cobbler in realm cobbler
New password: 
Re-type new password:

[root@localhost kickstarts]# 创建digest文件:


查看已经文件已经生成:users.digest


pxe 简介以及 cobbler安装配置自动化_color_11

[root@localhost cobbler]# cobbler sync
[root@localhost cobbler]# service httpd restart
[root@localhost cobbler]# service cobblerd restart


测试已经可以登录了:

 

创建一个:

pxe 简介以及 cobbler安装配置自动化_color_12


执行cobbler sync:发现已经成功:

pxe 简介以及 cobbler安装配置自动化_color_13


注意:

                  (1)dhcp服务定义filename

                        filename"pxelinux.0"

 

                  (2)/etc/cobbler/settings

                        manage_dhcp:0

                        manage_tftpd:0

 

                  (3)使用cobbler import可直接导致光盘中安装树,会自动生成相应的distroprofile

                        生成的profile会使用默认的ks文件/var/lib/cobbler/kickstarts/default.ks文件

 

                  (4)可自定义kicsktart文件,而后新建profile

 

                  (5)cobbler_web 2.6中使用htdigest的认证方式,添加用户

                        htdigest/etc/cobbler/users.digest "Cobbler" cobbler