Rapid deployment of network PXE shell scripts

Source: Internet
Author: User
Tags yum repolist dchp


#!/bin/bash

#获取当前机器IP地址

ip= ' Ifconfig | head-2 | Tail-1 | awk ' {print $} '

#获取当前机器MASK地址

mask= ' Ifconfig | head-2 | Tail-1 | awk ' {print $4} '

Mask1= ' echo $MASK | Awk-f. ' {print '} '

If [$MASK 1-ne 0];then

Ip1= ' echo $IP | Awk-f. ' {print '} '

Min1= ' echo $IP | Awk-f. ' {print '} '

Max1= ' echo $IP | Awk-f. ' {print '} '

Else

Ip1=0

Min1=1

max1=254

Fi

Mask2= ' echo $MASK | Awk-f. ' {print $} '

If [$MASK 2-ne 0];then

Ip2= ' echo $IP | Awk-f. ' {print $} '

Min2= ' echo $IP | Awk-f. ' {print $} '

Max2= ' echo $IP | Awk-f. ' {print $} '

Else

Ip2=0

Min2=1

max2=254

Fi

Mask3= ' echo $MASK | Awk-f. ' {print $} '

If [$MASK 3-ne 0];then

Ip3= ' echo $IP | Awk-f. ' {print $} '

Min3= ' echo $IP | Awk-f. ' {print $} '

Max3= ' echo $IP | Awk-f. ' {print $} '

Else

Ip3=0

Min3=1

max3=254

Fi

Mask4= ' echo $MASK | Awk-f. ' {print $4} '

If [$MASK 4-ne 0];then

Ip4= ' echo $IP | Awk-f. ' {print $4} '

Min4= ' echo $IP | Awk-f. ' {print $4} '

Max4= ' echo $IP | Awk-f. ' {print $4} '

Else

Ip4=0

Min4=1

max4=254

Fi

#NETIP为要配置DHCP的网络号

Netip= "$IP 1. $IP 2. $IP 3. $IP 4"

#MINIP the minimum IP for the DCHP range to be configured

Minip= "$MIN 1. $MIN 2. $MIN 3. $MIN 4"

#MAXIP to configure the DCHP range for the maximum IP

Maxip= "$MAX 1. $MAX 2. $MAX 3. $MAX 4"



Systemctl Stop Firewalld.service

Setenforce 0

#配置本地YUM源

Echo-en "Configuring local Yum Source ... \t\t"

Creatyum () {

echo "/dev/cdrom/mnt/iso9660 defaults 0 0" >>/etc/fstab

Mount-a &>/dev/null

n= ' ls/mnt/$Date | Wc-l '

If [$n-eq 0];then

Echo ' Please mount the disc file!!! '

Exit

Fi

rm-rf/etc/yum.repos.d/*

echo "[DVD]

Name=dvd

baseurl=file:///mnt/

Gpgcheck=0

">/etc/yum.repos.d/dvd.repo

Yum Clean all &>/dev/null

}

Yum repolist &> ${date}.txt

A= ' Cat ${date}.txt | Tail-1 | Sed ' s/[,]//' | awk ' {print $} '

RM-RF ${date}.txt

If [-Z ' echo ' $a ' | grep-e ' s/[^0-9]//'];then

Creatyum

elif [$a-eq 0];then

Creatyum

Fi

Echo-e "\e[32;1m[ok]\e[0m"




#部署DHCP服务器

Echo-en "Deploying DHCP server ... \t\t"

Yum-y Install DHCP >&/dev/null

Echo '

Subnet $NETIP netmask $MASK {

Range $MINIP $MAXIP;

Option Domain-name-servers $IP;

option routers $IP;

Default-lease-time 600;

Max-lease-time 7200;

Next-server $IP;

FileName "pxelinux.0";


} ' >/etc/dhcp/dhcpd.conf

Sed-i "s/\ $IP/$IP/"/etc/dhcp/dhcpd.conf

Sed-i "s/\ $MASK/$MASK/"/etc/dhcp/dhcpd.conf

Sed-i "s/\ $NETIP/$NETIP/"/etc/dhcp/dhcpd.conf

Sed-i "s/\ $MINIP/$MINIP/"/etc/dhcp/dhcpd.conf

Sed-i "s/\ $MAXIP/$MAXIP/"/etc/dhcp/dhcpd.conf

Systemctl restart DHCPD>&/dev/null

Systemctl enable DHCPD>&/dev/null

Echo-e "\e[32;1m[ok]\e[0m"


#搭建TFTP服务

Echo-en "Building TFTP service ... \t\t"

Yum-y Install tftp-server.x86_64>&/dev/null

Systemctl Restart TFTP>&/dev/null

Systemctl enable TFTP>&/dev/null

Echo-e "\e[32;1m[ok]\e[0m"


#部署pxelinux. 0 file

Echo-en "Deploying pxelinux.0 Files ... \t\t"

Yum-y Install syslinux-4.05-12.el7.x86_64 >&/dev/null

cp/usr/share/syslinux/pxelinux.0/var/lib/tftpboot/

mkdir/var/lib/tftpboot/pxelinux.cfg/>&/dev/null

cp/mnt/isolinux/initrd.img/mnt/isolinux/vmlinuz/mnt/isolinux/vesamenu.c32/var/lib/tftpboot/

Echo-e "\e[32;1m[ok]\e[0m"



#部署default默认的菜单文件

Echo-en "Deploying default Menu Files ... \t\t"

Yum-y Install vsftpd >&/dev/null

Systemctl Restart VSFTPD >&/dev/null

Systemctl Enable VSFTPD >&/dev/null

Mkdir/var/ftp/rhel7 >&/dev/null

Mount/dev/cdrom/var/ftp/rhel7 >&/dev/null

Echo-e "\e[32;1m[ok]\e[0m"


#搭建vsftpd服务, shared answer file

Echo-en "Building vsftpd service, sharing answer file ... \t\t"

Echo '

#platform =x86, AMD64, or Intel EM64T

#version =devel

# Install OS instead of upgrade

Install

# Keyboard Layouts

Keyboard ' US '

# Root Password

ROOTPW--iscrypted $1$VL9/L0OR$ZM8S/NJIJLPSGY6P0CMMB.

# System TimeZone

TimeZone Asia/shanghai

# Use Network Installation

URL--url= "ftp://$IP/rhel7"

# System Language

Lang ZH_CN

# Firewall Configuration

Firewall--disabled

# System Authorization Information

Auth--useshadow--passalgo=sha512

# Use graphical Install

Graphical

# SELinux Configuration

SELinux--disabled

# Do not configure the X Window System

Skipx


# Network Information

Network--bootproto=dhcp--device=eth0

# Reboot after installation

Reboot

# System Bootloader Configuration

Bootloader--LOCATION=MBR

# Clear the Master Boot Record

Zerombr

# Partition Clearing Information

Clearpart--all--initlabel

# Disk Partitioning Information

Part swap--fstype= "swap"--size=1024

Part/--fstype= "XFS"--grow--size=1


%post--interpreter=/bin/bash

rm-rf/etc/yum.repos.d/*

echo "

[FTP]

Name=ftp

baseurl=ftp://$IP/rhel7

Enabled=1

Gpgcheck=0

">/etc/yum.repos.d/ftp.repo

%end


%packages

@base


%end

' >/var/ftp/ks.cfg

Sed-i "s/\ $IP/$IP/"/var/ftp/ks.cfg

Echo-e "\e[32;1m[ok]\e[0m"


#部署default默认的菜单文件

Echo-en "Deploying default Menu Files ... \t\t"

Echo '

Default Vesamenu.c32

Timeout 600


Display Boot.msg


# Clear The screen when exiting the menu, instead of leaving the menu displayed.

# for Vesamenu, this means the graphical background is still displayed without

# The menu itself for as long as the remains in graphics mode.

Menu Clear

Menu Background Splash.png

Menu Title PXE SERVER

Menu Vshift 8

Menu Rows 18

Menu Margin 8

#menu Hidden

Menu Helpmsgrow 15

Menu Tabmsgrow 13


# Border Area

Menu Color Border * #00000000 #00000000 None


# Selected Item

Menu Color sel 0 #ffffffff #00000000 None


# Title Bar

Menu Color title 0 #ff7ba3d0 #00000000 None


# Press [TAB] Message

Menu Color tabmsg 0 #ff3a6496 #00000000 None


# unselected menu item

Menu Color Unsel 0 #84b8ffff #00000000 None


# Selected Hotkey

Menu Color Hotsel 0 #84b8ffff #00000000 None


# unselected Hotkey

Menu Color Hotkey 0 #ffffffff #00000000 None


# Help Text

Menu Color Help 0 #ffffffff #00000000 None


# A ScrollBar of some type? Not sure.

Menu Color scrollbar 0 #ffffffff #ff355594 None


# Timeout MSG

Menu Color Timeout 0 #ffffffff #00000000 None

Menu Color timeout_msg 0 #ffffffff #00000000 None


# Command Prompt Text

Menu Color Cmdmark 0 #84b8ffff #00000000 None

Menu Color CmdLine 0 #ffffffff #00000000 None


# do not display the actual menu unless the user presses a key. All this is displayed a timeout message.


Menu Tabmsg Press Tab for full configuration options on menu items.


Menu Separator # Insert an empty line

Menu Separator # Insert an empty line


Label Linux

Menu Label ^install RHEL

Kernel Vmlinuz

Append initrd=initrd.img ks=ftp://$IP/ks.cfg


' >/var/lib/tftpboot/pxelinux.cfg/default

Sed-i "s/\ $IP/$IP/"/var/lib/tftpboot/pxelinux.cfg/default

chmod 644/var/lib/tftpboot/pxelinux.cfg/default


Echo-e "\e[32;1m[ok]\e[0m"

ECHO-E "PXE service deployment succeeded \t\t"


Please see http://blog.51cto.com/13558754/2058170 for specific steps.



Rapid deployment of network PXE shell scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.