Openstack版本:openstack-queen 版本
一、环境准备
网络规划:
Management + API Network:10.10.11.0/24 eth1 网桥:br1
VM (Tenant Network: 10.10.12.0/24 eth2 网桥:br2
External Network: 10.10.10.0/24 eth0 网桥vbr
集群环境:Centos7.4 x86_64
Controller: 2C + 8G + 50G eth0 eth1 eth2
Compute1:2C + 8G + 50G eth0 eth1
Neutron: 2C + 8G + 50G eth0 eth1
Cinder: 2C + 8G + 50G eth0 eth1
附加节点 为集群提供本地yum源
Yum节点: 2C + 8G + 50G eth0 网桥:br1 IP:10.10.11.200
二、搭建网桥
2.1 创建网桥文件
创建网桥文件:vbr.xml
networks]# cd /etc/libvirt/qemu/networks/
networks]# cat vbr.xml
<network>
<name>vbr</name>
<forward mode='nat'/>
<bridge name='vbr' stp='on' delay='0'/>
<ip address='10.10.10.1' netmask='255.255.255.0'>
<dhcp>
<range start='10.10.10.10' end='10.10.10.254'/>
</dhcp>
</ip>
</network>
创建网桥文件:br1.xml
networks]# cat br1.xml
<network>
<name>br1</name>
<bridge name='br1' stp='on' delay='0'/>
<ip address='10.10.11.1' netmask='255.255.255.0'>
<dhcp>
<range start='10.10.11.10' end='10.10.11.254'/>
</dhcp>
</ip>
创建网桥文件:br2.xml
networks]# cat br2.xml
<network>
<name>br2</name>
<uuid>f06b24c9-963b-4239-a75a-25d4814df099</uuid>
<ip address='10.10.12.1' netmask='255.255.255.0'>
<dhcp>
<range start='10.10.12.10' end='10.10.12.254'/>
</dhcp>
</ip>
</network>
2.2 启用网桥
定义:
networks]# for i in `ls *.xml`
> do
> virsh net-define $i
> done
Network br1 defined from br1.xml
Network br2 defined from br2.xml
Network vbr defined from vbr.xml
启动:
networks]# for i in vbr br1 br2
> do
> virsh net-start $i
> done
开机自启:
networks]# for i in vbr br1 br2
> do
> virsh net-autostart $i
> done
Network vbr marked as autostarted
Network br1 marked as autostarted
Network br2 marked as autostarted
ifconfig 可见:
三、创建4台虚拟机
3.1 准备 镜像模板 + 虚拟机定义文件
提前准备好:node.qcow2 和node.xml 并作对应修改,否则无法使用:
node.xml关键信息:
qemu]# cd /etc/libvirt/qemu/
qemu]# cat node.xml | grep "<name>"
<name>node</name>
qemu]# cat node.xml | grep "<memory"
<memory unit='KiB'>8848000</memory>
qemu]# cat node.xml | grep "<currentMemory"
<currentMemory unit='KiB'>8848000</currentMemory>
qemu]# cat node.xml | grep "<source file"
<source file='/var/lib/libvirt/images/node.img'/>
3.2 创建脚本 build.sh
sh]# ls
build.sh
sh]# cat build.sh
#!/bin/bash
read -p "How many VMs do you want:" Num
for((i=1;i<=$Num;i++));
do
read -p "Name:" name
cd /var/lib/libvirt/images
qemu-img create -f qcow2 -b node.qcow2 $name.img 50G
cd /etc/libvirt/qemu
sed "s,node,$name," node.xml > $name.xml
virsh define $name.xml
done
3.3 创建虚拟机
sh]# bash build.sh
How many dou you want:4
Name:controller
Formatting 'controller.img', fmt=qcow2 size=53687091200 backing_file='node.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
Domain controller defined from controller.xml
Name:compute1
Formatting 'compute1.img', fmt=qcow2 size=53687091200 backing_file='node.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
Domain compute1 defined from compute1.xml
Name:neutron
Formatting 'neutron.img', fmt=qcow2 size=53687091200 backing_file='node.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
Domain neutron defined from neutron.xml
Name:cinder
Formatting 'cinder.img', fmt=qcow2 size=53687091200 backing_file='node.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
Domain cinder defined from cinder.xml
sh]# virsh list --all
Id Name State
----------------------------------------------------
1 yum running
- cinder shut off
- compute1 shut off
- controller shut off
- neutron shut off
3.4 根据配置分别给虚拟机添加网卡
打开virt-manager,这里只演示给controller添加网卡:
添加vbr:
添加br1:
添加br2:
其他主机一样,不需要添加vbr,只需要添加br1和br2。
启动虚拟机:
]# for i in controller compute1 neutron cinder
> do
> virsh start $i
> done