parent
7e7d31f8ed
commit
20633aa928
@ -0,0 +1,141 @@ |
|||||||
|
#!/usr/bin/bash |
||||||
|
|
||||||
|
color(){ |
||||||
|
unset c |
||||||
|
declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34) |
||||||
|
#echo -e "\033[${c[$1]}m[`date +%T`]($1) $2\033[0m" |
||||||
|
printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2" |
||||||
|
sleep 0.5 |
||||||
|
} |
||||||
|
|
||||||
|
# pxe服务器初始化 |
||||||
|
color Info "pxe服务器初始化" |
||||||
|
curl -s -L https://download.beyourself.org.cn/shell-project/os/get-os-init.sh | sh |
||||||
|
|
||||||
|
|
||||||
|
# 安装dhcp、tftp、tftp-server、syslinux、wget、vsftpd、pykickstart |
||||||
|
color Info "安装pxe服务依赖" |
||||||
|
yum install -y dhcp tftp tftp-server syslinux wget vsftpd pykickstart |
||||||
|
|
||||||
|
# 配置dhcp |
||||||
|
color Info "配置dhcp" |
||||||
|
ipaddr=$(ip -4 -f inet a show dev ens33 | awk '/inet/{print $2}') |
||||||
|
cat > /etc/dhcp/dhcpd.conf << EOF |
||||||
|
ddns-update-style interim; |
||||||
|
ignore client-updates; |
||||||
|
authoritative; |
||||||
|
allow booting; |
||||||
|
allow bootp; |
||||||
|
allow unknown-clients; |
||||||
|
|
||||||
|
# A slightly different configuration for an internal subnet. |
||||||
|
subnet ${ipaddr%.*}.0 netmask 255.255.255.0 |
||||||
|
{ |
||||||
|
range ${ipaddr%.*}.100 ${ipaddr%.*}.200; |
||||||
|
option domain-name-servers ${ipaddr%.*}.1; |
||||||
|
option domain-name "server1.example.com"; |
||||||
|
option routers ${ipaddr%.*}.1; |
||||||
|
option broadcast-address ${ipaddr%.*}.255; |
||||||
|
default-lease-time 600; |
||||||
|
max-lease-time 7200; |
||||||
|
|
||||||
|
# PXE SERVER IP |
||||||
|
next-server ${ipaddr%/*}; # DHCP server ip |
||||||
|
filename "pxelinux.0"; |
||||||
|
} |
||||||
|
EOF |
||||||
|
|
||||||
|
# 配置tftp |
||||||
|
color Info "配置tftp" |
||||||
|
cat > /etc/xinetd.d/tftp << EOF |
||||||
|
service tftp |
||||||
|
{ |
||||||
|
socket_type = dgram |
||||||
|
protocol = udp |
||||||
|
wait = yes |
||||||
|
user = root |
||||||
|
server = /usr/sbin/in.tftpd |
||||||
|
server_args = -s /tftpboot |
||||||
|
disable = no |
||||||
|
per_source = 11 |
||||||
|
cps = 100 2 |
||||||
|
flags = IPv4 |
||||||
|
} |
||||||
|
EOF |
||||||
|
|
||||||
|
# 配置vsftpd |
||||||
|
color Info "配置vsftpd" |
||||||
|
cp /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /var/lib/tftpboot/ |
||||||
|
mkdir /var/lib/tftpboot/pxelinux.cfg |
||||||
|
mkdir /var/lib/tftpboot/netboot |
||||||
|
mount /dev/cdrom /mnt |
||||||
|
cp -rvf /mnt/* /var/ftp/pub |
||||||
|
|
||||||
|
cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/netboot/ |
||||||
|
cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/netboot/ |
||||||
|
|
||||||
|
cat > /var/ftp/pub/ks.cfg <<EOF |
||||||
|
#platform=x86, AMD64, or Intel EM64T |
||||||
|
#version=DEVEL |
||||||
|
# Firewall configuration |
||||||
|
firewall --disabled |
||||||
|
# Install OS instead of upgrade |
||||||
|
install |
||||||
|
# Use NFS installation media |
||||||
|
url --url="ftp://${ipaddr%/*}/pub/" |
||||||
|
rootpw --plaintext 123456 |
||||||
|
#root的密码设为123456 |
||||||
|
# Use graphical install |
||||||
|
graphical |
||||||
|
firstboot disable |
||||||
|
# System keyboard |
||||||
|
keyboard us |
||||||
|
# System language |
||||||
|
lang en_US |
||||||
|
# SELinux configuration |
||||||
|
selinux disabled |
||||||
|
# Installation logging level |
||||||
|
logging level=info |
||||||
|
# System timezone |
||||||
|
timezone Asia/Shanghai |
||||||
|
# System bootloader configuration |
||||||
|
bootloader location=mbr |
||||||
|
clearpart --all --initlabel |
||||||
|
part swap --asprimary --fstype="swap" --size=1024 |
||||||
|
part /boot --fstype xfs --size=200 |
||||||
|
part pv.01 --size=1 --grow |
||||||
|
volgroup rootvg01 pv.01 |
||||||
|
logvol / --fstype xfs --name=lv01 --vgname=rootvg01 --size=1 --grow |
||||||
|
reboot |
||||||
|
|
||||||
|
%packages |
||||||
|
@core |
||||||
|
wget |
||||||
|
lsof |
||||||
|
net-tools |
||||||
|
vim |
||||||
|
%end |
||||||
|
|
||||||
|
%post |
||||||
|
# curl -s -L https://download.beyourself.org.cn/shell-project/os/get-os-init.sh | sh |
||||||
|
%end |
||||||
|
EOF |
||||||
|
|
||||||
|
# 配置启动项 |
||||||
|
color Info "配置启动项" |
||||||
|
cat >/var/lib/tftpboot/pxelinux.cfg/default <<EOF |
||||||
|
default menu.c32 |
||||||
|
prompt 0 |
||||||
|
timeout 30 |
||||||
|
MENU TITLE Togogo.net Linux Training |
||||||
|
|
||||||
|
LABEL centos7_x64 |
||||||
|
MENU LABEL CentOS 7 X64 for newrain |
||||||
|
KERNEL /netboot/vmlinuz |
||||||
|
APPEND initrd=/netboot/initrd.img inst.repo=ftp://${ipaddr%/*}/pub ks=ftp://${ipaddr%/*}/pub/ks.cfg |
||||||
|
EOF |
||||||
|
|
||||||
|
# 启动服务 |
||||||
|
color Info "启动服务" |
||||||
|
systemctl enable dhcpd vsftpd tftp |
||||||
|
systemctl restart dhcpd vsftpd tftp |
Loading…
Reference in new issue