Centos7一键搭建kvm环境

1、自动检测是否支持硬件虚拟化
2、自动创建br0、br1网桥,用于内网和外网
3、自动安装kvm所需组件


取消网卡自动改名

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

export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"

egrep '(vmx|svm)' /proc/cpuinfo
[ $? -ne 0 ] && echo "Hardware virtualization is not supported" &&exit 1
yum install -y wget
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
yum makecache
yum install -y net-tools vim lrzsz tree screen lsof tcpdump
systemctl disable firewalld
systemctl stop firewalld
systemctl disable NetworkManager
systemctl stop NetworkManager
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 update -y && reboot
hostnamectl --static set-hostname kvm-node1
cat > /etc/sysconfig/network-scripts/ifcfg-br0 <<EOF
TYPE="Bridge"
BOOTPROTO="static"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
IPADDR="192.168.7.68"
NETMASK="255.255.248.0"
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-br1 <<EOF
TYPE="Bridge"
BOOTPROTO="static"
NAME="br1"
DEVICE="br1"
ONBOOT="yes"
IPADDR="172.16.7.68"
NETMASK="255.255.255.0"
EOF

mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.bak

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth0"
BRIDGE="br0"
DEVICE="eth0"
ONBOOT="yes"
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth1"
BRIDGE="br1"
DEVICE="eth1"
ONBOOT="yes"
EOF

yum -y install kvm
lsmod | grep kvm

yum -y install python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-install virt-v2v libguestfs-tools acpid

[ $? -eq 0 ] && echo "Success!"

转载于Ropon运维博客–https://www.idiyrom.com/14.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值