http://www.yaukb.com/2011/12/pxe/
一、PXE的介绍
a.组成组件:
pxe:dhcp+tftp+(ftp/nfs/http)+kickstart(%post)+dns
dhcp –客户机可以获取地址,告诉客户机找到安装服务器以及要查找的文件名
tftp –快速传输安装文件,使用UDP端口69,用于客户端启动时的小系统
ftp/nfs/http –传输安装树文件
kickstart –生成安装配置文件(模板)
%post:安装完成后加载初始化脚本
DNS:设置主机名,依据IP反查主机名
b.帮助文件:
#yum install system-config-netboot –安装此包,tftp-server、xinetd也会一起安装好。
#system-config-netboot –运行此命令可以打开pxe的图形窗口,选择帮助进行文档查看或直接到下面地址进行查看文档帮助:
file:///usr/share/doc/system-config-netboot-0.1.45.1/s1-netboot-tftp.html
c.客户机启动的流程
client(netboot)->dhcpd(next-server/filename)–>tftp(pxelinux.0/default)–>ks.cfg–>
二、配置流程
1.DHCP:服务器一定要设置为固定IP地址
#yum -y install dhcp –安装软件
#vim /etc/dhcpd.conf –修改配置文件
ddns-update-style interim;
ignore client-updates;
option domain-name "yaukb.com"; –定义域名
option domain-name-servers 172.16.0.1; –域名服务器地址
option time-offset -18000; # Eastern Standard Time
default-lease-time 21600;
max-lease-time 43200;
subnet 172.16.0.0 netmask 255.255.255.0 {
# — default gateway
option routers 172.16.0.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 172.16.0.128 172.16.0.254; --地址池
# we want the nameserver to appear at a fixed address
next-server 172.16.0.1; –告诉客户机找到安装服务器
filename "linux-install/pxelinux.0"; –告诉客户机如何获取安装文件,默认是去/tftpboot目录下去查找
}
# service dhcpd start –开启服务
# chkconfig dhcpd on –设置开机启动
2.dns:设置主机名,依据IP反查主机名,客户机安装好后可以自动设置对应的主机名
# yum -y install bind caching-nameserver –安装软件包
修改配置文件
#vi /etc/named.conf –修改主配置文件,开放权限(设置监听地址,可查询地址)
options {
listen-on port 53 { 127.0.0.1;any; };
allow-query { localhost; any;};
};
view localhost_resolver {
match-clients { localhost;any; };
include "/etc/named.rfc1912.zones";
};
注册区域:
#vi /etc/named.rfc1912.zones –添加两个区域(正向和反向)
zone "yaukb.com" IN {
type master;
file "yaukb.com.zone"; –定义主区域文件名
};
zone "0.16.172.in-addr.arpa" IN {
type master;
file "172.16.0.rev";
};
创建区域文件:
#vi /var/named/yaukb.com.zone –正向查询文件
$TTL 86400
@ IN SOA dns.yaukb.com. root.dns.yaukb.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS dns.yaukb.com.
dns IN A 172.16.0.1
station1 IN A 172.16.0.251
station2 IN A 172.16.0.252
station3 IN A 172.16.0.253
station4 IN A 172.16.0.254
#/var/named/172.16.0.rev –反向查询文件
$TTL 86400
@ IN SOA dns.yaukb.com. root.dns.yaukb.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS dns.yaukb.com.
1 IN PTR dns.yaukb.com.
251 IN PTR station1.yaukb.com.
252 IN PTR station2.yaukb.com.
253 IN PTR station3.yaukb.com.
254 IN PTR station4.yaukb.com.
3.tftp:
a.安装软件包:
# yum -y install system-config-netboot.noarch –一般安装此软件包后,tftp-server,xinetd包都会一起安装,同时在/tftpboot目录产生一些文件(pxelinux.0)
# yum -y install tftp-server –如没有安装,可以直接安装tftp的软件包
b.开启服务:
# chkconfig xinetd on –因tftp是依赖xinetd服务的
# chkconfig tftp on
# service xinetd restart –重启下xinetd服务
# netstat -unlp |grep :69 –检查tftp(使用69端口)是否又启动
udp 0 0 0.0.0.0:69 0.0.0.0:* 7308/xinetd
检查/tftpboot目录是否又产生需要的文件:
# pwd
/tftpboot/linux-install
# ll
总计 36
drwxr-xr-x 2 root root 4096 08-30 22:43 msgs
-rw-r–r– 1 root root 13100 2005-12-20 pxelinux.0 –这是一个小系统,pxelinux.0—是syslinux包产生的,在/usr/lib/sysconfig/目录下
drwxr-xr-x 2 root root 4096 2008-04-07 pxelinux.cfg
# ll msgs/
总计 48
-rw-r–r– 1 root root 439 2008-04-07 boot.msg –开机的显示信息、选择标签
-rw-r–r– 1 root root 668 2008-04-07 expert.msg
-rw-r–r– 1 root root 871 2008-04-07 general.msg
-rw-r–r– 1 root root 860 2008-04-07 param.msg
-rw-r–r– 1 root root 530 2008-04-07 rescue.msg
-rw-r–r– 1 root root 545 2008-04-07 snake.msg
4.ftp:
因ftp默认就是开放匿名用户下载权限的,只要安装软件和启动服务就可以了。在生产环境中最好使用实名用户,这样不是所有人从网卡启动就可以安装系统
a.安装软件包
# yum -y install vsftpd
b.启动服务
# service vsftpd start
# chkconfig vsftpd on
5.安装树部署
将光盘中的安装文件全部拷贝到ftp匿名用户访问的目录(/var/ftp/pub/)中去。
# mkdir /var/ftp/pub/RHEL5 –新建放置安装树的目录
# mkdir /var/ftp/pub/scripts –新建放置脚本的目录
# mount -o loop /tmp/dvd.iso /var/ftp/pub/RHEL5/ –将镜像文件挂载到/var/ftp/pub/RHEL5/目录
loop将光盘映像文件进行挂载
6.开机所需文件(内核、驱动、default文件)部署
# mkdir /tftpboot/linux-install/RHEL5/ –新建放置临时内核、驱动文件的目录
a.复制启动时所需要临时内核/驱动文件:
# cd /var/ftp/pub/RHEL5/images/pxeboot –进入到光盘镜像文件的/images/pxeboot目录
# cp initrd.img vmlinuz /tftpboot/linux-install/RHEL5/
b.拷贝default文件
# cd /var/ftp/pub/RHEL5/isolinux –进入到光盘镜像文件的/isolinux目录
# cp isolinux.cfg /tftpboot/linux-install/pxelinux.cfg/default –将isolinux.cfg文件拷贝到/tftpboot/linux-install/pxelinux.cfg目录,并重命名为default
c.编辑default文件,定义查找内核、驱动程序、ks.cfg文件
# vim /tftpboot/linux-install/pxelinux.cfg/default –编辑default文件,使输入关键字时启动相应的临时内核文件、加载相应的驱动、以及查找相应的ks.cfg文件
default local –默认本地启动,local为标签
prompt 1 –这是说,向用户提示输入选择,直接回车就是缺省选项了
timeout 60
display msgs/boot.msg –启动时看到的选项菜单、图形等信息
F1 msgs/boot.msg –F1-F5按键启动的相关项
F2 msgs/options.msg
F3 msgs/general.msg
F4 msgs/param.msg
F5 msgs/rescue.msg
label local –定义local标签
localboot 1
label ws
kernel RHEL5/vmlinuz –加载的临时内核文件,自动到/tftpboot/linux-install目录去找
append ksdevice=eth0 load_ramdisk=1 initrd=RHEL5/initrd.img network ks=ftp://192.168.0.3/pub/scripts/ks.cfg noipv6 –指定驱动文件、ks.cfg等,ksdevice指监听网卡,initrd指定加载的驱动,ks指定ks.cfg文件,network指网络安装;
如只指定了initrd,而没有指定ks将需要手动进行选择是哪种方式安装:FTP|HTTP|NFS|光盘|本地硬盘(method=ftp://172.16.0.1/pub/rhel5.4 来指定安装树的位置)
7.kickstart:生成ks.cfg文件
a.安装软件包:
# yum -y install system-config-kickstart –安装kickstart包
b.生成ks.cfg文件:可以先安装一台服务器,然后使用/root/anaconda-ks.cfg这个文件为模块设置ks.cfg
# system-config-kickstart –运行图形的kickstart工具,以快速生成ks.cnf文件
# vim ks.cfg
auth –useshadow –enablemd5
bootloader –location=mbr –password=123
key –skip –跳过许可证输入
text
firewall –disabled
firstboot –disable
keyboard us
lang zh_CN
logging –level=info
url –url=ftp://192.168.0.3/pub/RHEL5 –指定使用FTP方式安装以及安装树位置
network –bootproto=dhcp –device=eth0 –onboot=on
reboot
rootpw –iscrypted $1$FbQW218y$mE3lU1WlriTSIMpnTnZNS.
selinux –disabled
timezone Asia/Shanghai
install
xconfig –defaultdesktop=GNOME –depth=24 –resolution=800×600
clearpart –all –分区信息
part /boot –fstype ext3 –size=100
part pv.100000 –size=18000
part swap –size=512
volgroup vol0 –pesize=32768 pv.100000
logvol /home –fstype ext3 –name=home –vgname=vol0 –size=480
logvol / –fstype ext3 –name=root –vgname=vol0 –size=8192
%post –%post指定安装完后执行的脚本
wget ftp://172.16.0.1/pub/scripts/init.sh –下载脚本到本地
/bin/sh init.sh –执行脚本
/bin/rm -rf init.sh –执行完后,删除脚本
%packages –指定安装包
@base-x
@gnome-desktop
@chinese-support
@admin-tools
@system-tools
@text-internet
@graphical-internet
@editors
三、增加一个RHEL6.0安装标签
1.拷贝安装树
# mkdir /var/ftp/pub/RHEL6 –创建放置6.0版本的安装树目录
# mount -o loop /tmp/rhel-server-6.0-x86_64-dvd.iso /var/ftp/pub/RHEL6 –挂载镜像文件
2.创建启动时临时内核及根文件系统:
# mkdir /tftpboot/linux-install/RHEL6
# cd /var/ftp/pub/RHEL6/isolinux/ –进入到光盘镜像文件的/isolinux目录
# cp vmlinuz initrd.img /tftpboot/linux-install/RHEL6/
3.在default文件中增一个安装标签:
# vim /tftpboot/linux-install/pxelinux.cfg/default
label RHEL6
kernel RHEL6/vmlinuz
append ksdevice=eth0 load_ramdisk=1 initrd=RHEL6/initrd.img network ks=ftp://192.168.0.3/pub/scripts/ks.cfg noipv6
4.创建ks.cfg文件
最好在rhel6版本上创建ks.cfg文件;因有些地方不能与RHEL5.4兼容
四、使用pxe自带创建命令生成我们的安装环境
使用命令可以自动完成vmlinuz、initrd.img的复制,default和boot.msg文件的修改;使用自动创建将会删除手动创建的标签
先清空原来的环境:
# rm -rf RHEL5/ RHEL6/ pxelinux.cfg/default
1.使用图开界面添加一个安装标签
#system-config-netboot
只要按照提示填写相关项就可以完成
2.使用命令添加RHEL6的安装标签
# pxeos -a -i "auto install RHEL6.0 from pxe" -p FTP -D 0 -s 192.168.0.3 -L /pub/RHEL6 -Kftp://192.168.0.3/pub/scripts/ks2.cfg RHEL6.0
-a 增加
-i 注释
-p FTP|HTTP|NFS 需要大写
-D 0网络安装、1本地安装
-s 服务器地址
-L 安装目录树存放目录
-K 指定ks.cfg文件
-d 删除
-l 列出已有的标签信息
# pxeos –help |man pxeos –查看帮助
# pxeos -l
RHEL_HTTP
Description: auto install RHEL5.0 from pxe
Protocol: HTTP
isDiskless: False
Server: 172.16.0.1
Location: /RHEL5
RHEL6_FTP
Description: Use FTP auto install RHEL6.0 from pxe
Protocol: FTP
isDiskless: False
Server: 172.16.0.1
Location: /pub/RHEL6
isAnonymous: True
User:
Password:
RHEL_FTP
Description: Use FTP auto install RHEL5.0 from pxe
Protocol: FTP
isDiskless: False
Server: 172.16.0.1
Location: /pub/RHEL5
isAnonymous: True
User:
Password:
RHEL_NFS
Description: Use NFS auto install RHEL5.0 from pxe
Protocol: NFS
isDiskless: False
Server: 172.16.0.1
Location: /var/ftp/pub/RHEL5
3.使用命令添一个手工安装RHEL5的标签
# pxeos -a -i "install RHEL5.0 by yourself from pxe" -p FTP -D 0 -s 192.168.0.3 -L /pub/RHEL5 RHEL5.4_sg
五、使用httpd传输我们的安装树
a.安装软件、启动服务
# yum -y install httpd
# service httpd start
# chkconfig httpd on
b.在默认的httpd网站目录/var/www/html/放置安装树文件
# ln -s /var/ftp/pub/RHEL5/ /var/www/html/ –建立软连接
# ln -s /var/ftp/pub/RHEL6/ /var/www/html/
# ln -s /var/ftp/pub/scripts/ /var/www/html/
c.拷贝服务器启动时所需的内核、驱动,生成default文件
# pxeos -a -i "auto install RHEL6.0 from pxe" -p HTTP -D 0 -s 192.168.0.3 -L /RHEL5 -K http://172.16.0.1/scripts/ks_httpd.cfg RHEL_httpd –添加RHEL6.0的HTTP安装方式标签
d.创建ks.cfg文件
# cd /var/www/html/scripts/
# vim ks_httpd.cfg --编辑脚本
#platform=x86, AMD64, 或 Intel EM64T
# System authorization information
auth –useshadow –enablemd5
# System bootloader configuration
bootloader –location=mbr –password=123
# Partition clearing information
key –skip
clearpart –none
# Use text mode install
text
# Firewall configuration
firewall –disabled
# Run the Setup Agent on first boot
firstboot –disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Installation logging level
logging –level=info
# Use network installation
url –url=http://172.16.0.1/RHEL5
# Network information
network –bootproto=dhcp –device=eth0 –onboot=on
# Reboot after installation
reboot
#Root password
rootpw –iscrypted $1$FbQW218y$mE3lU1WlriTSIMpnTnZNS.
# SELinux configuration
selinux –disabled
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig –defaultdesktop=GNOME –depth=24 –resolution=800×600
clearpart –all
part /boot –fstype ext3 –size=100
part pv.100000 –size=18000
part swap –size=512
volgroup vol0 –pesize=32768 pv.100000
logvol /home –fstype ext3 –name=home –vgname=vol0 –size=480
logvol / –fstype ext3 –name=root –vgname=vol0 –size=8192
%packages
@base-x
@gnome-desktop
@chinese-support
@admin-tools
@system-tools
@text-internet
@graphical-internet
@editors
六、使用NFS传输安装树
a.安装软件包
#yum install nfs-utils portmap
b.开启服务
#service nfs start
#service portmap start –portmap是nfs传输数据时需要的
#chkconfig nfs on
#chkconfig portmap on
c.建立共享
#vi /etc/exports –将安装目录使用NFS分发出去
/var/ftp/pub/RHEL5 172.16.0.0/24(ro)
/var/ftp/pub/scripts 172.16.0.0/24(ro) –发布脚本存放目录
d.导入配置文件
#exportfs -rv –导入配置文件
e.添加nfs安装方式
pxeos -a -i "use NFS auto install RHEL5.4" -p NFS -s 172.16.0.1 -D 0 -L /var/ftp/pub/rhel5.4/ -K nfs:172.16.0.1:/var/ftp/pub/scripts/ks_nfs.cfg nfs_rhel5
f.创建kc.cfg文件
#platform=x86, AMD64, 或 Intel EM64T
# System authorization information
auth –useshadow –enablemd5
# System bootloader configuration
bootloader –location=mbr –password=admin,.123
key –skip
# Partition clearing information
clearpart –none
# Use text mode install
text
# Firewall configuration
firewall –disabled
# Run the Setup Agent on first boot
firstboot –disable
# System keyboard
keyboard us
# System language
lang zh_CN
# Installation logging level
logging –level=info
# Use network installation
nfs –server=172.16.0.1 –dir=/var/ftp/pub/RHEL5 –地址的指定方式跟http和ftp不同
# Network information
network –bootproto=dhcp –device=eth0 –onboot=on
# Reboot after installation
reboot
#Root password
rootpw –iscrypted $1$TnTOCh3B$wG5jVqUq7oUSr9t0SI3sQ/
# SELinux configuration
selinux –disabled
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig –defaultdesktop=GNOME –depth=24 –resolution=640×480
clearpart –linux –drives=hda
part /boot –fstype ext3 –size=100 –ondisk=hda
part pv.2 –size=0 –grow –ondisk=hda
volgroup VolGroup00 –pesize=32768 pv.2
logvol / –fstype ext3 –name=LogVol00 –vgname=VolGroup00 –size=1024 –grow
logvol swap –fstype swap –name=LogVol01 –vgname=VolGroup00 –size=512 –grow –maxsize=1024
%post
mount -t nfs 172.16.0.1:/var/ftp/pub/scripts /mnt
/bin/sh /mnt/init.sh
umount /mnt
%packages
@gnome-desktop
@development-libs
@development-tools
@system-tools
@admin-tools
@chinese-support
@graphical-internet
@text-internet
@editors