04.KVM实现自动化创建虚拟机.md
1、查看支持的os的两个cli
virt-install --osinfo list
osinfo-query os

这是win2016 2008这下👇


# ===============================
# 基础安装方式
# ===============================
install
text
reboot
cdrom
# ===============================
# 语言 / 键盘 / 时区
# ===============================
lang zh_CN.UTF-8
keyboard us
timezone Asia/Shanghai --isUtc
# ===============================
# 网络(DHCP,生产建议装后再改)
# ===============================
network --bootproto=dhcp --device=eth0 --onboot=on
# ===============================
# Root 密码(建议上线后立刻改)
# ===============================
rootpw --plaintext ChangeMe123!
# ===============================
# SELinux / 防火墙(生产推荐)
# ===============================
selinux --permissive
firewall --enabled --service=ssh
# ===============================
# 启动器
# ===============================
bootloader --location=mbr
# ===============================
# 磁盘分区(生产常用)
# ===============================
zerombr
clearpart --all --initlabel
part /boot --fstype=xfs --size=1024
part swap --size=8192
part pv.01 --grow
volgroup vg0 pv.01
logvol / --vgname=vg0 --size=20480 --name=root --fstype=xfs
logvol /var --vgname=vg0 --size=20480 --name=var --fstype=xfs
logvol /data --vgname=vg0 --grow --name=data --fstype=xfs
# ===============================
# 软件包
# ===============================
%packages
@^minimal-environment
@core
vim
wget
curl
bash-completion
net-tools
bind-utils
chrony
rsyslog
lsof
tcpdump
htop
git
-audio
-plymouth
%end
# ===============================
# 安装后配置
# ===============================
%post --log=/root/ks-post.log
# 设置时钟
systemctl enable chronyd
systemctl start chronyd
# SSH 基础加固
sed -i 's/^#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd
# 提高文件句柄
cat >> /etc/security/limits.conf <<EOF
* soft nofile 1048576
* hard nofile 1048576
* soft nproc 65535
* hard nproc 65535
EOF
# sysctl 常用优化
cat > /etc/sysctl.d/99-prod.conf <<EOF
net.ipv4.ip_forward = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 65535
fs.file-max = 2097152
vm.swappiness = 10
EOF
sysctl --system
%end