使用服务器 PXE 功能从网络安装操作系统
目的是方便集群服务器安装, 减少人力及物力开销,压缩安装系统时间, 目前多数服务器都支持 PXE 方式从服务器网卡进行引导,通过安装服务
器的 DHCP 功能分配 ip 地址, 由 tftp 软件创建引导服务器安装的引导菜单,再调用 nfs/ftp/http 方式进行安装操作系统.
此文档是使用 http 方式进行安装服务器系统.编写此文档时安装服务器使用 CenOS 5.2 x64 位操作系统.配置好了 yum 源. 其它操作系统类
似.安装步聚都是一样的.
PXE server 从网络安装操作系统需要以下几个步聚
1) 安装 DHCP 服务
2) 安装 tftp 服务
3) 安装 NFS/FTP/HTTP 服务器(从中选其一)
1 安装 dhcp 服务
[root@server1 ~] # yum install dhcp
Dhcpd 配置文件是 /etc/dhcpd.conf 文件, 可以用 /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample 这个基本样例配置文件创建/etc/dhcp
.conf , 根据你自己的需要修改你的子网和配置你的 dhcp 服务在你的网络上. 此文档使用 172.20.30.x 子网, 此文档中的配置文件内容如下:
#*****************************************
# /etc/dhcpd.conf configure file contents
#*****************************************
ddnsupdatestyle interim;
not authoritative;
option domainname "shirwa.net";
option domainnameservers 208.67.222.222, 208.67.220.220;
option subnetmask 255.255.255.0;
subnet 172.20.30.0 netmask 255.255.255.0 {
authoritative;
range 172.20.30.10 172.20.30.90;
option routers 172.20.30.254;
allow unknownclients;
allow booting
allow bootp
nextserver 172.20.30.100;
filename "pxelinux.0";
}
2 安装 tftp 服务
tftp 服务是一个通过 udp 协议来传输数据的小型 ftp, 使用 xinetd 服务来调用 tftp 服务.监听 tcp/udp 的 69 端口. 由 xinetd 来启动 tftp 服务.
编辑 /etc/xinetd.d/tftp 配置文件, 设置选项中的 disable 为 no 即可, 我的服务器上的 tftp 配置如下
#*****************************************
#tftp configure file
#*****************************************
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
}
3 创建网络安装源
我们能用三种方法用 pxe 网络引导时安装操作系统, 三种方法分别是 nfs, ftp 或者 http, 我是用的 http, 从 http 安装操作系统,
3.1 安装 http 服务
[root@server1 ~] # yum install http
3.2 编辑 http 配置文件
编辑/etc/http/conf/httpd.conf
增加发行版本的 iso 源文件目录别名
在之间加入:
Alias /iso "/www/iso/www/"
然后在之后加入对 iso 源文件目录权限设置:
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
3.3 及创建安装源目录
mkdir p /www/iso/www/centos/5.2/x64
mkdir p /www/iso/www/centos/5.2/i386
3.4 创建安装源
如果你有一个从互联网上下载下来的 dvd 或 cd 文件, 你可以将 dvd 或 cd 文件的 iso mount 到安装源目录上
我下载的是 centos5.2 的 dvd 64 及 32 们版本,使用以下命令 mount 到安装源目录上:
mount o loop /home/opensoft/iso/centos/5.2/x64/centos.iso /www/iso/www/centos/5.2/x64
mount o loop /home/opensoft/iso/centos/5.2/i386/centos.iso /www/iso/www/centos/5.2/i386
4 启动 dhcp, tftp 和 http 服务
[root@guorui ~] # /etc/init.d/dhcpd restart
[root@guorui ~] # /etc/init.d/xinetd restart
[root@guorui ~] # /etc/init.d/httpd restart
配置以上三个服务在重启后自动运行, 运行以下命令
[root@guorui ~] # chkconfig level 345 dhcpd on
[root@guorui ~] # chkconfig level 345 httpd on
[root@guorui ~]# chkconfig –level 345 xinetd on
tftpd 服务是用 xinetd 来启动,所以只设置 xinetd 服务开机启动即可
5 配置 tftp 网络启动文件
5.1 创建/tftpboot/images 上当用于当 PXE 启动安装程序时要找的启动文件目录
mkdir p /tftpboot/images
5.2 拷贝 /usr/lib/syslinux/pxelinux.0 文件到/tftpboot/目录下
[root@guorui tftpboot]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot
5.3 建立 /tftpboot/images 目录树并且拷贝 vmlinuz 和 initrd.img 文件从你的安装源目录 (/images/pxeboot/vmlinuz 和
/images/pxeboot/initrd.img
[root@guorui tftpboot]# mkdir p images/centos/5.2/i386
[root@guorui tftpboot]# mkdir p images/centos/5.2/x64
[root@guorui tftpboot]# cp /www/iso/www/centos/5.2/i386/images/pxeboot/vmlinuz
images/centos/5.2/i386/
[root@guorui tftpboot]# cp /www/iso/www/centos/5.2/i386/images/pxeboot/initrd.img images/centos/5.2/
i386/
[root@guorui tftpboot]# cp /www/iso/www/centos/5.2/x64/images/pxeboot/vmlinuz images/centos/5.2/x64/
[root@guorui tftpboot]# cp /www/iso/www/centos/5.2/x64/images/pxeboot/initrd.img
images/centos/5.2/x64/
6 创建 PXE 引导菜单
用以下步聚创建 PXE 引导菜单
6.1 拷贝 menu.c32 文件从/usr/lib/syslinux/menu.c32 到/tftpboot
[root@guorui ~]# cp /usr/lib/syslinux/menu.c32 /tftpboot
6.2 建立/tftpboot/pxelinux.cnf 目录
[root@guorui ~]# mkdir p /tftpboot/pxelinux.cnf
6.3 建立/tftpboot/pxelinux.cnf/default 配置文件, 以下是我的 default 配置文件
default menu.c32
prompt 0
timeout 300
MENU TITLE PXE Menu
LABEL CentoS 5.2 i386
MENU LABEL CentOS 5.2 i386
KERNEL images/centos/5.2/i386/vmlinuz
append vga=normal initrd=images/centos/5.2/i386/initrd.img ramdisk_size=32768 \
method=ftp://172.20.30.100/iso/centos/5.2/i386/
LABEL CentoS 5.2 x64
MENU LABEL CentOS 5.2 x64
KERNEL images/centos/5.2/x64/vmlinuz
append vga=normal initrd=images/centos/5.2/x64/initrd.img ramdisk_size=32768 \
method=ftp://172.20.30.100/iso/centos/5.2/x64/
6.4 tftp 服务的文件树结构看起来应该像这个样子
[root@guorui ~]# tree /tftpboot/
/tftpboot/
| images
| | centos
| | 5.2
| | ` i386
| | | initrd.img
| | ` vmlinuz
| ` 5.2
| ` x64
| | initrd.img
| ` vmlinuz
| menu.c32
| pxelinux.0
` pxelinux.cfg
` default
8 directories, 7 files
7 到此为止就可以使用这台服务器来通过 pxe 方式安装操作系统了.
注意: 有的服务器的网卡不支持新的操作系统,如华硕 RS100-X5/P12 服务器,网卡型号 Marvell Yukon 88E8056, 些网卡就不支持 CentOS 5.2
操作系统. 需要到 下载驱动模块.
阅读(1947) | 评论(1) | 转发(0) |