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沒有配置信息,所以之際複製一份模板:
安裝dhcp:yum -y install dhcp
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
首先修改配置文件:
range ip:地址池配置範圍
option routers:路由網關
next-server:告訴dhcp,tftp服務器地址
filename:請求獲取的文件
2.準備鏡像資源,本機直接掛載光盤資源。
mount -r /dev/cdrom /mnt
在images和isolinux目錄裏面複製以下文件:
複製:
[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.新建虛擬機
網絡模式爲dhcp主機地址段:ok完成pxe
3.創建文件樹
[root@localhost ~]# mkdir /var/www/html/centos6
將光盤文件卸載,並掛載到
[root@localhost ~]# mount -r /dev/cdrom /var/www/html/centos6/
地址填寫爲:http://10.0.10.1/centos6 也就是管盤文件掛載的地方
至此已經完成。可以安裝了。
2.cobbler
1.Cobbler 概述
Cobbler由python語言開發,是對PXE和Kickstart以及DHCP的封裝。融合很多特性,提供了CLI和Web的管理形式。更加方便的實行網絡安裝。同時,Cobbler也提供了API接口,使用其它語言也很容易做擴展。它不緊可以安裝物理機,同時也支持kvm、xen虛擬化、Guest OS的安裝。更多的是它還能結合Puppet等集中化管理軟件,實現自動化的管理。
下面我們來簡單的說明一下,
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
啓動cobbler,httpd,tftp,dhcp等程序。
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
6,7)註釋掉一下兩行/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 images 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 images 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
將製作好的文件保存在本機上
將文件導入到以下地方並且添加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
測試完成,已經可以自動化安裝了。
3.cobbler web界面
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
[root@localhost cobbler]# cobbler sync [root@localhost cobbler]# service httpd restart [root@localhost cobbler]# service cobblerd restart
測試已經可以登錄了:
創建一個:
執行cobbler sync:發現已經成功:
注意:
(1)dhcp服務定義filename
filename"pxelinux.0"
(2)/etc/cobbler/settings
manage_dhcp:0
manage_tftpd:0
(3)使用cobbler import可直接導致光盤中安裝樹,會自動生成相應的distro及profile
生成的profile會使用默認的ks文件/var/lib/cobbler/kickstarts/default.ks文件
(4)可自定義kicsktart文件,而後新建profile
(5)cobbler_web 2.6中使用htdigest的認證方式,添加用戶
htdigest/etc/cobbler/users.digest "Cobbler" cobbler