1 准备模板机
具体步骤如下:
1. 下载镜像安装系统
https://mirrors.aliyun.com/CentOS/7.5.1804/isos/x86_64/
2. 安装完成配置好IP ,关闭SELINUX ,关闭firewalld ,修改网卡名
3. 预设置好修改其他机器IP脚本
1.1 安装系统
略
1.2 模板机的设置
修改网卡名eth0
# 当前系统版本
[root@localhost ~]# cat /etc/RedHat-release
CentOS Linux release 7.2.1511 (Core)
# 修改网卡配置文件为eth0
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# mv ifcfg-enxxxx eth0
# 修改为静态ip
[root@localhost network-scripts]# cat ifcfg-eth0
TYPE="Ethernet"
BOOTPROTO="static"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=10.0.0.79
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=10.0.0.2
# 禁用该可预测命名规则
# 在 grup 文件里面的 GRUB_CMDLINE_LINUX 变量添加 net.ifnames=0 biosdevname=0
[root@localhost ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
#运行命令重新生成GRUB配置并更新内核参数
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-692c580a413f41d8b51ddc4724500560
Found initrd image: /boot/initramfs-0-rescue-692c580a413f41d8b51ddc4724500560.img
done
关闭selinux
[root@localhost ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
[root@localhost ~]# egrep -v "^#|^$" /etc/sysconfig/selinux
SELINUX=disabled
SELINUXTYPE=targeted
关闭firewalld
[root@localhost ~]# systemctl disable firewalld.service
重启系统
[root@localhost ~]# reboot
然后给批量创建虚拟机设置自定义的IP和主机名的脚本
[root@localhost ~]# cat /root/first.sh
#!/bin/bash
#Author:keme
#Blog:https://www.cnblogs.com/keme
#Time:2018-11-23
#Name:first.sh
#Version:V1.0
#Description:This is a test script.
ip=$1
hostname=$2
if [ $# -ne 2 ]
then
echo "sh $0 ip hostname"
fi
set_ip(){
sed -ri "/IPADDR/s#(.*.)\..*#\1.${ip}#" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -ri "/IPADDR/s#(.*.)\..*#\1.${ip}#" /etc/sysconfig/network-scripts/ifcfg-eth1
echo "=============================================="
echo "now you can running : service network restart"
service network restart
}
set_hostname(){
sed -i "s#.*#${hostname}#" /etc/hostname
hostnamectl set-hostname ${hostname}
echo "=============================================="
echo "hostname is : $(cat /etc/hostname)"
echo "=============================================="
}
main(){
set_ip
set_hostname
}
main
[root@localhost ~]# chmod +x /root/first.sh
关机创建快照
2 目录规划模板虚拟机所在目录
2.1 模板机所在目录E:\VMS\Centos7\template
3 vmrun结合脚本批量创建虚拟机vmrun.exe 程序
git 软件
编写脚本
设置IP 的脚本
3.1 vmrun.exe找到vmrun.exe 程序
创建一个E:\SOFT\VM文件夹复制到新创建的文件夹
vmrun使用
https://www.linuxidc.com/Linux/2019-01/156357.htm
3.2 git 软件作用方便使用linux 的shell 命令
3.3 编写脚本auto_VM.sh内容如下