用CD/DVD安装操作系统不仅无聊而且消耗很长的时间,又需要在嘈杂的机房待很长时间,所以无人值守的自动化安装就很方便的解决了这个问题,目前linux环境中主要的无人值守方式有两种:PXE和cobbler,本文主要描述了PXE+KS在RHEL及ESX安装过程中的使用,有时间再补充cobbler的应用。

PXE的安装方式需要以下几个组件:

1.DHCP 用于给客户机pxe网络启动时分配IP地址,本文使用RHEL5.5中dhcp的rpm包,yum install dhcpd*

2.TFTP 一个轻量级的FTP服务器,用于存放操作系统的kernel(vmlinuz)和ramdisk(initrd.img)。本文使用RHEL5.5中tftp的rpm包,yum install tftp*

3.HTTPD(FTP或NFS),用于存放操作系统镜像文件以及ks.cfg脚本。本文使用apache。

PXE的安装过程如下:

1.目标主机通过PXE启动

2.目标主机发送一个DHCP请求

3.DHCP服务器给目标主机分配一个IP地址(可以是静态的IP也可以是动态的IP),同时告知目标主机TFTP服务器的地址

4.目标主机收到返回的信息后会联系TFTP服务器,请求DHCP服务器告知他的文件(pxelinux.0)

5.TFTP服务器会把启动目录发送给目标主机,目标主机按照需求执行不同的启动程序

6.PXELINUX会在TFTP服务器上查找配置文件(默认的配置文件名为default),然后根据配置文件启动相应的kernel,在本例中将会加载kernel(vmlinuz)和ramdisk(initrd.img)

7.目标主机会下载这两个文件,并加载

8.目标主机开始安装

9.安装程序读取PXE配置文件(ks.cfg),按照配置文件中的脚本执行安装过程

10.安装程序从HTTPD(或FTP或NFS或其他介质)上读取操作系统安装文件

11.安装完成

一. 配置DHCP服务器:

1.vim /etc/dhcpd.conf

ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.224.0 netmask 255.255.254.0 {

option routers 192.168.225.254; 
option subnet-mask 255.255.254.0;

option domain-name-servers 192.168.80.1;

option time-offset -18000; # Eastern Standard Time

range dynamic-bootp 192.168.225.131 192.168.225.150; //DHCP分配的IP段
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.224.131; //TFTP服务器IP

filename “pxelinux.0″; //pxelinux loader文件的位置(相对于TFTP的根目录) 

二.配置TFTP服务器

1.本文中,TFTP服务器安装在RHEL5.5中,使用xinetd管理

2.打开tftpd的开机启动:

[root@tianjing-ops ~]# chkconfig tftp on  

查看tftp启动情况:

[root@tianjing-ops ~]# chkconfig –list | grep tftp
tftp: on  

3.修改xinetd配置文件

vim /etc/xinetd.d/tftp

service tftp
{
disable = no //默认为YES,改为no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot //tftp的根目录
per_source = 11
cps = 100 2
flags = IPv4
 

 

4. 重启xinetd服务

三. 配置PXE需要的文件

1.PXELINUX是由syslinux、isolinux派生出来的,支持PXE的bootloader,它可以实现远程通过PEX启动一台机器。把/usr/lib/syslinux/pxelinux.0拷到/tftpboot/目录下

下面分别配置RHEL5.5和ESX4.1 u1需要的文件

2.配置RHEL5.5需要的文件

a.从RHEL的iso中拷贝initrd.img和vmlinuz到/tftpboot

b.配置TFTP的配置文件

vim /tftpboot/pxelinux.cfg/default

display msgs/boot.msg //定义启动页面显示的内容
label Local //从本地硬盘启动
localboot 0
label RHEL5.5_x64 //安装RHEL5.5
kernel vmlinuz //kernel位置,相对与TFTP的根目录
append ks=http://192.168.224.131/RHEL5.5_x86_64/ks.cfgksdevice=eth0 initrd=initrd.img devfs=nomount ramdisk_size=16384 nofb

// ks配置文件,ksdevice可以指定使用哪个网卡
LABEL ESX4.1 //安装ESX4.1
menu label ESX auto install
kernel esx/vmlinuz //kernel位置

append initrd=esx/initrd.img debugLogToSerial=1 mem=512M ks=http://192.168.224.131/ESX4.1/ks.cfg quiet 

 

vim msgs/boot.msg

Welcome to Network Installer!

Enter the shortname of the Operation System you wish to install:

Local. Local Machine
RHEL5.5_x64. RHEL5.5_x86_64

ESX4.1. ESX Server4.1 update01 

 

3. 配置RHEL的ks.cfg文件

vim ks.cfg

# Install OS instead of upgrade
install
# Use text mode install
text
# Use network installation
url –url=http://192.168.224.131/RHEL5.5_x86_64
# Installation logging level
logging –level=info

key –skip //跳过RHEL的key输入

lang en_US.UTF-8

keyboard us

network –bootproto=dhcp –device=eth0 –onboot=on

rootpw –iscrypted $1$P7vha6R8$plsp2BHaMUxZWsGmOL2hC0 //默认root密码

authconfig –enableshadow –enablemd5

firewall –enabled –port=22:tcp //默认防火墙规则
selinux –disabled //关闭selinux

# Do not configure the X Window System
skipx

timezone –utc Asia/Hong_Kong

# X Window System configuration information
xconfig –defaultdesktop=GNOME –depth=8 –resolution=640×480

#The services listed in the disabled list will be disabled //关闭不需要的服务开机启动
services –disabled autofs,cpuspeed,kudzu,mdmonitor,xfs,hidd,hplip,pcscd,gpm,cups,anacron,avahi-daemon,bluetooth,cpuspeed,firstboot,
isdn,ip6tables,mcstrans,yum-updatesd,setroubleshoot,rpcidmapd,rpcgssd,rhnsd,restorecond,rawdevices,lvm2-monitor

user –name=tianjing –groups=tianjing –password=$1$P7vha6R8$plsp2BHaMUxZWsGmOL2hC0 –iscrypted //创建新用户

reboot //重新启动

# System bootloader configuration
bootloader –location=mbr –driveorder=sda –append=”rhgb quiet”

# Partition clearing information //默认的磁盘分区,需要根据需要修改
clearpart –all
# Disk partitioning information
part / –asprimary –bytes-per-inode=4096 –fstype=”ext3″ –grow –size=1
part /boot –asprimary –bytes-per-inode=4096 –fstype=”ext3″ –size=200
part swap –bytes-per-inode=4096 –fstype=”swap” –size=20480

%post –interpreter=/bin/bash //安装本地的yum源
echo “” > /etc/yum.repos.d/rhel-local.repo
cat >> /etc/yum.repos.d/rhel-local.repo <[RHEL_Server]
name=RHEL_Server
baseurl=http://192.168.224.131/RHEL5.5_x86_64//Server
enabled=1
gpgcheck=0
[RHEL_1]
name=RHEL_1
baseurl=http://192.168.224.131/RHEL5.5_x86_64//HighAvailability
enabled=1
gpgcheck=0
[RHEL_2]
name=RHEL_2
baseurl=http://192.168.224.131/RHEL5.5_x86_64//LoadBalancer
enabled=1
gpgcheck=0
[RHEL_3]
name=RHEL_3
baseurl=http://192.168.224.131/RHEL5.5_x86_64//ResilientStorage
enabled=1
gpgcheck=0
[RHEL_3]
name=RHEL_3
baseurl=http://192.168.224.131/RHEL5.5_x86_64//ResilientStorage
enabled=1
gpgcheck=0
[RHEL_4]
name=RHEL_4
baseurl=http://192.168.224.131/RHEL5.5_x86_64//ScalableFileSystem
enabled=1
gpgcheck=0
EOF
%end

%packages //默认安装的包
@admin-tools
@base
@core
@dialup
@editors
@gnome-desktop
@games
@graphical-internet
@graphics
@legacy-software-support
@office
@printing
@sound-and-video
@text-internet
@base-x
kexec-tools
fipscheck
device-mapper-multipath
sgpio
ipmitool
libsane-hpaio
xorg-x11-utils
xorg-x11-server-Xnest
system-config-kickstart
imake

expect 

4.测试

开机,一般按F12会从PXE启动,然后输入RHEL5.5_x64选择安装RHEL5.5

5.配置ESX需要的文件

a. 建立ESX的目录

[root@tianjing-ops tftpboot]# mkdir -p /tftpboot/esx  

b. 从ESX4.1的iso中拷贝initrd.img和vmlinuz到/tftpboot/esx 目录

c. cp /usr/lib/syslinux/menu.c32 /tftpboot/esx/

d. 配置TFTP的default配置文件,同2(b)中的Label ESX4.1

6.配置ESX4.1的ks.cfg文件

#Accept the VMware End User License Agreement
accepteula

keyboard us

#root password
rootpw –iscrypted $1$7V9yciy4$MAsxRDcPl6WtKqkyeOAvb/

auth

#BootLoader
bootloader –location=mbr

timezone ‘Asia/Shanghai’

#Install
install url http://192.168.224.131/ESX4.1

network –addvmportgroup=true –device=vmnic0 –bootproto=dhcp

# clear partitions
clearpart –alldrives –overwritevmfs –initlabel

# Partitioning
part ‘/boot’ –fstype=ext3 –size=1100 –onfirstdisk
part ‘none’ –fstype=vmkcore –size=110 –onfirstdisk
part ‘datastore1′ –fstype=vmfs3 –size=9004 –grow –onfirstdisk

virtualdisk ‘esxconsole’ –size=8004 –onvmfs=’datastore1′

part ‘swap’ –fstype=swap –size=1000 –onvirtualdisk=’esxconsole’
part ‘/var/log’ –fstype=ext3 –size=2000 –onvirtualdisk=’esxconsole’
part ‘/’ –fstype=ext3 –size=5000 –grow –onvirtualdisk=’esxconsole’

reboot

%post –interpreter=bash 

7.测试

F12从PXE启动后,输入ESX4.1开始安装ESX。

输入Local可以跳过PXE安装从本地启动服务器。

8. ESX4.1安装完成以后需要用vSphere client 登录以后创建一个普通用户,然后在用普通用户ssh登录ESX主机更改为固定IP,ESX4.1不建议使用动态IP地址。

待解决的问题:

1.sun的X6240刀片使用pxe安装ESX时如何在安装的过程中加载光纤卡的驱动程序?

2.ESX4.1安装完成以后如何自动新建一个普通帐号或者打开root的ssh登录权限?简化修改IP地址的过程。