Centos7环境下制作kvm模板

作者: ropon 分类: Kvm 发布时间: 2017-04-13 23:24

首先创建一个虚拟机安装模板系统

以下自动化shell脚本,需要注意的是:vnc登录安装系统,vnc密码:ropon.top,不要使用lvm方式安装,使用标准分区,然后点击自动创建分区安装

#!/bin/bash
#centos7模板优化自动化shell脚本

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=
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=
NETMASK=
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=
NETMASK=
EOF
cat > /etc/resolv.conf <<EOF
nameserver 119.29.29.29
nameserver 114.114.114.114
EOF

echo "#!/bin/bash
umount /home
fdisk -S 56 /dev/vdb << EOF
d
n
p
1


wq
EOF
resize2fs -f /dev/vdb1
mount -a" >> /root/disk.sh

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
tempdata=tempdisksize
if [ $tempdata -gt 0 ];then
	/root/disk.sh
	sleep 1
	rm -rf /root/disk.sh
fi
rm /root/set.sh
reboot
EOF

chmod +x /root/set.sh
chmod +x /root/disk.sh
chmod +x /etc/rc.d/rc.local
ls -la /root/set.sh
ls -la /etc/rc.d/rc.local

fdisk -S 56 /dev/vdb << EOF
n
p
1


wq
EOF
mkfs.ext4 /dev/vdb1
echo "/dev/vdb1			/home		ext4 		defaults	0 	0" >> /etc/fstab
mount -a
df -vh

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
rm -f /etc/udev/rules.d/*persistent-net.rules
history -c
rm -f $0
echo "success"
init 0

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注