用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 [RHEL_2] name=RHEL_2 baseurl=http://192.168.224.131/RHEL5.5_x86_64//LoadBalancer [RHEL_3] name=RHEL_3 baseurl=http://192.168.224.131/RHEL5.5_x86_64//ResilientStorage [RHEL_4] name=RHEL_4 baseurl=http://192.168.224.131/RHEL5.5_x86_64//ScalableFileSystem 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 #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位址。