1、安装kvm:
yum -y install kvm qemu qemu-kvm
yum -y install libvirt virt-install virt-viewer libpk-gtk-module.so virt-manager
2、桥接:
2.1 编辑网卡
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
BRIDGE=br0
NM_CONTROLLED=no# vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.200.15
NETMASK=255.255.255.0
GATEWAY=192.168.200.1
DNS1=202.106.0.20
NM_CONTROLLED=no
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
BRIDGE=br0
NM_CONTROLLED=no# vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.200.15
NETMASK=255.255.255.0
GATEWAY=192.168.200.1
DNS1=202.106.0.20
NM_CONTROLLED=no
2.2 重启网络
service network restart
或者重启系统,和可能重启网络重启不起来
3、创建镜像
systemctl restart libvirtd
qemu-img create -f qcow2 /data/kvm/centos-7.5-qcow2.img 15G
virt-install –name=centos1804 –os-variant=RHEL7 –ram 2048 –vcpus=1 –disk path=/data/kvm/centos-7.5-qcow2.img,size=15,bus=virtio –accelerate –cdrom /data/CentOS-7-x86_64-Minimal-1804.iso –vnc –vncport=5910 –network bridge=br0 –noautoconsole
然后用vnc连接5910端口即可,然后安装系统[安装系统环节略,默认vnc监听127.0.0.1:5910,连接方式不赘述;也可以修改/etc/libvirt/qemu.conf修改vnc_listen = “0.0.0.0”]
4、制作模板
virsh list –all
virsh start centos1708
然后重新用vnc的5910端口上去
rm -f /etc/udev/rules.d/70-*
rm -f /var/log/*
history -c && history -w
init 0
5、在openstack的controller上面创建镜像
将img传到openstack上
openstack image create “centos1804″ –file /data/kvm/centos-7.5-qcow2.img –disk-format qcow2 –container-format bare –public
然后查看:
openstack image list