#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '7s/enforcing/disabled' /etc/selinux/config
yum install dhcp -y
ip=`ip a | grep ens33 | awk 'NR==2''{print $2}' | awk -F'/' '{print $1}'`
cat >>/etc/dhcp/dhcpd.conf<<EOF
subnet ${ip%.*}.0 netmask 255.255.255.0 {
range ${ip%.*}.10 ${ip%.*}.100;
option domain-name-servers ${ip%.*}.1;
option routers ${ip%.*}.1;
default-lease-time 600;
max-lease-time 7200;
next-server $ip; # #TFTP Server 的IP地址,也就是本机
filename "pxelinux.0"; # pxelinux 启动文件位置;
}
EOF
#${ip%.*} 中的 % 表示从变量 ip 的值中删除匹配 .* 模式的最小部分(即最后一个点及其后面的内容)。
systemctl start dhcpd; systemctl enable dhcpd
yum install tftp-server -y
yum install syslinux -y
mkdir -pv /mnt/centos/
mount /dev/cdrom /mnt/centos/
cd /var/lib/tftpboot/
cp -a /mnt/centos/isolinux/boot.msg ./
cp -a /mnt/centos/images/pxeboot/{initrd.img,vmlinuz} ./
cp -a /usr/share/syslinux/pxelinux.0 ./
mkdir pxelinux.cfg
cd pxelinux.cfg/
cp -a /mnt/centos/isolinux/isolinux.cfg ./default
umount /mnt/centos/
cat >> /var/lib/tftpboot/pxelinux.cfg/default<<EOF
default ks
prompt 1
timeout 6
display boot.msg
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
menu helpmsgrow 15
menu tabmsgrow 13
menu color border * #00000000 #00000000 none
menu color sel 0 #ffffffff #00000000 none
menu color title 0 #ff7ba3d0 #00000000 none
menu color tabmsg 0 #ff3a6496 #00000000 none
menu color unsel 0 #84b8ffff #00000000 none
menu color hotsel 0 #84b8ffff #00000000 none
menu color hotkey 0 #ffffffff #00000000 none
menu color help 0 #ffffffff #00000000 none
menu color scrollbar 0 #ffffffff #ff355594 none
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
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 CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
label check
menu label Test this ^media & install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
menu separator # insert an empty line
menu begin ^Troubleshooting
menu title Troubleshooting
label vesa
menu indent count 5
menu label Install CentOS 7 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
CentOS 7.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet
label ks
kernel vmlinuz
append initrd=initrd.img ks=http://$ip/ks.cfg
label rescue
menu indent count 5
menu label ^Rescue a CentOS system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet
label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
EOF
systemctl start tftp; systemctl enable tftp
yum install httpd -y
mkdir -pv /var/www/html/centos/
mount /dev/cdrom /var/www/html/centos/
systemctl start httpd ;systemctl enable httpd
cat >> /var/www/html/ks.cfg<<EOF
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://$ip/centos" ##### 这里需要手动修改为自己主机的http链接
# Root password
rootpw --iscrypted $1$x1wkiXJv$45UMW./5aUCEkfymzt4WQ/ #### 默认root密码为:123456
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --utc Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
#bootloader --location=gpt
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part biosboot --fstype=biosboot --size=1
part /boot/efi --fstype="efi" --ondisk=sda --size=1024 --fsoptions="defaults,uid=0,gid=0,umask=0077,shortname=winnt"
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=1000
part pv.01 --size=1 --grow
volgroup vg00 pv.01
logvol / --vgname=vg00 --size=8192 --name=lv_root
%pre
parted -s /dev/sda mklabel gpt
%end
%packages
openssh-clients
@core
%end
EOF
systemctl status tftp httpd dhcpd
pxe+kickstart 无人值守安装及自动化运维------脚本
最新推荐文章于 2024-08-13 23:05:14 发布