Centos7环境下制作kvm模板
程序员文章站
2024-03-11 10:40:43
...
取消网卡自动改名
cat > /etc/sysconfig/grub <<EOF
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb net.ifnames=0 biosdevname=0 quiet"
GRUB_DISABLE_RECOVERY="true"
EOF
grub2-mkconfig -o /boot/grub2/grub.cfg
接下来创建一个虚拟机制作模板
#!/bin/bash
[ ! -d /vmdata ] && mkdir /vmdata
[ ! -d /vmdata/iso ] && mkdir -p /vmdata/iso
dd if=/dev/cdrom of=/vmdata/iso/centos7.iso
qemu-img create /vmdata/template/template_os 10G
qemu-img create /vmdata/template/template_data 10G
virt-install --virt-type kvm --name=template --ram=512 --vcpus=1 --cdrom=/vmdata/iso/centos7.iso --network bridge=br0 --network bridge=br1 --noautoconsole --os-type=linux --os-variant=rhel7 --disk path=/vmdata/template/template_os,bus=virtio,cache=writeback --autostart --graphics vnc,listen=0.0.0.0,password=test1234 --boot cdrom,hd,menu=on --accelerate
vnc登录安装系统,vnc密码:test1234,不要使用lvm方式安装,使用标准分区,然后点击自动创建分区安装
安装系统完成后对模板做调整
#!/bin/bash
systemctl disable firewalld #禁用自启服务
systemctl stop firewalld
systemctl disable NetworkManager #禁用自启服务
systemctl stop NetworkManager
getenforce #查看状态
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0 #临时关闭服务
echo ' * - nofile 100000 ' >>/etc/security/limits.conf
yum -y install wget net-tools
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
hostnamectl --static set-hostname template
cat > /etc/sysconfig/network <<EOF
GATEWAY=192.168.0.1
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=
NETMASK=255.255.248.0
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=
NETMASK=255.255.255.0
EOF
cat > /etc/resolv.conf <<EOF
nameserver 119.29.29.29
EOF
cat > /root/set.sh <<EOF
#!/bin/bash
(echo "passwdtemp";sleep 1;echo "passwdtemp") | passwd > /dev/null
hostnamectl --static set-hostname vmnametemp
sed -i "s/\/root\/set.sh//g" /etc/rc.d/rc.local
rm $0
reboot
EOF
chmod +x /root/set.sh
chmod +x /etc/rc.d/rc.local
ls -la /root/set.sh
ls -la /etc/rc.d/rc.local
转载于Ropon运维 – https://www.idiyrom.com/16.html
上一篇: centos7安装python3环境
下一篇: PHP实现的简单排列组合算法应用示例