目的就是分享openstack 的安装文档,
同时 我自己试验,感谢陈沙克老师的博客。因为下定决心学一门新的技术或者做一件事不容易。
这个文档是描述Openstack Essex安装,把所有的服务安装在一台机器上。包括组件Nova,Keystone, Glance, Dashboard.
基本介绍
Openstack的网络比较复杂,也很难理解。大家可以直接看
上图的例子:10.0.0.0/24, 是fix IP的网络。这是multihost=true的设置。这个图是可以很好帮助大家理解Openstack的网络。
我文档和这个图有点不一样,我是使用eth1做为bridge,而不是eth0
虚拟机间互相通讯,是直接通过br100通信
和外网通信,才需要通过另外一块网卡,floating IP
准备系统
安装ubuntu 12.04
最小化安装,只需要安装ssh server就可以。
apt-get update && apt-get -y dist-upgrade
设置网络
Eth0: 10.1.199.17
Eth1: 不需要设置IP
可根据自己的ip 自己调整
编辑 /etc/network/interfaces,需要注意一点是对于ubuntu 12.04,dns的设置,推荐在网卡设置。
auto loiface lo inet loopbackauto eth0iface eth0 inet staticaddress 10.1.199.17hwaddress ether 00:25:90:67:ce:64 (根据ifconfig 的网卡MAC 地址更改)netmask 255.255.255.0network 10.1.199.0gateway 10.1.199.1dns-search bgi.cnnameservers 8.8.8.8 (根据自己的dns 服务器设置)auto eth1iface eth1 inet manualup ifconfig eth1 up
查看当前网卡情况
# mii-tooleth0: negotiated 1000baseT-FD flow-control, link oketh1: negotiated 1000baseT-FD flow-control, link ok
设置hostname (可选)
这是我的习惯,Openstack基本是不需要使用hostname。大家可以忽略。(陈沙克)
# cat /etc/hostnamenode17# cat /etc/hosts127.0.0.1 localhost10.1.199.17 node17.chenshake.com node17# The following lines are desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allrouters# hostnamenode17# hostname -fnode17.chenshake.com
NTP服务器
对于单节点来说,NTP服务器,并不是必须的。如果是多台机器的环境。就需要设置所有的节点,都吧ntp服务指向相同的一个ntp服务器上。
apt-get -y install ntp
设置NTP
编辑 /etc/ntp.conf ,在 server ntp.ubuntu.com 下添加两行
server ntp.ubuntu.comserver 127.127.1.0fudge 127.127.1.0 stratum 10
或者直接运行下面命令
sed -i 's/server ntp.ubuntu.com/server ntp.ubuntu.com\nserver 127.127.1.0\nfudge 127.127.1.0 stratum 10/g' /etc/ntp.conf
重启NTP服务
#service ntp restart
上面设置 server 127.127.1.0 的含义,大家可以参考
设置ISCSI (可选)
这是为Nova-volume服务使用的。不过目前nova-volume并不稳定,大家测试一下就可以。未来的Folsom版本,将会有新的组件来替代Nova-volume。
如果你不测试nova volume,可以不安装
apt-get -y install tgt
nova-compute节点,需要安装ISCSI客户端
apt-get install -y open-iscsi open-iscsi-utils
Nova-volume (可选)
如果你没有单独的分区,那么就不建议你测试,采用文件模拟的方式,基本是不可行。
我安装系统的时候,创建了一个nova-volume的分区,我先umount,再创建一个volume,名字为nova-volumes。nova的默认使用的volume的名字就是叫 nova-volumes. 如果你希望改变,就需要指定在nova.conf 文件里。
查看分区情况
# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda8 623G 941M 591G 1% /udev 2.0G 4.0K 2.0G 1% /devtmpfs 790M 276K 789M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 2.0G 0 2.0G 0% /run/shm/dev/sda1 138M 30M 101M 23% /boot/dev/sda7 97G 188M 92G 1% /nova-volume/dev/sda6 97G 188M 92G 1% /swift
创建nova-volumes 卷
umount /dev/sda7pvcreate /dev/sda7vgcreate nova-volumes /dev/sda7
编辑 /etc/fstab , 注释掉nova-volumes开机加载,否则会导致你开机无法启动。我是安装过程,直接创建了一个nova-volume的分区
sed -i '/nova-volume/s/^/#/' /etc/fstab
Bridge
目前Openstack的网络是通过linux的bridge和iptables来实现的。
apt-get -y install bridge-utils
重启网络
/etc/init.d/networking restart
RabbitMQ和Memcache 等
RabbitMQ是用来做调度使用。Memcache是给Dashboard使用。
apt-get install -y rabbitmq-server memcached python-memcache kvm libvirt-bin curl
环境变量
大家经常参考文档安装不成功,基本都是因为你修改的IP地址或者你更改了我文档默认的密码。为了让文档更加灵活,所以需要设置一下环境变量。
你可以根据你的实际情况修改admin的密码和mysql的密码。下面文档和数据库相关的密码都是相同,你只需要修改novarc就可以。
运行完下面的命令,你再对novarc进行修改。
cat >/root/novarc <
根据你的需求进行调整,
我的novarc的内容
# cat novarcexport OS_TENANT_NAME=adminexport OS_USERNAME=adminexport OS_PASSWORD=passwordexport MYSQL_PASS=passwordexport SERVICE_PASSWORD=passwordexport FIXED_RANGE=10.0.0.0/24export FLOATING_RANGE=10.1.199.224/27export OS_AUTH_URL="http://localhost:5000/v2.0/"export SERVICE_ENDPOINT="http://localhost:35357/v2.0"export SERVICE_TOKEN=d5d892e6de00a922f9fbexport MASTER="10.1.199.17"
确认没有问题或者进行修改,运行
source novarcecho "source novarc">>.bashrc
MYSQL
在Openstack组件里,Nova,Keystone, Glance, 都需要用到数据库。所以我们需要创建相关的数据库和用户。
应用数据库 数据库用户 密码mysql root passwordnova nova passwordglance glance passwordkeystone keystone password
安装
mysql自动安装
cat <
Openstack都是Python写的,所以你需要python-mysqldb,安装过程,就不会提示你输入root密码
apt-get install -y mysql-server python-mysqldb
配置
编辑/etc/mysql/my.cnf, 允许网络访问mysql
#bind-address = 127.0.0.1bind-address = 0.0.0.0
或者直接运行下面命令
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
重启mysql服务
service mysql restart
创建相关数据库
mysql -uroot -p$MYSQL_PASS <
Keystone
Keystone是Openstack的核心,所有的组件,都需要通过keystone进行认证和授权。
租户(tenant) | 用户 | 密码 | |
admin | admin | password | |
service | nova | password | |
glance | password |
安装
apt-get install -y keystone python-keystone python-keystoneclient
配置
编辑/etc/keystone/keystone.conf,需要修改
keystone的默认token是ADMIN,我这里修改成随机生成,查看novarc获得
默认是采用sqlite连接,我们需要改成mysql
[DEFAULT]#bind_host = 0.0.0.0public_port = 5000admin_port = 35357#admin_token = ADMINadmin_token = d5d892e6de00a922f9fb[sql]#connection = sqlite:var/lib/keystone/keystone.dbconnection = mysql://keystone:password@10.1.199.17/keystone
或者运行下面命令,很多朋友都是因为修改错误导致错误,建议直接使用下面命令进行修改。
sed -i -e " s/admin_token = ADMIN/admin_token = $SERVICE_TOKEN/g" /etc/keystone/keystone.confsed -i '/connection = .*/{s|sqlite:///.*|mysql://'"keystone"':'"$MYSQL_PASS"'@'"$MASTER"'/keystone|g}' /etc/keystone/keystone.conf
重启服务
service keystone restart
同步keystone数据库
keystone-manage db_sync
keystone的数据库,需要导入数据和endpoint,你可以一步一步用命令行导入,可以参考
为了方便,你可以直接使用下面2个脚本来进行全部的设置。
导入用户信息
设置endpoint
Keystone Data
wget http://www.chenshake.com/wp-content/uploads/2012/07/keystone_data.sh_.txtmv keystone_data.sh_.txt keystone_data.shbash keystone_data.sh
没任何输出,就表示正确,可以通过下面命令检查
echo $?
显示0,就表示脚本正确运行,千万不要重复运行脚本。
Endpoint 导入
wget http://www.chenshake.com/wp-content/uploads/2012/07/endpoints.sh_.txtmv endpoints.sh_.txt endpoints.shbash endpoints.sh
需要注意的是,这个脚本是假设你的glance服务和swift都是安装相同的服务器,如果你的glance在不同的服务器,你需要调整一下endpoint,可以在数据库里调整。
测试
可以使用curl命令来测试。
命令的格式如下
curl -d '{"auth": {"tenantName": "adminTenant", "passwordCredentials":\{"username": "adminUser", "password": "secretword"}}}' -H "Content-type:\application/json" http://IP:35357/v2.0/tokens | python -mjson.toolIP: 注意这个是你的 主机IP你需要替换一下。
你需要替换一下。
curl -d '{"auth": {"tenantName": "admin", "passwordCredentials":{"username": "admin", "password": "password"}}}' -H "Content-type:application/json" http://$MASTER:35357/v2.0/tokens | python -mjson.tool
你就可以获得一个24小时的token。(注意,上面的脚本没有创建demo用户,所以没法用demo账号去测试)
"token": { "expires": "2012-09-27T02:09:37Z", "id": "c719448800214e189da04772c2f75e23", "tenant": { "description": null, "enabled": true, "id": "dc7ca2e51139457dada2d0f7a3719476", "name": "admin" }
通过下面命令,可以检查keystone的设置是否正确。
root@node17:~# keystone user-list+----------------------------------+---------+----------------------+--------+| id | enabled | email | name |+----------------------------------+---------+----------------------+--------+| 1189d15892d24e00827e707bd2b7ab07 | True | admin@chenshake.com | admin || cca4a4ed1e8842db99239dc98fb1617f | True | glance@chenshake.com | glance || daccc34eacc7493989cd13df93e7f6bc | True | swift@chenshake.com | swift || ee57b02c535d44f48943de13831da232 | True | nova@chenshake.com | nova |+----------------------------------+---------+----------------------+--------+ root@node17:~# keystone endpoint-list+----------------------------------+-----------+-----------------------------------------------+-----------------------------------------------+------------------------------------------+| id | region | publicurl | internalurl | adminurl |+----------------------------------+-----------+-----------------------------------------------+-----------------------------------------------+------------------------------------------+| 0b04e1baac1a4c9fb07490e0911192cf | RegionOne | http://10.1.199.17:5000/v2.0 | http://10.1.199.17:5000/v2.0 | http://10.1.199.17:35357/v2.0 || 0d3315627d52419fa08095f9def5d7e4 | RegionOne | http://10.1.199.17:8776/v1/%(tenant_id)s | http://10.1.199.17:8776/v1/%(tenant_id)s | http://10.1.199.17:8776/v1/%(tenant_id)s || 1c92290cba9f4a278b42dbdf2802096c | RegionOne | http://10.1.199.17:9292/v1 | http://10.1.199.17:9292/v1 | http://10.1.199.17:9292/v1 || 56fe83ce20f341d99fc576770c275586 | RegionOne | http://10.1.199.17:8774/v2/%(tenant_id)s | http://10.1.199.17:8774/v2/%(tenant_id)s | http://10.1.199.17:8774/v2/%(tenant_id)s || 5fb51aae00684e56818869918f86b564 | RegionOne | http://10.1.199.17:8080/v1/AUTH_%(tenant_id)s | http://10.1.199.17:8080/v1/AUTH_%(tenant_id)s | http://10.1.199.17:8080/v1 || aaac7663872d493b85d9e583329be9ed | RegionOne | http://10.1.199.17:8773/services/Cloud | http://10.1.199.17:8773/services/Cloud | http://10.1.199.17:8773/services/Admin |+----------------------------------+-----------+-----------------------------------------------+-----
可以使用下面命令来查看结果
keystone tenant-listkeystone user-listkeystone role-list
Glance
Glance是提供镜像管理服务,可以理解成一个中间件,后面的存储可以是本地存储,也可以使用swift存储。
安装
apt-get install -y glance glance-api glance-client glance-common glance-registry python-glance
配置
编辑 /etc/glance/glance-api-paste.ini,/etc/glance/glance-registry-paste.ini,两个文件,都是修改文档最后3行
#admin_tenant_name = %SERVICE_TENANT_NAME%#admin_user = %SERVICE_USER%#admin_password = %SERVICE_PASSWORD%admin_tenant_name = serviceadmin_user = glanceadmin_password = password
也可以直接运行下面两条命令,实现修改
sed -i -e " s/%SERVICE_TENANT_NAME%/service/g; s/%SERVICE_USER%/glance/g; s/%SERVICE_PASSWORD%/$SERVICE_PASSWORD/g; " /etc/glance/glance-api-paste.inised -i -e " s/%SERVICE_TENANT_NAME%/service/g; s/%SERVICE_USER%/glance/g; s/%SERVICE_PASSWORD%/$SERVICE_PASSWORD/g; " /etc/glance/glance-registry-paste.ini
编辑/etc/glance/glance-registry.conf,改成使用mysql验证
#sql_connection = sqlite:var/lib/glance/glance.sqlitesql_connection = mysql://glance:password@10.1.199.17/glance
或者运行下面命令实现修改
sed -i '/sql_connection = .*/{s|sqlite:///.*|mysql://'"glance"':'"$MYSQL_PASS"'@'"$MASTER"'/glance|g}' /etc/glance/glance-registry.conf
编辑/etc/glance/glance-registry.conf 和 /etc/glance/glance-api.conf,都在文件末尾添加两行
[paste_deploy]flavor = keystone
或者运行下面命令,完成修改
cat <>/etc/glance/glance-api.conf[paste_deploy]flavor = keystoneEOFcat < >/etc/glance/glance-registry.conf[paste_deploy]flavor = keystoneEOF
重启glance服务
service glance-api restart && service glance-registry restart
同步glance数据库
# glance-manage version_control 0# glance-manage db_sync/usr/lib/python2.7/dist-packages/glance/registry/db/migrate_repo/versions/003_add_disk_format.py:47: SADeprecationWarning: useexisting is deprecated. Use extend_existing. useexisting=True)
看到下面的输出,表示正常的。
重启glance服务
service glance-api restart && service glance-registry restart
测试
glance index
没有输出,表示正常,因为目前还没有镜像。
下载Image
我们下载CirrOS的p_w_picpath作为测试使用,只有10M。如果是ubuntu官方的p_w_picpath,220M,并且ubuntu官方的p_w_picpath,都是需要使用密钥登陆。
CirrOS
下载p_w_picpath
wget https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
上传p_w_picpath
glance add name=cirros-0.3.0-x86_64 is_public=true container_format=bare \disk_format=qcow2 < /root/cirros-0.3.0-x86_64-disk.img
Cirros,是可以使用用户名和密码登陆,也可以使用密钥登陆
user:cirros
password:cubswin:)Ubuntu官方p_w_picpath
下载p_w_picpath
wget http://cloud-p_w_picpaths.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
上传p_w_picpath
glance add name="Ubuntu 12.04 cloudimg amd64" is_public=true container_format=ovf \disk_format=qcow2 < /root/precise-server-cloudimg-amd64-disk1.img
user:ubuntu
只能使用密钥登陆。
查看p_w_picpath
# glance indexID Name Disk Format Container Format Size ------------------------------------ ------------------------------ -------------------- -------------------- --------------5dcf84a0-b491-4710-8d7a-5531bce0dedc cirros-0.3.0-x86_64 qcow2 bare 9761280f4f62d8a-3e5b-4136-8547-ce3cb79771aa Ubuntu 12.04 cloudimg amd64 qcow2 ovf 230817792
Nova
安装
apt-get install -y nova-api nova-cert nova-common nova-objectstore \nova-scheduler nova-volume nova-consoleauth novnc python-nova python-novaclient \nova-compute nova-compute-kvm nova-network
如果你希望控制节点,不打算跑计算服务,装完后,把nova compute的服务停掉也可以。
配置
编辑 /etc/nova/api-paste.ini , 修改末尾3行
#admin_tenant_name = %SERVICE_TENANT_NAME%#admin_user = %SERVICE_USER%#admin_password = %SERVICE_PASSWORD%admin_tenant_name = serviceadmin_user = novaadmin_password = password
或者运行下面命令进行修改
sed -i -e " s/%SERVICE_TENANT_NAME%/service/g; s/%SERVICE_USER%/nova/g; s/%SERVICE_PASSWORD%/$SERVICE_PASSWORD/g; " /etc/nova/api-paste.ini
编辑/etc/nova/nova.conf 文件,
下面是我的nova.conf 文件的配置。需要注意的一点是Essex版本的nova,配置文件不需要前面加上 — 。日后我会逐步调整nova.conf 文件,让他更加可读和方便大家理解。
为了简单,大家直接copy下面内容,运行就可以。
如果你是在虚拟机里安装,你需要吧 libvirt_type=kvm 改成 ibvirt_type=qemu
cat >/etc/nova/nova.conf <
设置目录权限
chown -R nova:nova /etc/nova
重启所有服务
service rabbitmq-server restartservice libvirt-bin restartservice nova-scheduler restartservice nova-network restartservice nova-cert restartservice nova-compute restartservice nova-api restartservice nova-objectstore restartservice nova-volume restart
由于服务数量比较多,创建一个脚本 restart.sh 来重启所有服务。
#!/bin/bashfor a in rabbitmq-server libvirt-bin nova-network nova-cert nova-compute \nova-api nova-objectstore nova-scheduler nova-volume \novnc nova-consoleauth; do service "$a" stop; donefor a in rabbitmq-server libvirt-bin nova-network nova-cert nova-compute \nova-api nova-objectstore nova-scheduler nova-volume \novnc nova-consoleauth; do service "$a" start; done
运行脚本
bash restart.shStopping rabbitmq-server: rabbitmq-server.libvirt-bin stop/waitingnova-network stop/waitingnova-cert stop/waitingnova-compute stop/waitingnova-api stop/waitingnova-objectstore stop/waitingnova-scheduler stop/waitingnova-volume stop/waiting * Stopping OpenStack NoVNC proxy nova-novncproxy [ OK ]nova-consoleauth stop/waitingStarting rabbitmq-server: SUCCESSrabbitmq-server.libvirt-bin start/running, process 9683nova-network start/running, process 9703nova-cert start/running, process 9713nova-compute start/running, process 9724nova-api start/running, process 9734nova-objectstore start/running, process 9744nova-scheduler start/running, process 9759nova-volume start/running, process 9775 * Starting OpenStack NoVNC proxy nova-novncproxy [ OK ]nova-consoleauth start/running, process 9839
同步数据库
nova-manage db sync
会有一堆的输出,不过应该是没问题的。nova数据库里已经有相应的表,就表示正确。
# nova-manage db sync2012-07-19 18:43:34 WARNING nova.utils [-] /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py:639: SADeprecationWarning: The 'listeners' argument to Pool (and create_engine()) is deprecated. Use event.listen(). Pool.__init__(self, creator, **kw)2012-07-19 18:43:34 WARNING nova.utils [-] /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py:145: SADeprecationWarning: Pool.add_listener is deprecated. Use event.listen() self.add_listener(l)
创建Fix IP
FIX IP,就是分配给虚拟机的实际IP地址。这些数据都会写入数据库。$FIXED_RANGE 在novarc里设置。
nova-manage network create private --fixed_range_v4=$FIXED_RANGE \ --num_networks=1 --bridge=br100 --bridge_interface=eth1 \--network_size=256 --multi_host=T
创建floating IP
所谓Floating IP,是亚马逊EC2的定义。简单说,就是公网的IP。他其实是通过类似防火墙类似,做一个映射。实际上是通过iptables来实现映射.
nova-manage floating create --ip_range=$FLOATING_RANGE
重启nova服务
bash restart.shlibvirt-bin stop/waitingnova-network stop/waitingnova-cert stop/waitingnova-compute stop/waitingnova-api stop/waitingnova-objectstore stop/waitingnova-scheduler stop/waitingnova-volume stop/waiting * Stopping OpenStack NoVNC proxy nova-novncproxy [ OK ]nova-consoleauth stop/waitinglibvirt-bin start/running, process 23232nova-network start/running, process 23252nova-cert start/running, process 23262nova-compute start/running, process 23273nova-api start/running, process 23285nova-objectstore start/running, process 23303nova-scheduler start/running, process 23321nova-volume start/running, process 23336 * Starting OpenStack NoVNC proxy nova-novncproxy [ OK ]nova-consoleauth start/running, process 23386
测试
可以尝试用下面命令去检查nova的状况
nova-manage service list