一.安装准备
1.家里一台台式机系统win10专业版,(内存8gi5的核),bios中开启vt-x和intel虚拟化,win10系统服务关闭自带的hyper-v虚拟机(不关闭会导致无法安装32位系统)。
后来我建立的虚拟机都不支持全虚拟化排除了以上两个原因,后来发现由于我的win10系统本身不支持嵌套虚拟化,才导致我的虚拟机不支持kvm。
可以使用cat /proc/cpuinfo |egrep 'svm|vmx'来确认是否支持虚拟化。amd cpu返回svm,intel cpu返回vmx。
2.安装virtualbox,安装vagrant,安装bitvise ssh client。
二.虚拟机建立
- 下载vagrant box,我下载的是centos 7.2。使用迅雷离线下载再拖到本地可以加快下载。
- 生成虚拟机。新建vagrant目录,比如f:\vagrantWork
添加box
vagrant add centos7 f:/vagrantWork/centos7.2-x86_64.box
列出存在的box
vagrant box list
生成vagrantfile
vagrant init
使用如下配置同时生成两个虚拟机,rubby语言写的配置文件明白如话。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
#指定box
config.vm.box = "centos7"
node_servers = { :control => ['10.0.0.101','192.168.15.101','192.168.0.125'],
:compute => ['10.0.0.102','192.168.15.102','192.168.0.126']
}
node_servers.each do |node_name,node_ip|
config.vm.define node_name do |node_config|
node_config.vm.host_name = node_name.to_s
node_config.vm.network :private_network,ip: node_ip[0]
node_config.vm.network :private_network,ip: node_ip[1],virtualbox_inet: true
node_config.vm.network :public_network,ip: node_ip[2],virtualbox_inet: true
config.vm.boot_timeout = 300
node_config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 1
end
end
end
end
我给两台机器配了3个网卡,两个私有网络,一个公共网络。设置这个公共网络是为了让我的局域网中另一台笔记本能够ssh登录到这两个虚拟机。
官方文档给出的controller节点最小内存4g,compute节点最小内存2g,这里都给分配了4g。
建立这两个虚拟机
vagrant up controller compute
- 虚拟机的初始配置。
通过控制台输出可以发现,vagrant将两个虚拟机的ssh端口映射到了本地的2222和2220端口,通过.vagrant目录里可以找到私钥,通过vagrant账户和私钥可以初次登录到该虚拟机。
登陆后sudo -i切换到root用户,输入passwd设定登录密码。
这时我发现如果输入ip addr发现网络配置中的三个网卡都不工作,于是必须service network restart才能确保三个网卡都工作。
这也就是为什么我后来不将那些openstack服务添加到开机服务中去的原因,
因为网络都没准备好,openstack服务肯定启动出问题。也不知道我这个是不是特例,因为条件有限我只能在自家电脑上尝试,不知道换个环境开机网络配置会不会正常。
(通过利用开机服务优先级顺序让网络重启先于openstack服务进行应可以解决这个问题)。
替换为阿里云源,并更新本地仓库
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 update -y
关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
三.openstack之网络配置
- 选择网络选项。文档给出了两种网络选项,一种是提供者网络,另一种是私有网络。私有网络比提供者网络能够提供如LBaas,FWaaS等高级,一个能用VXLAN一个不能用VXLAN。为了简便起见选用提供者网络。
- 网卡配置。无论是选项一还是选项二,controller和compute都至少需要两块网卡,一块是管理网络网段(我选用10.0.0.1/24),另一块是提供者网段(我选用192.168.15.1/24)
对controller节点,编辑/etc/sysconfig/network-scripts/目录下提供者网络接口对应的文件,我的文件是ifcfg-enp0s9,更改如下值
DEVICE=enp0s9
TYPE=Ethernet
ONBOOT="yes"
BOOTPROTO="none"
对compute节点,编辑/etc/sysconfig/network-scripts/目录下提供者网络接口对应的文件,我的文件是ifcfg-enp0s9,更改如下值
DEVICE=enp0s9
TYPE=Ethernet
ONBOOT="yes"
BOOTPROTO="none"
- 对controller compute修改本地host文件/etc/hosts,添加controller和compute的名称解析。
# controller
10.0.0.101 controller
# compute1
10.0.0.31 compute
使用service network restart 使配置生效。