#!/bin/bash# -*- coding: utf-8 -*-##  dfkp5.sh##  Copyright 2012 wanghui 
## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,# MA 02110-1301, USA.###声明全局变量#网络网段NET=`ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print$2}' |cut -d. -f1,2,3`#pxe服务器主机ipSER_IP=`ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | awk -F: '{print$2}'`#dhcp服务分配的起始ipSTA_IP="$NET.10"#dhcp服务分配的结束ipEND_IP="$NET.100"#子网掩码NETMASK=`ifconfig eth0 | grep Mask |awk -F: '{print $4}'`ROUTE=`route | grep default | awk '{print $2}'`##配置本地yum服务##判断yum服务是否安装rpm -qa | grep yum >& /dev/nullif [ $? -eq 1 ] then echo "yum is not installed! please install yum." else echo "yum is installed!"fi#判断使用光盘还是iso文件做安装镜像echo "-----------------------------------"echo "1) use cdrom "echo "2) use iso file"echo "q) exit"echoecho -n "Please Enter a Installation method:"read MET case $MET in 1)echo "you slect cdrom install operationg system!" echo -e "\033[31m Please insert your cdrom.... \033[0m" sleep 20 mount -r /dev/cdrom /mnt >& /dev/null mount -r /dev/cdrom /var/ftp/pub >& /dev/null ;; 2)echo "you slect iso file install operationg system!" echo -n "Please input you file path:" read ISOF mount -o loop $ISOF /mnt >& /dev/null mount -o loop $ISOF /var/ftp/pub >& /dev/null ;; q)echo "quit!" exit 0 ;; *)echo "Please slect 1|2|q" exit 1 ;; esac#配置yum服务的本地yum源cat <
/etc/yum.repos.d/server.repo[base]name=basebaseurl=file:///mnt/Server/enabled=1gpgcheck=0EOF#清除yum源的缓存yum clean allyum list >& /dev/nullif [ $? -eq 0 ] then echo "YUM 服务配置成功!"fi##判断是否安装了相关软件#for RPM in vsftpd tftp tftp-server system-config-kickstart do rpm -qa | grep $RPM >& /dev/null if [ $? -eq 1 ] then echo "$RPM is not installed!" yum install -y $RPM #>& /dev/null if [ $? -eq 0 ] then echo -e "\033[32m$RPM 已安装成功!\033[0m" else echo -e "\033[31m$RPM 安装失败!\033[0m" fi else echo -e "\033[34m$RPM is installed!\033[0m" fidone##配置vsftp服务##配置ks.cfg文件system-config-kickstartKSCFG=/var/ftp/ks.cfgcp -rf ks.cfg $KSCFGcat postshell >>$KSCFGsed -i '/^# System language/i key --skip' $KSCFGsed -i "s/serverip/${SER_IP}/g" $KSCFG/etc/init.d/vsftpd restart##配置tftp服务#TFTP='/etc/xinetd.d/tftp'TMP_TFTP="/tmp/tmp.$$"sed -i '/disable/s/yes/no/' $TFTP#mv -f $TMP_TFTP $TFTPPXE='/usr/lib/syslinux/pxelinux.0'ISO='/mnt/isolinux/isolinux.cfg'IMG='/mnt/p_w_picpaths/pxeboot/initrd.img'VML='/mnt/p_w_picpaths/pxeboot/vmlinuz'DEFT='/tftpboot/pxelinux.cfg/default'mkdir /tftpboot/pxelinux.cfgcp $PXE /tftpboot/cp $ISO $DEFTcp $IMG /tftpboot/cp $VML /tftpboot/chmod 644 $DEFTsed -i "3s/600/1/;12d;11 a\ append initrd=initrd.img ks=ftp://$SER_IP/ks.cfg" $DEFT/etc/init.d/xinetd restart##配置dhcp服务#yum install -y dhcpDHCP='/etc/dhcpd.conf'TMP_DHCP="/tmp/tmp.$$"cat <
$DHCPddns-update-style interim;ignore client-updates;subnet $NET.0 netmask $NETMASK { option routers $ROUTE; option subnet-mask $NETMASK; filename="pxelinux.0"; next-server $SER_IP; range dynamic-bootp $STA_IP $END_IP; default-lease-time 21600; max-lease-time 43200;}EOF#mv -f $TMP_DHCP $DHCP/etc/init.d/dhcpd restart##系统安全设置#iptables -Fservice iptables saveservice iptables stopsetenforce 0##配置NFS#mkdir /sharedataecho "/sharedata *(sync,rw)">/etc/exportsservice nfs restart