|
原理和概念: 1.1 什么是PXE 严格来说,PXE 并不是一种安装方式,而是一种引导的方式。进行 PXE 安装的必要条件是要安装的计算机中包含一个 PXE 支持的网卡(NIC),即网卡中必须要有 PXE Client。PXE (Pre-boot Execution Environment)协议使计算机可以通过网络启动。协议分为client 和 server 端,PXE client 在网卡的 ROM 中,当计算机引导时,BIOS 把 PXE client 调入内存执行,由 PXE client 将放置在远端的文件通过网络下载到本地运行。运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。DHCP 服务器用来给 PXE client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。此外,在 PXE client 的 ROM 中,已经存在了 TFTP Client。PXE Client 通过 TFTP 协议到 TFTP Server 上下载所需的文件。 1.2 什么是KickStart KickStart是一种无人职守安装方式。KickStart的工作原理是通过记录典型的安装过程中所需人工干预填写的各种参数,并生成一个名为ks.cfg的文件;在其后的安装过程中(不只局限于生成KickStart安装文件的机器)当出现要求填写参数的情况时,安装程序会首先去查找KickStart生成的文件,当找到合适的参数时,就采用找到的参数,当没有找到合适的参数时,才需要安装者手工干预。这样,如果KickStart文件涵盖了安装过程中出现的所有需要填写的参数时,安装者完全可以只告诉安装程序从何处取ks.cfg文件,然后去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中设置的重启选项来重启系统,并结束安装。 1.3 PXE + KickStart安装的条件 执行 PXE + KickStart安装需要的设备为: ? DHCP 服务器; ? TFTP 服务器; ? KickStart所生成的ks.cfg配置文件 ? 一台存放系统安装文件的服务器,如 NFS、HTTP 或 FTP 服务器。 ? 带有一个 PXE 支持网卡的将安装的主机;
部署需要一台安装好的图形界面的Centos5.5虚拟机机器。内存和机器多大都可以。Ip:192.168.1.20
现在开始部署: 1. 插入光盘,挂载光驱: [iyunv@DZ-03 ~]# mount /dev/cdrom /mnt/ mount: block device /dev/cdrom is write-protected, mounting read-only [iyunv@DZ-03 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 13G 2.8G 9.4G 23% / /dev/sda1 1.9G 41M 1.8G 3% /boot tmpfs 125M 0 125M 0% /dev/shm /dev/hdc 3.9G 3.9G 0 100% /media/CentOS_5.5_Final /dev/hdc 3.9G 3.9G 0 100% /mnt
2. 安装tftp服务器 [iyunv@DZ-03 ~]# yum -y install tftp* tftp-server [iyunv@DZ-03 ~]# vim /etc/xinetd.d/tftp #更改tftp配置文件,打开tftp服务,如下: # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = yes #把yes改成no,然后保存退出即可。 per_source = 11 cps = 100 2 flags = IPv4 }
[iyunv@DZ-03 ~]# /etc/init.d/xinetd restart #启动tftp服务,因为tftp是xinetd服务的子进程受xinetd的管辖。 Stopping xinetd: [FAILED] Starting xinetd: [ OK ]
3. 设置pex配置文件 [iyunv@DZ-03 ~]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/ #复制pex引导安装主程序。 [iyunv@DZ-03 ~]# cp /mnt/images/pxeboot/initrd.img /tftpboot/ #复制initrd.img---ramdisk文件,帮助内核可选加载硬件驱动模块。 [iyunv@DZ-03 ~]# cp /mnt/images/pxeboot/vmlinuz /tftpboot/ #复制vmlinuz内核文件。 [iyunv@DZ-03 ~]# cp /mnt/isolinux/*.msg /tftpboot/ #复制linux开机引导文件。 [iyunv@DZ-03 ~]# cp /mnt/isolinux/splash.lss /tftpboot/ #复制安装系统背景图标。 [iyunv@DZ-03 ~]# mkdir /tftpboot/pxelinux.cfg #创建引导菜单的的目录。 [iyunv@DZ-03 ~]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default #default-引导菜单,可在tftp目录下建立不同vmlinuz和initrd.img的目录组合,从而建立不同系统引导的条件。
4. 安装dhcp服务 [iyunv@DZ-03 ~]# yum -y install dhcp* [iyunv@DZ-03 ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf #拷贝dhcp模板文件到/etc/目录下命名为dhcpd.conf。 cp: overwrite `/etc/dhcpd.conf'? yes #选择yes,覆盖原配置文件。 [iyunv@DZ-03 ~]# vim /etc/dhcpd.conf #更改dhcp配置文件。
ddns-update-style interim; #dhcp支持的dns动态更新方式。 ignore client-updates; #忽略客户端DNS动态更新。
next-server 192.168.1.20; #添加:Tftp server服务器的ip地址。 filename "/pxelinux.0"; #添加:Bootstrap文件。
subnet 192.168.1.0 netmask 255.255.255.0 { #声明KickStart ip网段.
# --- default gateway option routers 192.168.1.1; #必须改成KickStart ip网段的网关地址。 option subnet-mask 255.255.255.0;
option nis-domain "domain.org"; option domain-name "domain.org"; option domain-name-servers 192.168.1.20; #必须改成KickStart ip服务器正确地址。
option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2;
range dynamic-bootp 192.168.1.100 192.168.1.254; #更改:安装完系统默认分配的客户端ip地址。 default-lease-time 21600; max-lease-time 43200;
# we want the nameserver to appear at a fixed address host ns { next-server marvin.redhat.com; hardware ethernet 12:34:56:78:AB:CD; fixed-address 207.175.42.254; } }
[iyunv@DZ-03 ~]# /etc/init.d/dhcpd restart #启动dhcpd服务器
5. 安装NFS文件系统 [iyunv@DZ-03 ~]# yum -y install nfs-* [iyunv@DZ-03 ~]# mkdir /tftpboot/ks [iyunv@DZ-03 ~]# vim /etc/exports #打开配置文件,添加如下: /mnt *(ro) /tftpboot/ks/ *(ro)
[iyunv@DZ-03 ~]# /etc/init.d/portmap restart [iyunv@DZ-03 ~]# /etc/init.d/nfs restart [iyunv@DZ-03 ~]# showmount -e localhost #检查是否加载成功 Export list for localhost: /mnt * /tftpboot/ks *
6. 安装KickStart [iyunv@DZ-03 ~]# yum -y install system-config-kickstart.noarch [iyunv@DZ-03 ~]# system-config-kickstart #开始进行图形化配置
(图一):
(图二):
(图三):备注:什么都不需要修改
(图四):
(图五):
(图六):
(图七):
(图八):
最后选保存
[iyunv@DZ-03 ~]# cp /root/ks.cfg /tftpboot/ks/ [iyunv@DZ-03 ~]# chmod 777 /tftpboot/pxelinux.cfg/default [iyunv@DZ-03 ~]# vim /tftpboot/pxelinux.cfg/default #打开配置文件,更改。 default linux #更改成ks。 prompt 1 timeout 600 #引导安装的超时时间改成6秒即可。 display boot.msg F1 boot.msg F2 options.msg F3 general.msg F4 param.msg F5 rescue.msg label linux kernel vmlinuz append initrd=initrd.img label text kernel vmlinuz append initrd=initrd.img text label ks kernel vmlinuz append ks=nfs:192.168.1.20:/tftpboot/ks/ks.cfg initrd=initrd.img #添加ks路径 append ks initrd=initrd.img #把这行用#号注释掉。 label local localboot 1 label memtest86 kernel memtest append –
1. 关闭防火墙和selinux [iyunv@DZ-03 ~]# /etc/init.d/iptables stop [iyunv@DZ-03 ~]# setenforce 0
2. 最后添加一台新的linux主机来测试,测试结果如下:
呵呵,自动化系统安装成功了。
|