yum install -y kvm virt-* libvirt bridge-utils qemu-img
是否加载模块
lsmod |grep kvm
编辑网卡
[root@node01 ~]# cd /etc/sysconfig/network-scripts/
[root@node01 network-scripts]# cp ifcfg-eth0 ifcfg-br0
[root@node01 network-scripts]# vim ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
[root@node01 network-scripts]# vim ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.2.71
PREFIX=24
GATEWAY=192.168.2.1
DNS1=192.168.2.1
重启网络
启动或重启libvirtd服务和messagebus 服务
[root@node01 ~]# /etc/init.d/libvirtd start
Starting libvirtd daemon:
[root@node01 ~]# /etc/init.d/messagebus restart
Stopping system message bus: [ OK ]
Starting system message bus: [ OK ]
此时可以查看网络接口列表
[root@node01 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29af5025 no eth0
virbr0 8000.52540085962c yes virbr0-nic
添加额外的分区
[root@node01 ~]# virt-install --name redhat6.7_1 --ram 512 --disk path=/data/redhat6.7_1.img,size=30 --vcpus 1 --os-type linux --os-variant rhel6 --network bridge=br0 --graphics none --console pty,target_type=serial --location 'http://mirrors.aliyun.com/centos/6.9/os/x86_64/' --extra-args 'console=ttyS0,115200n8 serial'
配置网络
完成
本地安装
root@node01 data]# qemu-img create -f qcow2 -o preallocation=metadata /data/test02.qcow2 7G
Formatting '/data/test02.qcow2', fmt=qcow2 size=7516192768 encryption=off cluster_size=65536 preallocation='metadata'
[root@node01 ~]# virt-install --name redhat6.7_2 --ram 512 --disk path=/data/test02.qcow2,format=qcow2,size=10,bus=virtio --vcpus 1 --os-type linux --os-variant rhel6 --network bridge=br0 --graphics none --console pty,target_type=serial --location '/mnt/' --extra-args 'console=ttyS0,115200n8 serial'
查看机器
[root@node01 ~]# virsh list --all
Id Name State
----------------------------------------------------
2 redhat6.7_1 running
4 redhat6.7_2 running