Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1069927
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类:

2009-12-10 11:21:42

linux下搭建pxe自动化安装环境

linux下搭建pxe自动化安装环境

作/译者:叶金荣(Email: ),来源:,转载请注明作/译者和出处,并且不能用于商业用途,违者必究。

目录:

1. 前言

现在企业采购的很多计算机都是没光驱的,怎么安装系统呢?另外,如何能快速大规模安装服务器操作系统呢,有什么好办法吗?
答案是有的,那就是本文要说的:PXE。
整个安装的过程是这样的:PXE网卡启动 => DHCP获得IP地址 => 从TFTP上下载 pxelinux.0、vmlinuz、initr.img 等 => 引导系统进入安装步骤 => 通过PEX linux 下载ks.cfg文件并跟据ks.cfg自动化安装系统 => 完成。
接下来,我们将PXE环境中的各个步骤分解开,逐一部署。

服务器环境描述:
IP:192.168.0.2
GW: 192.168.0.1
NETMASK: 255.255.255.0

2. 配置dhcpd

dhcpd的作用就是在客户端启动时,从中分配IP,便于继续后面的网络化自动安装。首先,我们需要安装 dhcp rpm包。

rpm -ivhU dhcp*rpm
[yejr@imysql.cn ~yejr]# cat /etc/dhcpd.conf
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option PXE.discovery-control code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr code 7 = ip-address;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
option vendor-class-identifier "PXEClient";
vendor-option-space PXE;
option PXE.mtftp-ip 0.0.0.0;
filename "pxelinux.0";
next-server 192.168.0.2;
}
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
ddns-updates on;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 202.106.0.20;
option time-offset 28800;
pool {
range 192.168.0.3 192.168.0.253;
default-lease-time 200;
max-lease-time 400;
allow members of "pxeclients";
}
}

其中,next-server就是指定tftp服务器的地址,filename是pxe引导文件。

3. 配置tftpd

安装rpm包,修改 xinet.d 下的 tftpd 配置文件,然后配置 tftpd 服务端环境。

[yejr@imysql.cn ~yejr]# rpm -ivhU syslinux*rpm tftp*rpm
[yejr@imysql.cn ~yejr]# mkdir -p /var/www/html/as4u7 /tftpboot/
[yejr@imysql.cn ~yejr]# mount path/as4u7_x86_64.iso -t iso9660 -o loop /var/www/html/as4u7
[yejr@imysql.cn ~yejr]# cd /var/www/html/as4u7
[yejr@imysql.cn ~yejr]# cp isolinux/vmlinuz isolinux/initrd.img /usr/lib/syslinux/pxelinux.0 /tftpboot
[yejr@imysql.cn ~yejr]# mkdir -p /tftpboot/pxelinux.cfg/
[yejr@imysql.cn ~yejr]# cat /tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 600
label linux
kernel vmlinuz
append netmask=255.255.255.0 gateway=192.168.0.2 ksdevice=eth0 initrd=initrd.img nofb text ks=
[yejr@imysql.cn ~yejr]# cat /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}

这里需要注意的是,/etc/xinetd.d/tftp 文件中的 disable 改成 no。另外,我们也可以采用其他网络方式安装,常见的有 HTTP、NFS、FTP,在这里,我们采用熟悉的 HTTP 方式。

4. 配置httpd以及pxe自动安装脚本

httpd的安装不再多说,我们只需要把 pxe 自动化配置文件放到 DocumentRoot 指定的位置下,然后根据文件中配置的参数挂载iso影响文件。在这里,我们假定 DocumentRoot 就是默认的 /var/www/html。

[yejr@imysql.cn ~yejr]# cat /var/www/html/ks.cfg
#基础设置
lang en_US
langsupport zh_HK zh_CN zh_TW --default=en_US
keyboard us
mouse
timezone Asia/Shanghai
rootpw yejr
selinux --disabled
reboot
text
install
#http安装路径
url --url
zerombr yes
auth --useshadow --enablemd5
firewall --disabled
skipx
#定制安装包
%packages --resolvedeps
@ admin-tools
@ system-tools
@ editors
@ emacs
@ compat-arch-support
@ chinese-support
@ development-tools
kernel
kernel-utils
curl
grub
sysstat
#初始化设置
%pre --interpreter /bin/sh
export PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin
DRIVER_INSTALL="`fdisk -l | grep -i '^Disk /dev/' | awk '{print $2, $3}' | sed 's/://g' | sed 's#/dev/##g' | awk 'BEGIN{ disk=""; size=0}{if(size == 0 || size > $2) {size = $2; disk = $1}}END{print disk}'`"
%post --interpreter /bin/sh
/sbin/chkconfig --level 2345 irqbalance on
/sbin/chkconfig --level 2345 psacct on
/sbin/chkconfig --level 2345 anacron off
/sbin/chkconfig --level 2345 apmd off
/sbin/chkconfig --level 2345 atd off
/sbin/chkconfig --level 2345 autofs off
/sbin/chkconfig --level 2345 gpm off
/sbin/chkconfig --level 2345 httpd off
/sbin/chkconfig --level 2345 identd off
/sbin/chkconfig --level 2345 ipchains off
/sbin/chkconfig --level 2345 iptables off
/sbin/chkconfig --level 2345 isdn off
/sbin/chkconfig --level 2345 keytable off
/sbin/chkconfig --level 2345 kudzu off
/sbin/chkconfig --level 2345 linuxconf off
/sbin/chkconfig --level 2345 lpd off
/sbin/chkconfig --level 2345 netfs off
/sbin/chkconfig --level 2345 nfslock off
/sbin/chkconfig --level 2345 pcmcia off
/sbin/chkconfig --level 2345 portmap off
/sbin/chkconfig --level 2345 random off
/sbin/chkconfig --level 2345 rawdevices off
/sbin/chkconfig --level 2345 rhnsd off
/sbin/chkconfig --level 2345 sgi_fam off
/sbin/chkconfig --level 2345 xfs off
/sbin/chkconfig --level 2345 xinetd off
/sbin/chkconfig --level 2345 ip6tables off
/sbin/chkconfig --level 2345 cups off
/sbin/chkconfig --level 2345 hpoj off
/sbin/chkconfig --level 2345 mdmpd off
/sbin/chkconfig --level 2345 firstboot off
/sbin/chkconfig --level 2345 arptables_jf off
/sbin/chkconfig --level 2345 mdmonitor off
/sbin/chkconfig --level 2345 smartd off
/sbin/chkconfig --level 2345 messagebus off
/sbin/chkconfig --level 2345 acpid off
/sbin/chkconfig --level 2345 rpcsvcgssd off
/sbin/chkconfig --level 2345 rpcgssd off
/sbin/chkconfig --level 2345 rpcidmapd off
/sbin/chkconfig --level 2345 cpuspeed off
/sbin/chkconfig --level 2345 sysstat off
mkdir -p /root/.ssh
/bin/rpm -e --nodpes mysqlclient10
/bin/rpm -e --nodpes mysql
/sbin/chkconfig sshd on

至此,所有配置已经完成,启动相关服务,然后开始测试。

[yejr@imysql.cn ~yejr]# /etc/init.d/xinetd start
[yejr@imysql.cn ~yejr]# /etc/init.d/httpd start
[yejr@imysql.cn ~yejr]# /etc/init.d/dhcpd start

下面是测试过程。

5. 测试

随便找一个支持网络启动的机器,启用pxe,然后启动。在服务器端用tcpdump监听并且查看/var/log/messages 日志文件,在dhcp或者tftp过程中,一旦有问题的话,都可以从dump或日志文件中发现问题所在。一般常见的问题是找不到对应文件,因此需要将相关 配置文件放在正确位置下。并且人工测试一下,确保可以访问。

阅读(774) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

@sky2009-12-11 09:15:25

#Generated by Kickstart Configurator #System language lang en_US #Language modules to install langsupport --default en_US en_US zh_CN.GB2312 #System keyboard keyboard us #System mouse mouse genericps/2 #System timezone timezone --utc Asia/Shanghai #Root password rootpw sinogrid #System bootloader configuration bootloader --location=mbr #Install Red Hat Linux instead of upgrade selinux --disabled reboot text install #Use FTP installation media url --url http://192.168.10.40/

@sky2009-12-10 15:28:00

#Generated by Kickstart Configurator #System language lang en_US #Language modules to install langsupport --default en_US en_US zh_CN.GB2312 #System keyboard keyboard us #System mouse mouse genericps/2 #System timezone timezone --utc Asia/Shanghai #Root password rootpw sinogrid #System bootloader configuration bootloader --location=mbr #Install Red Hat Linux instead of upgrade selinux --disabled reboot text install #Use FTP installation media url --url http://192.168.10.40/a