#!/bin/bash #internet #安装epel7源和centos7源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo >/dev/null 2>&1 ##########install softwall ############################# yum -y install httpd dhcp xinetd tftp-server net-tools syslinux >/dev/null 2>&1 ####---- 设置ip和网段变量 ----#### read -p "Please insert ip address": IPADDR mask=$(echo $IPADDR| cut -d '.' -f 1-3) subnet=$(ifconfig |grep "$mask" | awk '{print $4}') #######dhcp配置########################## cat >/etc/dhcp/dhcpd.conf<<EOF #option domain-name "example.org"; #option domain-name-servers ns1.example.org, ns2.example.org; #default-lease-time 600; #max-lease-time 7200; #log-facility local7; subnet $mask.0 netmask $subnet { range dynamic-bootp $mask.10 $mask.60; filename "pxelinux.0"; next-server $IPADDR; } EOF ####---- tftpd配置 ----#### sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/tftp mkdir /var/lib/tftpboot/pxelinux.cfg -p ####------------httpd配置----------#### mkdir /var/www/html/centos7 mount /dev/cdrom /var/www/html/centos7 ####-----------syslinux-----------#### /bin/cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ /bin/cp /var/www/html/centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default /bin/cp /var/www/html/centos7/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/ /bin/cp /var/www/html/centos7/isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/ ####-----------pxelinux.cfg/default------#### cat >/var/lib/tftpboot/pxelinux.cfg/default<<EOF default vesamenu.c32 timeout 6 label linux menu label ^Install CentOS 7 kernel vmlinuz append initrd=initrd.img inst.ks=http://$IPADDR/centos7_2.cfg quiet EOF ####------------------------------ks.cfg---------------------------------#### cat >/var/www/html/centos7_2.cfg<<EOF #Kickstart Configurator by Jason Zhao #platform=x86, AMD64, or Intel EM64T #System language lang en_US #System keyboard keyboard us #Sytem timezone timezone Asia/Shanghai #Root password rootpw 123456 #Use text mode install text #Install OS instead of upgrade install #Use NFS installation Media #url --url=$tree url --url=http://$IPADDR/centos7 #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr #Partition clearing information clearpart --all --initlabel #Disk partitioning information part /boot --fstype xfs --size 1024 --ondisk sda part swap --size 16384 --ondisk sda part / --fstype xfs --size 1 --grow --ondisk sda #System authorization infomation auth --useshadow --enablemd5 #Network information #network config network --bootproto=dhcp --device=eth0 --onboot=on # Reboot after installation reboot #Firewall configuration firewall --disabled #SELinux configuration selinux --disabled #Do not configure XWindows skipx #Package install information %packages @ base @ core sysstat iptraf ntp lrzsz ncurses-devel openssl-devel zlib-devel OpenIPMI-tools nmap screen %end %post systemctl disable postfix.service $yum_config_stanza %end EOF ####------------------------------ks.cfg---------------------------------#### ####-------------------------- restart service---------------------------#### systemctl restart dhcpd.service systemctl restart xinetd.service systemctl restart httpd.service systemctl stop firewalld.service setenforce 0