shell脚本之全自动化部署PXE
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本之全自动化部署PXE相关的知识,希望对你有一定的参考价值。
#!/bin/bash
#2017-07-21 by max
#config pxe
#config yum
if [ ! -d ~/yum.bak ];
then
mv /etc/yum.repos.d/* ~/yum.bak
else
mkdir ~/yum.bak
mv /etc/yum.repos.d/* ~/yum.bak
fi
cat >/etc/yum.repos.d/server.repo<< EOF
[base]
name=server
baseurl=file:///mnt
gnabled=1
gpgcheck=0
EOF
mount /dev/cdrom /mnt
yum clean all
yum -y update
#config ftp
yum -y install vsftpd
systemctl restart vsftpd ; systemctl enable vsftpd
#config tftp
yum -y install tftp tftp-server xinetd
sed ‘13s/\/var\/lib/ /‘ /etc/xinetd.d/tftp -i
sed ‘14s/yes/no/‘ /etc/xinetd.d/tftp -i
#config network
cat >/etc/sysconfig/network-scripts/ifcfg-eno16777736<<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eno16777736
DEVICE=eno16777736
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.25.1
EOF
systemctl restart network
#config dhcp
yum -y install dhcp
if [ -f /etc/dhcp/dhcpd.conf.bak ];
then
rm -rf /etc/dhcp/dhcpd.conf.bak
fi
cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
rm -rf /etc/dhcp/dhcpd.conf
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet 192.168.25.0 netmask 255.255.255.0 {
range 192.168.25.100 192.168.25.200;
next-server 192.168.25.1;
filename "pxelinux.0";
}
EOF
systemctl restart dhcpd ;systemctl enable dhcpd
#config kickstart
if [ ! -d /tftpboot/ ];
then
mkdir /tftpboot/
else
rm -rf /tftpboot/*
fi
mkdir /tftpboot/pxelinux.cfg -p
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot/
cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
cp /mnt/images/pxeboot/initrd.img /tftpboot/
cp /mnt/images/pxeboot/vmlinuz /tftpboot/
chmod 644 /tftpboot/pxelinux.cfg/default
#config boot ‘default‘
sed ‘1s/.*/default linux/‘ /tftpboot/pxelinux.cfg/default -i
sed ‘64s/.*/append initrd=initrd.img ks=ftp:\/\/192.168.25.1\/ks.cfg/‘ /tftpboot/pxelinux.cfg/default -i
sed ‘68d‘ /tftpboot/pxelinux.cfg/default -i
sed ‘63 imenu default‘ /tftpboot/pxelinux.cfg/default -i
cat >/var/ftp/ks.cfg<<EOF
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard ‘us‘
# Root password
rootpw --iscrypted $1$syci/OCt$KHzs273jZFiTzcp92eGxJ0
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url="ftp://192.168.25.1/pub"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --enforcing
# Network information
network --bootproto=dhcp --device=eno16777736 --onboot=yes
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr --md5pass="$1$wLuI.AZb$sO8s4dCMYHZ7rRDIhRC95."
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=20480
part swap --fstype="swap" --size=2048
%packages
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@multimedia
@print-client
@x11
%end
EOF
#config srouce and server
umount /dev/cdrom
mount /dev/cdrom /var/ftp/pub
iptables -F
setenforce 0
systemctl stop firewalld
systemctl restart dhcpd
systemctl restart vsftpd
systemctl restart xinetd
以上是关于shell脚本之全自动化部署PXE的主要内容,如果未能解决你的问题,请参考以下文章
自动化部署java maven项目到多个目标主机的Shell脚本