master
root 3 months ago
parent 673f8c2e11
commit 746e9f85d0
  1. 3
      control/KVMInstall.sh
  2. 5
      control/VMHost.sh
  3. 5
      control/VMTemplate.sh
  4. 59
      control/ks.cfg
  5. 59
      control/ks.cfg.temp
  6. 3
      template/template.xml

@ -62,8 +62,9 @@ BRIDGE=br0
EOF
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf && sysctl -p
systemctl enable libvirtd --now
brctl stp br0 on
color Success "安装并启动完成"
systemctl restart network
}
main
main

@ -110,6 +110,11 @@ done
if [ ! -d ${MOUNT_PATH} ];then
mkdir -p ${MOUNT_PATH}
fi
status=$(virsh list | awk '$2 ~ /^template$/{print "yes"}')
if [ "$status" = "yes" ];then
echo "正在关闭模板服务器"
fi
qemu-img create -f qcow2 -b ${TEMPLATE_PATH}/${TEMPLATE_IMAGE_NAME} ${VDISKS_PATH}/${VM_HOSTNAME}.qcow2
rm -rf ${MOUNT_PATH}/*
guestmount -a ${VDISKS_PATH}/${VM_HOSTNAME}.qcow2 -m /dev/centos/root ${MOUNT_PATH}

@ -13,6 +13,8 @@ VM_TEMPLATE_NAME=template
VM_MEMORY=2050 # 不能低于2G,单位为M
VM_DISK_SIZE=5 # 单位为G
VM_DISK_PATH=${MAIN_PATH}/template/${VM_TEMPLATE_NAME}.qcow2
VM_PASSWORD=123456
VM_JUMPSERVER_HOST=10.36.176.155
cpus=`lscpu | awk '/^CPU\(s\):/{print $2}'`
if [ $VM_CPUS -ge $cpus ]; then
@ -25,4 +27,5 @@ if [ $VM_MEMORY -ge $memory ]; then
exit 1
fi
virt-install --connect qemu:///system -n ${VM_TEMPLATE_NAME} -r ${VM_MEMORY} --disk path=${VM_DISK_PATH},size=${VM_DISK_SIZE} --os-type=linux --os-variant=centos7.0 --vcpus=${VM_CPUS} --location=${IMAGE_PATH} -x console=ttyS0 --nographics
sed "s/PASSWORD/${VM_PASSWORD}/g;s/JUMPSERVER_HOST/${VM_JUMPSERVER_HOST}/g" ./ks.cfg.temp > ks.cfg
virt-install --connect qemu:///system -n ${VM_TEMPLATE_NAME} -r ${VM_MEMORY} --disk path=${VM_DISK_PATH},size=${VM_DISK_SIZE} --os-type=linux --os-variant=centos7.0 --network bridge=br0 --vcpus=${VM_CPUS} --location=${IMAGE_PATH} -x "console=ttyS0" --nographics --initrd-inject ${MAIN_PATH}/control/ks.cfg --extra-args="ks=file:ks.cfg"

@ -0,0 +1,59 @@
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
network
network --bootproto dhcp
firewall --disabled
# Root password configuration
rootpw --plaintext 123456
#url --url=https://mirrors.mit.edu/centos/7.9.2009/os/x86_64/
# Use graphical install
#graphical
# Firstboot configuration
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=gpt
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
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 after installation
shutdown
%packages --ignoremissing
@core
%end
%post
# Add local DNS resolution
rm -rf /etc/yum.repos.d/*
curl https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/kvm-repo.sh |repo=10.35.187.67 sh
yum install -y python3 python3-devel gcc
echo "10.36.176.155 jumpserver.server" >> /etc/hosts
pip3 install requests httpsig -i https://mirrors.aliyun.com/pypi/simple
%end

@ -0,0 +1,59 @@
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
network
network --bootproto dhcp
firewall --disabled
# Root password configuration
rootpw --plaintext PASSWORD
#url --url=https://mirrors.mit.edu/centos/7.9.2009/os/x86_64/
# Use graphical install
#graphical
# Firstboot configuration
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=gpt
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
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 after installation
shutdown
%packages --ignoremissing
@core
%end
%post
# Add local DNS resolution
rm -rf /etc/yum.repos.d/*
curl https://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master/os/kvm-repo.sh |repo=10.35.187.67 sh
yum install -y python3 python3-devel gcc
echo "JUMPSERVER_HOST jumpserver.server" >> /etc/hosts
pip3 install requests httpsig -i https://mirrors.aliyun.com/pypi/simple
%end

@ -1,5 +1,5 @@
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit template
or other application using the libvirt API.
@ -104,3 +104,4 @@ or other application using the libvirt API.
</rng>
</devices>
</domain>

Loading…
Cancel
Save