注意脚本中的ip需要修改!#bin/bash##by syaving#date 2016-11-09#pxe install OS#Linux for CentOS-6.8 2.6.32-642.el6.x86_64. /etc/init.d/functionsfor rpm in dhcp tftp tftp-server xinetd syslinux httpddorpm -qa | grep $rpm >/dev/null 2>&1if [[ $? == 0 ]];thenechoecho -e "Package [$rpm] is already installed. "elseechoecho -e "Start to install package [$rpm]."yum install -y $rpm >/dev/null 2>&1rpm -qa | grep $rpm >/dev/null 2>&1 if [[ $?==0 ]];then echo echo -e "Install package [$rpm] SUCCESSFULLY." else echo echo -e "Install package [$rpm] FAILED." fifidonesleep 5/bin/cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bakcat >/etc/dhcp/dhcpd.conf<<eof# DHCP Server Configuration file.# see /usr/share/doc/dhcp*/dhcpd.conf.sample# by Syavingsubnet 172.16.1.0 netmask 255.255.255.0 { range 172.16.1.100 172.16.1.200; option subnet-mask 255.255.255.0; default-lease-time 21600; max-lease-time 43200; next-server 172.16.1.100; #注意要修改 filename "/pxelinux.0";}eof/etc/init.d/dhcpd start >>/dev/null 2>&1if [ $? -eq 0 ];then action "dhcp" /bin/trueelse action "dhcp" /bin/falsefisleep 6/bin/cp /etc/xinetd.d/tftp /etc/xinetd.d/tftp.bakcat >/etc/xinetd.d/tftp<<eof# 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 /var/lib/tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4}eof/etc/init.d/xinetd start >>/dev/null 2>&1if [ $? -eq 0 ];then action "tftp" /bin/trueelse action "tftp" /bin/falsefisleep 6sed -i "277i ServerName 127.0.0.1:80" /etc/httpd/conf/httpd.conf/etc/init.d/httpd start >>/dev/null 2>&1/bin/mkdir -p /var/www/html/CentOS-6.8###/bin/mount -o loop -t iso9660 /dev/cdrom /var/www/html/CentOS-6.8/if [ $? -eq 0 ];then action "http" /bin/trueelse action "http" /bin/falsefisleep 6/bin/cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot//bin/cp -a /var/www/html/CentOS-6.8/isolinux/* /var/lib/tftpboot//bin/mkdir -p /var/lib/tftpboot/pxelinux.cfgif [ $? -eq 0 ];then action "syslinux" /bin/trueelse action "syslinux" /bin/falsefisleep 6#ks.conf/bin/mkdir /var/www/html/ks_configks_xxx="/var/www/html/ks_config"/bin/cp /server/scripts/CentOS-6.8-ks.cfg $ks_xxx#/bin/cp /server/scripts/optimization.sh $ks_xxxcat >/var/lib/tftpboot/pxelinux.cfg/default<<eofdefault ksprompt 0label ks kernel vmlinuz append initrd=initrd.img ks=http://172.16.1.100/ks_config/CentOS-6.8-ks.cfg ksdevice=eth1eof
本文出自 “宋某人c” 博客,请务必保留此出处http://syaving.blog.51cto.com/5614476/1863707