1 case description
A company needs to install a centos operating system on a large number of servers. It is time-consuming and labor-intensive to manually install one. Therefore, it is very important to build a PXE Server. the system server is quickly installed without manual intervention. But how can we quickly and effectively build a PXE Server? We can quickly build a PXE platform by writing a Shell script.
2 Case Analysis
To set up the PXE Server, you can choose to install centos6.0X86 _ 64, centos5.5i386, and centos5.5X86 _ 64. You can choose automatic or manual installation. Therefore, servers on the PXE platform must have the kicstart file of centos6.0, kickstart file of centos5.5X86 _ 64, and kickstart file of centos5.5i386, which can be generated in the corresponding system and corresponding image files. it must be pre-transmitted to the host used to build a PXE Server.
3. Solution Process
3.1 first, the server must have image files installed on various types of systems. You can put these image files in the/opt directory.
[Root @ sswans20opt] # llC *
-Rw-r --. 1rootroot4181098720mar1616: 48CentOS-5.5-i386-bin-DVD.iso
-Rw-r --. 1rootroot4181098720mar1616: 48CentOS-5.5-x86_64-bin-DVD.iso
-Rw-r --. 1rootroot4238800896Mar1616: 29CentOS-6.0-x86_64-bin-DVD1.iso
3.2 put the corresponding ks. cfg file under the/opt directory.
[Root @ sswans20opt] # llks *
-Rwxrwxrwx.1rootroot1252Mar1617: 02ks5. 5-32.cfg # kickstart file generated by Centos5.5i386
-Rwxrwxrwx.1rootroot1256Mar1616: 50ks5. 5-64.cfg # kickstart file generated by Centos5.5X86 _ 64
-Rwxrwxrwx.1rootroot1068Mar1617: 02ks6. 0-64.cfg # kickstart file generated by Centos6.0X86 _ 64
3.3 The shell script for automatically building the PXE Server is as follows:
[Root @ sswans20opt] # vimauto_install.sh
#! /Bin/bash
######################################## ######################################## ######
############# Thisshellfilecanautoinstallcentos6.0andinstallcentos5.5 ###################
############################ CloseiptablesandSELINUX ######### ###################
Setenforce0
Echo"
# ThisfilecontrolsthestateofSELinuxonthesystem.
# SELINUX = cantakeoneofthesethreevalues:
# Enforcing-SELinuxsecuritypolicyisenforced.
# Permissive-SELinuxprintswarningsinsteadofenforcing.
# Disabled-NoSELinuxpolicyisloaded.
SELINUX = permissive
# SELINUXTYPE = cantakeoneofthesetwovalues:
# Targeted-Targetedprocessesareprotected,
# Mls-MultiLevelSecurityprotection.
SELINUXTYPE = targeted
">/Etc/sysconfig/selinux
Iptables-F
/Etc/init. d/iptablessave>/dev/null
################################## AutoMount ##### #################################
Mkdir-p/var/ftp/centos/5.5/i386/dvd
Mkdir-p/var/ftp/centos/5.5/x86_64/dvd
Mkdir-p/var/ftp/centos/6.0/x86_64/dvd
Mkdir-p/var/ftp/centos/ks
Echo "/opt/CentOS-5.5-i386-bin-DVD.iso/var/ftp/centos/5.5/i386/dvdiso9660defaults, loop, ro00">/etc/fstab
Echo & quot;/opt/CentOS-5.5-x86_64-bin-DVD.iso/var/ftp/centos/5.5/x86_64/dvdiso9660defaults, loop, ro00 & quot;>/etc/fstab
Echo & quot;/opt/CentOS-6.0-x86_64-bin-DVD1.iso/var/ftp/centos/6.0/x86_64/dvdiso9660defaults, loop, ro00 & quot;>/etc/fstab
Mount-
############################### Installsomepackages ####### #########################
Yuminstalldhcpvsftpdsyslinuxtftp-server-y>/dev/null
Servicevsftpdstart>/dev/null
############################ ConfigureDHCPService ######### #######################
Echo'
# Dhcpd. conf
# SampleconfigurationfileforISCdhcpd
# Optiondefinitionscommontoallsupportednetworks...
Default-lease-time600;
Max-lease-time7200;
Allowbooting;
Allowbootp;
Subnet172.25.0.0netmask0000255.0.0 {# network segment to be allocated and subnet mask
Range172.25.11.10172.25.11.30; # the IP address range assigned to the host
Optiondomain-name-servers172.25.11.20; # DNS server address
Optionrouters172.25.11.20; # vro address
Optionbroadcast-address172.25.255.255; # broadcast address
Next-server172.25.11.20; # address of the TFTP Server
Filename "pxelinux.0 ";
} '>/Etc/dhcp/dhcpd. conf
Servicedhcpdstart>/dev/null
########################### ConfigureTFTPService ########### #####################
Echo"
# Default: off
# Description: Thetftpserverservesfilesusingthetrivialfiletransfer \
# Protocol. Thetftpprotocolisoftenusedtobootdiskless \
# Workstations, downloadconfigurationfilestonetwork-awareprinters ,\
# Andtostarttheinstallationprocessforsomeoperatingsystems.
Servicetftp
{
Socket_type = dgram
Protocol = udp
Wait = yes
User = root
Server =/usr/sbin/in. tftpd
Server_args =-unobody-s/var/lib/tftpboot
Disable = no
Per_source = 11
Cps = 1002
Flags = IPv4
} ">/Etc/xinetd. d/tftp
Servicexinetdstart>/dev/null
DIR1 =/var/lib/tftpboot/pxelinux. cfg
If [-d $ DIR1]; then
Rm-rf $ DIR
Else
Mkdir-p/var/lib/tftpboot/pxelinux. cfg
Fi
######################## Cpsomefilesto/var/lib/tftpboot ######### #######################
Cp/usr/share/syslinux/pxelinux.0/var/lib/tftpboot/
Mkdir/var/lib/tftpboot/centos6.0 _ x86_64
Cp/var/ftp/centos/6.0/x86_64/dvd/images/pxeboot/vmlinuz/var/lib/tftpboot/centos6.0 _ x86_64
Cp/var/ftp/centos/6.0/x86_64/dvd/images/pxeboot/initrd. img/var/lib/tftpboot/centos6.0 _ x86_64
Cp/var/ftp/centos/6.0/x86_64/dvd/isolinux/boot. msg/var/lib/tftpboot/
Cp/var/ftp/centos/6.0/x86_64/dvd/isolinux/vesamenu. c32/var/lib/tftpboot/
Cp/var/ftp/centos/6.0/x86_64/dvd/isolinux/splash.jpg/var/lib/tftpboot/
####################### Addanewcentos5istmsystem ################ #################
Mkdir/var/lib/tftpboot/centos5.5 _ i386
Cp/var/ftp/centos/5.5/i386/dvd/images/pxeboot/vmlinuz/var/lib/tftpboot/centos5.5 _ i386
Cp/var/ftp/centos/5.5/i386/dvd/images/pxeboot/initrd. img/var/lib/tftpboot/centos5.5 _ i386
####################### Addanewcentos5x86_64system ################ ##############
Mkdir/var/lib/tftpboot/centos5.5 _ x86_64
Cp/var/ftp/centos/5.5/x86_64/dvd/images/pxeboot/vmlinuz/var/lib/tftpboot/centos5.5 _ i386
Cp/var/ftp/centos/5.5/x86_64/dvd/images/pxeboot/initrd. img/var/lib/tftpboot/centos5.5 _ i386
########################## Configurethedefaultfile ############# #######################
Echo"
Defaultvesamenu. c32
Timeout600
Displayboot. msg
Menubackgroundsplash.jpg
Menutitlewelcometokedaco minstallcentos!
Menucolorborder0 # ffffffff #00000000
Menucolorsel7 # ffffffff # ff000000
Menucolortitle0 # ffffffff #00000000.
Menucolortabmsg0 # ffffffff #00000000
Menucolorunsel0 # ffffffff #00000000.
Menucolorhotsel0 # ff000000 # ffffff
Menucolorhotkey7 # ffffffff # ff000000
Menucolorscrollbar0 # ffffffff #00000000
LabelCentOS6.0 _ x86_64
MenulabelCentOS6.0X86 _ 84 installwithkickstart
Menudefault
Kernelcentos6.0 _ x86_64/vmlinuz
Appendinitrd = centos6.0 _ x86_64/initrd. imgks = ftp: // 172.25.11.20/centos/ks/ks6.0-64. extends textksdevice = eth0
LabelCentOS5.5 _ i386
Menulabelcentos5.5i1_installwithkickstart
Kernelcentos5.5 _ i386/vmlinuz
Appendinitrd = centos5.5 _ i386/initrd. imgks = ftp: // 172.25.11.20/centos/ks/ks5.5-32. extends textksdevice = eth0
LabelCentOS5.5 _ x86_64
MenulabelCentOS5.5X86 _ 64 installwithkickstart
Kernelcentos5.5 _ x86_64/vmlinuz
Appendinitrd = centos5.5 _ x86_64/initrd. imgks = ftp: // 172.25.11.20/centos/ks/ks5.5-64. plain text
Ksdevice = eth0
LabelCentOS6.0-x86_64
MenulabelShoudonginstallCentOS6.0X86 _ 84
Kernelcentos6.0 _ x86_64/vmlinuz
Appendinitrd = centos6.0 _ x86_64/initrd. img
LabelCentOS5.5-i386
MenulabelShoudonginstallCentOS5.5i386
Kernelcentos5.5 _ i386/vmlinuz
Appendinitrd = centos5.5 _ i386/initrd. img
LabelCentOS5.5-x86_64
MenulabelShoudonginstallCentOS5.5X86 _ 64
Kernelcentos5.5 _ x86_64/vmlinuz
Appendinitrd = centos5.5 _ x86_64/initrd. img
">/Var/lib/tftpboot/pxelinux. cfg/default
############################ ConfigureKickstart ########### #########################
Mv/opt/ks5.5-32.133/var/ftp/centos/ks
Chmod777/var/ftp/centos/ks/ks5.5-32.cfg
Mv/opt/ks5.5-64.133/var/ftp/centos/ks
Chmod777/var/ftp/centos/ks/ks5.5-64.cfg
Mv/opt/ks6.0-64.133/var/ftp/centos/ks
Chmod777/var/ftp/centos/ks/ks6.0-64.cfg
########################### ALLServiceRestart ########### ##########################
ForFWindhcpdxinetdvsftpd
Do
Service $ FWrestart
Chkconfig $ FWon
Done
3.4 you can grant executable permissions to the prepared automated scripts so that the scripts can be executed.
[Root @ sswans20 ~] # Chmod777auto_install.sh
[Root @ sswans20 ~] # Llauto_install.sh
-Rwxrwxrwx.1rootroot5236Mar1616: 52auto_install.sh
Note
Because the IP addresses of my DHCP server, FTP server, TFTP server, and DNS server are 172.25.11.20, make the following changes according to your actual environment before executing this script.
Open each ks file and check whether the url -- url = ftp: // 172.25.11.20/is consistent with the address of your FTP server.
Make sure that the scriptRed FlagThe IP address must be the address of your FTP server or TFTP server.
, ScriptBlue markThe IP address can be changed or not, depending on your actual needs.
Run the script file after 3.5 or more errors
[Root @ sswans20 ~] #./Auto_install.sh # Wait for a while after execution
Shuttingdowndhcpd: [OK]
Startingdhcpd: [OK]
Stoppingxinetd: [OK]
Startingxinetd: [OK]
Shuttingdownvsftpd: [OK]
Startingvsftpdforvsftpd: [OK]
3.6 verify that the PXE Server is successfully built and verified by installing the system on the other server
650) this. width = 650; "width =" 578 "height =" 260 "style =" border: 1px solid # dddddddd; "src ="/e/u/themes/default/images/spacer.gif "alt =" spacer.gif "/>
I have not uploaded the centos5.5x86 _ 64-bit system image file on the server, so I can only see four installation options.
The Automatic Installation Process of centos5.5i386 is as follows:
650) this. width = 650; "width =" 604 "height =" 336 "style =" border: 1px solid # dddddddd; "src ="/e/u/themes/default/images/spacer.gif "alt =" spacer.gif "/>
4. solution results
On this installation page, you can use the up/down key to select the system type to be used for installation. Then, press the Enter key to start automatic installation. If the installation process is not selected, the first installation item is selected by default after 60 s.
5. Summary
The key to building a PXE Server automatically lies in the writing of shell scripts, which requires the writers to be familiar with shell syntax and have certain logic thinking capabilities. This script provides silly installation for those who are not clear about PXE setup. If you are interested, you can analyze and read the script content in detail. If you have any questions, please contact me via Weibo. Thank you.
This article is from the "706737" blog and will not be reproduced!