一、PXE:
Preboot Excution Environment預(yù)啟動(dòng)執(zhí)行環(huán)境鞍帝,由intel公司研發(fā)
pxe工作模式:基于C/S的網(wǎng)絡(luò)模式脆炎,支持遠(yuǎn)程主機(jī)通過網(wǎng)絡(luò)從遠(yuǎn)端服務(wù)器下載鏡像窑多,并由此支持通過網(wǎng)絡(luò)啟動(dòng)損傷系統(tǒng)
pxe技術(shù)的實(shí)現(xiàn)流程:
1.客戶端的網(wǎng)卡要支持網(wǎng)絡(luò)引導(dǎo)機(jī)制豆励;如果有操作系統(tǒng)的話,應(yīng)該調(diào)整為第一引導(dǎo)設(shè)備统诺;在主機(jī)被喚醒之后歪脏,開始加載網(wǎng)絡(luò)引導(dǎo)應(yīng)用時(shí),此網(wǎng)卡會(huì)通過在本地局域網(wǎng)中廣播一個(gè)rarp協(xié)議粮呢,第一步獲得一個(gè)ip地址婿失;
2.獲得ip地址的同時(shí)還會(huì)從dhcp那里獲得引導(dǎo)文件名稱和文件服務(wù)器地址钞艇;隨后會(huì)去找文件服務(wù)器主機(jī),加載對(duì)應(yīng)的文件豪硅,所需要的文件加載完成后哩照,在內(nèi)存中展開,而后基于此文件懒浮,可以實(shí)現(xiàn)去加載一個(gè)內(nèi)核文件飘弧,此內(nèi)核文件也一樣通過 tftp文件服務(wù)器獲取,內(nèi)核通常依賴于initrd虛根來完成對(duì)于真實(shí)根所在設(shè)備的驅(qū)動(dòng)加載砚著;
3.加載完成后眯牧,這個(gè)內(nèi)核文件通常是專用于為系統(tǒng)安裝所設(shè)定的,因此赖草,如果配置了網(wǎng)絡(luò)屬性,這個(gè)內(nèi)核文件還需要基于網(wǎng)絡(luò)配置在內(nèi)核上的ip地址剪个,基于網(wǎng)絡(luò)把自己扮演成某種協(xié)議的客戶端秧骑,加載一個(gè)能夠啟動(dòng)安裝程序的程序包,在本地完成安裝并啟動(dòng)這個(gè)應(yīng)用程序扣囊,而此程序在已經(jīng)不再tftp文件服務(wù)器上面乎折;
4.網(wǎng)絡(luò)引導(dǎo)安裝方式中,依賴于網(wǎng)絡(luò)上應(yīng)該存在一個(gè)基礎(chǔ)程序包鏡像倉庫侵歇,因此骂澄,此時(shí)還依賴于外部有一個(gè)基于ftp或http再或者nfs服務(wù)所提供的yum倉庫;還要通過這個(gè)yum倉庫加載安裝程序惕虑,以及安裝程序啟動(dòng)完成后坟冲,很可能要讀取kickstart文件,可以根據(jù)kickstart文件內(nèi)容溃蔫,解決依賴關(guān)系以后健提,基于這個(gè)yum倉庫,完成后續(xù)的所有安裝過程伟叛;
- 因此私痹,對(duì)于centos系統(tǒng)主機(jī),整個(gè)pxe技術(shù)大概要依賴以上所提到的服務(wù)统刮,dhcp服務(wù)紊遵、tftp服務(wù)、能夠提供yum倉庫的服務(wù)侥蒙;還要提供:kickstart文件(如果不想使用自動(dòng)化可以不用提供此文件)暗膜。
配置示例:
1.dhcp server:
[root@server1 ~]# yum install dhcp -y
[root@server1 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? yes
# 在打開的dhcpd.conf配置文件中添加如下內(nèi)空
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.20 192.168.1.30;
option routers 192.168.1.255;
filename "pxelinux.0";
next-server 192.168.1.10;
}
[root@server1 ~]# systemctl start dhcpd
[root@server1 ~]# ss -unl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 *:67 *:*
UNCONN 0 0 *%virbr0:67 *:*
#默認(rèn)端口號(hào)為67/udp
# 至此dhcp啟動(dòng)成功,添加開機(jī)自動(dòng)啟動(dòng)
[root@server1 ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@server1 ~]# systemctl is-enabled dhcpd
enabled
- tftp-server
[root@server1 ~]# yum install tftp tftp-server -y
[root@server1 ~]# systemctl start tftp
[root@server1 ~]# ss -unl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 *:67 *:*
UNCONN 0 0 *%virbr0:67 *:*
UNCONN 0 0 :::69 :::*
# tftp監(jiān)聽在69/udp端口辉哥,至此tftp-server服務(wù)啟動(dòng)桦山,默認(rèn)工作目錄為:
/var/lib/tftpboot/
[root@server1 ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@server1 ~]# systemctl is-enabled tftp
indirect
- vsftpd server
此處使用vsftpd服務(wù)來提供yum源訪問
[root@server1 ~]# yum install vsftpd -y
[root@server1 ~]# systemctl start vsftpd
[root@server1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
...
LISTEN 0 32 :::21 :::*
# vsftpd服務(wù)監(jiān)聽在21/tcp端口
# 提供光盤鏡像里的yum源訪問路徑
[root@server1 ~]# mkdir /var/ftp/pub/centos/7 -pv
mkdir: created directory ‘/var/ftp/pub/centos’
mkdir: created directory ‘/var/ftp/pub/centos/7’
[root@server1 ~]# mount -r /dev/sr0 /var/ftp/pub/centos/7
[root@server1 ~]# ls /var/ftp/pub/centos/7/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
# 提供一個(gè)kickstart文件放在/var/tftp/pub/kickstart/目錄下
# 此處舉例的kickstart文件就拿本地的anaconda-ks作示范
[root@server1 ~]# mkdir /var/ftp/pub/kickstart
[root@server1 ~]# cp anaconda-ks.cfg /var/ftp/pub/kickstart/
[root@server1 ~]# cd /var/ftp/pub/kickstart/
[root@server1 kickstart]# ls
anaconda-ks.cfg
[root@server1 kickstart]# mv anaconda-ks.cfg centos7-ks.cfg
[root@server1 kickstart]# ls
centos7-ks.cfg
[root@server1 kickstart]# chmod 644 centos7-ks.cfg
- 安裝系統(tǒng)需要的內(nèi)核等文件攒射,放在tftp服務(wù)工作目錄中
[root@server1 kickstart]# yum install syslinux -y
[root@server1 kickstart]# cd
[root@server1 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@server1 ~]# cp /usr/share/syslinux/{memdisk,mboot.c32,chain.c32,menu.c32} /var/lib/tftpboot/
[root@server1 ~]# cp /var/ftp/pub/centos/7/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
# 提供目錄,創(chuàng)建專門用來引導(dǎo)時(shí)顯示的菜單默認(rèn)文件:默認(rèn)配置要放pxelinux.cfg的目錄恒水,文件名為default
[root@server1 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@server1 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 30
MENU TITLE CentOS 7 PXE Menu
LABEL linux
MENU LABEL Install Centos 7 x86_64
KERNEL vmlinuz
APPEND initrd=initrd.img ks=ftp://192.168.1.10/pub/kickstart/centos7-ks.cfg inst.repo=ftp://192.168.1.10/pub/centos/7
# 關(guān)閉防火墻和selinux
[root@server1 ~]# iptables -F
[root@server1 ~]# setenforce 0
[root@server1 ~]# getenforce
Permissive
-
創(chuàng)建一個(gè)新的虛擬機(jī)以網(wǎng)絡(luò)自動(dòng)安裝系統(tǒng)測(cè)試
menu.png
至此自動(dòng)安裝開始PXE測(cè)試通過
kickstart文件內(nèi)容附錄如下:
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url="ftp://192.168.1.10/pub/centos/7"
# Use graphical install
text
firewall --disabled
selinux --disabled
reboot
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
timezone Asia/Shanghai --isUtc
# Network information
network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$CMUBzCualheXycom$I1OADgCKcXi7lK9LKgqt.efENmylM.09mCt8.aesLmsQJ8uLYgu2Ck9G.tarugXP73TN4rFxQVVsAdIU8yN/V/
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=inspur --password=$6$bx479ICdaF3SObqw$2F9YqiKtNp/SI5wPc.QJZggrWEhIfcXSbE1t74k222jaALrna.mqkH7PfWo.19mzCGjHrO1WwP1MXMDGZIrb7/ --iscrypted --gecos="inspur"
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
zerombr
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=1024
part swap --fstype="swap" --ondisk=sda --size=2049
part /home --fstype="xfs" --ondisk=sda --size=10240
part pv.254 --fstype="lvmpv" --ondisk=sda --size=20484
volgroup centos --pesize=4096 pv.254
logvol / --fstype="xfs" --size=20480 --name=root --vgname=centos
%packages
@base
@core
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@x11
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
二会放、Cobbler
快速網(wǎng)絡(luò)安裝linux操作系統(tǒng)的服務(wù),支持多種的linux發(fā)行版钉凌,也可以支持網(wǎng)絡(luò)安裝windows
- Cobbler是PXE的二次封裝咧最,將多種參數(shù)封裝到一個(gè)菜單;是用python語言編寫
Cobbler的工作流程:
- clinet裸機(jī)配置了從網(wǎng)絡(luò)啟動(dòng)后御雕,開機(jī)后會(huì)廣播包請(qǐng)求DHCP服務(wù)器(cobbler server)發(fā)送其分配好的一個(gè)ip
- DHCP收到請(qǐng)求后發(fā)送responese矢沿,包括其ip
- client拿到ip后再向cobbler server發(fā)送請(qǐng)求OS引導(dǎo)文件的請(qǐng)求
- cobbler server告訴client裸機(jī)OS引導(dǎo)文件的名字和TFTP server的ip和port
- client通過上面告知的tftp server地址通信,下載引導(dǎo)文件
- client執(zhí)行該引導(dǎo)文件酸纲,確定加載的信息捣鲸,選擇要按住的os,期間會(huì)想cobbler server請(qǐng)求kickstart文件和os image
- cobbler server發(fā)送請(qǐng)求的kickstart和os image
- client加載kickstart文件
- client接收os image闽坡,安裝該 os image
cobbler安裝
cobbler基于EPEL源栽惶,需要先配置好epel的yum源;cobbler服務(wù)集成:PXE疾嗅,DHCP外厂,rsync,Http代承,DNS汁蝶,Kickstart,IPMI電源管理......
一论悴、安裝:
[root@server1 ~]# yum install cobbler cobbler-web pykickstart debmirror
[root@server1 ~]# yum install cobbler cobbler-web pykickstart debmirror
[root@server1 ~]# systemctl start httpd cobblerd
[root@server1 ~]# cobbler check #檢查存在的問題
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.
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.
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.
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : comment 'dists' on /etc/debmirror.conf for proper debian support
6 : comment 'arches' on /etc/debmirror.conf for proper debian support
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
8 : 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掖棉、修改/etc/cobbler/settings文件中的server參數(shù)的值為提供cobbler服務(wù)的主機(jī)相應(yīng)的IP地址或主機(jī)名,如192.168.1.12膀估;
2啊片、修改/etccobbler/settings文件中的next_server參數(shù)的值為提供PXE服務(wù)的主機(jī)相應(yīng)的IP地址,如192.168.1.13玖像;
3紫谷、如果當(dāng)前節(jié)點(diǎn)可以訪問互聯(lián)網(wǎng),執(zhí)行“cobbler get-loaders”命令即可捐寥;否則笤昨,需要安裝syslinux程序包,而后復(fù)制/usr/share/syslinux/{pxelinux.0,memu.c32}等文件至/var/lib/cobbler/loaders/目錄中握恳;
4瞒窒、執(zhí)行“chkconfig rsync on”命令即可;
5乡洼、注釋/etc/debmirror.conf文件中的“@dists="sid"崇裁;”一行匕坯;
7、執(zhí)行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密碼拔稳,并用其替換/etc/cobbler/settings文件中default_password_crypted參數(shù)的值葛峻;
8、執(zhí)行“yum install cman fence-agents”命令安裝相應(yīng)的程序包即可巴比;
接著重啟cobblerd术奖,而后執(zhí)行“cobbler sync”同步新的配置至cobbler。
二轻绞、配置及啟動(dòng)cobbler所依賴的各服務(wù)
- cobbler的運(yùn)行依賴于dhcp采记、tftp、rsync及dns服務(wù)政勃。其中dhcp可由dhcpd(isc)提供唧龄,也可由dnsmasq提供;tftp可由tftp-server程序包提供奸远,也可由cobbler自帶的tftp功能提供选侨;rsync由rsync程序包提供;dns可由bind提供然走,也可由dnsmasq提供。
- cobbler可自行管理這些服務(wù)中的部分甚至是全部戏挡,但需要配置/etc/cobbler/settings文件中的“manage_dhcp”芍瑞、“manage_tftpd”、“manage_rsync”和“manage_dns”分別進(jìn)行定義褐墅。另外拆檬,由于每種服務(wù)都有著不同的實(shí)現(xiàn)方式,如若需要進(jìn)行自定義妥凳,需要通過修改/etc/cobbler/modules.conf配置文件中各服務(wù)的模塊參數(shù)的值來實(shí)現(xiàn)竟贯。
本文采用了獨(dú)立管理的方式,即不通過cobbler來管理這些服務(wù)
- 配置dhcp服務(wù)
定義好所需的“subnet”及其它參數(shù)或選項(xiàng)逝钥,而后啟動(dòng)dhcpd守護(hù)進(jìn)程即可屑那。本示例中所用的dhcpd的配置如下所示:
option domain-name "magedu.com";
option domain-name-servers 192.168.10.254,172.16.0.1;
default-lease-time 43200;
max-lease-time 86400;
log-facility local7;
subnet 172.16.0.0 netmask 255.255.0.0 {
range 172.16.100.121 172.16.200;
option routers 172.16.100.10;
}
next-server 172.16.100.10;
filename="pxelinux.0";
接著使用“service dhcpd start
”啟動(dòng)服務(wù)即可
- 配置tftp服務(wù)
# chkconfig tftp on
# service xinetd restart
三、配置cobbler
cobbler的各主要組件間的關(guān)系如下圖所示艘款。
- 管理distro
使cobbler變得可用的第一步為定義distro持际,其可以通過為其指定外部的安裝引導(dǎo)內(nèi)核及ramdisk文件的方式實(shí)現(xiàn)。而如果已經(jīng)有完整的系統(tǒng)安裝樹(如 CentOS6的安裝鏡像)則推薦使用import直接導(dǎo)入的方式進(jìn)行哗咆。
- 例如蜘欲,對(duì)于已經(jīng)掛載至/media/cdrom目錄的CentOS 6.5 x86_64的安裝鏡像,則可以使用類似如下命令進(jìn)行導(dǎo)入
cobbler import --name=centos-6.5-x86_64 --path=/media/cdrom
- 可使用“
cobbler distro list
”列出所有的distro - 如果有kickstart文件晌柬,也可以使用“
--kickstart=/path/to/kickstart_file
”進(jìn)行導(dǎo)入姥份,因此import會(huì)自動(dòng)為導(dǎo)入的distro生成一個(gè)profile郭脂。
- 管理profile
cobbler使用profile來為特定的需求類別提供所需要安裝配置,即在distro的基礎(chǔ)上通過提供kickstart文件來生成一個(gè)特定的系統(tǒng)安裝配置澈歉。distro的profile可以出現(xiàn)在PXE的引導(dǎo)菜單中作為安裝的選擇之一展鸡。
因此,如果需要為前面創(chuàng)建的centos06.5-x86_64這個(gè)distro提供一個(gè)可引導(dǎo)安裝條目闷祥,其用到的kickstart文件為/tmp/centos-6.5-x86_64.cfg(只提供了最基本的程序包)娱颊,則可通過如下命令實(shí)現(xiàn)。
cobbler profile add --name=centos-6.5-x86_64-basic --distro=centos-6.5-x86_64 --kickstart=/tmp/centos-6.5-x86_64.cfg
可使用“cobbler profile list
”查看已經(jīng)創(chuàng)建的profile凯砍。
四箱硕、使用cobbler_web - 配置cobbler_web的認(rèn)證功能
cobbler_web支持多種認(rèn)證方式,如authn_configfile悟衩、authn_ldap或authn_pam等剧罩,默認(rèn)為authn_denyall,即拒絕所有用戶登錄座泳。下面說明兩種能認(rèn)證用戶登錄cobbler_web的方式惠昔。
使用authn_pam模塊認(rèn)證cobbler_web用戶
首先修改modules中[authentication]段的module參數(shù)的值為authn_pam。
接著添加系統(tǒng)用戶挑势,用戶名和密碼按需設(shè)定即可镇防,例如下面的命令所示。
# useradd cblradmin
# echo 'cblrpass' | passwd --stdin cblradmin
而后將cblradmin用戶添加至cobbler_web的admin組中潮饱。修改/etc/cobbler/users.conf文件来氧,將cblradmin用戶名添加為admin參數(shù)的值即可,如下所示香拉。
[admins] admin = "cblradmin"
最后重啟cobblerd服務(wù)啦扬,通過http://YOU_COBBLERD_IP/cobbler_web訪問即可。
- 使用authn_configfile模塊認(rèn)證cobbler_web用戶
首先修改modules.conf中[authentication]段的module參數(shù)的值為authn_configfile凫碌。
接著創(chuàng)建其認(rèn)證的文件/etc/cobbler/users.digest扑毡,并添加所需的用戶即可。需要注意的是盛险,添加第一個(gè)用戶時(shí)瞄摊,需要為htdigest命令使用“-c”選項(xiàng),后續(xù)添加其他用戶不能再使用苦掘;另外泉褐,cobbler_web的realm只能為Cobbler。如下所示鸟蜡。
# htdigest -c /etc/cobbler/users.digest Cobbler cblradmin
最后重啟cobblerd服務(wù)膜赃,通過http://YOU_COBBLERD_IP/cobbler_web訪問即可。