这两周一直在学习openstack,因为要发论文的缘故,同时又想搞一搞理论上的东西。第一次听说openstack还是师兄从爱立信实习回来之后了解到的,当时只是知道这是一个开源的云框架,后来在这个基础上又进一步的了解到他的相关知识,开源的所以是十分方便的我们能够看到他的源码,从而在对源码的理解以及对系统架构的理解上,做出一些性能上的优化。自从云计算和hadoop出现以后,出现了很多不同的私有云,公有云,很多公司也推出了自己的云服务,比喻google的,亚马逊的等等。目前大部分的企业私有云的服务都是收费的,都是按需来收费,改变了传统的固定的模式。就目前国内而言,我都试用了一些腾讯和阿里推出的云服务,总体感觉是阿里在客户的体验性以及系统的稳定性等方面是做的更好一点。阿里目前我正在使用它的云服务器和云数据库,感觉项目在上面还是运行得很好的。
为什么选择openstack呢,我觉得还是跟我之前学的东西有关,之前学习的东西很多,基本上目前主流的东西都学过,读研以后,又学习了java web和ssh框架,说实话之前学习的java的知识还是相当的浅显的,也没有做过相应的项目,所以做项目之后,基本上能够很好的掌握几种框架的使用,同时对于前台的html、css以及javascript都有更好的了解,特别是对面向切面,依赖注入,模式等知识都也学习了。但是这些项目总体而言,还是太偏向于实际应用,而且对于现在的网站制作,总体而言,随着技术的进步,速度相应的越来越快,界面的体验性,交互性也越来越好,但是我总感觉研究的东西还是太少,加之自己也是一直对云这一块比较感兴趣,一直也没有做过深入的研究,本科的时候学习过linux的相关知识,而且对于linux系统我也是比较喜欢的,所以这一块的东西感觉还是比较有用的。openstack是用python来开发的,所以对于python也要有一定的掌握,有了之前学习linux shell的经验,python学习起来还是比较的顺利的。
这次因为实验室空闲的机器还是比较多的,所以想先尝试着搭一个简单一点的三节点的IaaS,也就是一个controller node,一个network node,一个compue node,因为我使用的是三台物理机,所以以后做实验应该还是比较方便的,性能方便应该还是可以的。但是中间搭建的所费时间有点长,一来自己是第一次搭建,要重新装系统,系统更新要花一些时间,二来还是相关的知识不是很熟悉。目前三台机子使用的是ubuntu 12.04.05,安装的openstack版本是folsm,这也是openstack都一个比较稳定的发行版,openstack的版本目前已经更新到了kilo,很多服务都得到了优化,比如在folsm中quantum,后来就由neutron来代替了,性能更加的优越,而且也没有那么的复杂。就自己搭建的过程而言,目前的想法是先搭建一个三节点的架构,利用已有的一些知识做一些实验,最起码对于架构使用配置等问题应该要熟悉,然后就是测试一些它的性能,搞得差不多了基本上从之前实验的过程中学到的一些东西来阅读源码,这样的话估计更有目的性一点,对整个架构做一些优化,利用这些成果估计可以发一篇,毕业论文的东西我也想在此基础上进行研究。openstack的一个方便之处就是他的服务可以按需添加。接下来的学习的过程估计将是相当枯燥和烦闷的,但是为了顺利的毕业学得了知识也是值得的,下面是控制节点的搭建过程,另外的两个以后再补上:
当然我们搭建的方式很多种,也可以利用pip源来进行源码安装。
folsm这个版本中主要安装的是mysql-client,mysql-server,rabbitmq,keystone,glance,nova,cinder,quantum,以及最后的图形界面管理dashboard
由于Ubuntu 12.04 LTS默认包含OpenStack Essex,我们将使用Ubuntu Cloud Archive来安装Folsom:
apt-get install ubuntu-cloud-keyring
编辑 /etc/apt/sources.list.d/cloud-archive.list :
deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/folsom main
Upgrade the system (and reboot if you need) :
apt-get update && apt-get upgrade
3.配置网络:
• 编辑 /etc/network/interfaces 文件:
# Management Network auto eth0
iface eth0 inet static address 192.168.0.1 netmask 255.255.255.0 gateway 192.168.0.254
dns-nameservers 8.8.8.8
# API + Public Network auto eth1
iface eth1 inet static address 7.7.7.7 netmask 255.255.255.0
• Edit /etc/sysctl.conf :
net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.default.rp_filter = 0
Then, restart network service :
service networking restart
• Edit the /etc/hosts file and add folsom-controller, folsom-network and folso
m- compute hostnames with correct IP.
4.安装配置NTP:
• 安装软件包:
apt-get install -y ntp
• 配置 /etc/ntp.conf 文件:
server ntp.ubuntu.com iburst server 127.127.1.0
fudge 127.127.1.0 stratum 10
• 重新启动服务:
service ntp restart
MySQL数据库服务
1.安装软件包:
apt-get install mysql-server python-mysqldb
2.允许从该网络连接:
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
3.重新启动服务:
service mysql restart
4.创建数据库、用户、权限:
mysql -u root -ppassword <<EOF CREATE DATABASE nova;
GRANT ALL PRIVILEGES ON nova.*TO 'nova'@'localhost' \ IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nova.*TO 'nova'@'192.168.0.1' \ IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nova.*TO 'nova'@'192.168.0.2' \ IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON nova.*TO 'nova'@'192.168.0.3' \ IDENTIFIED BY 'password';
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.*TO 'cinder'@'localhost' \ IDENTIFIED BY 'password';
CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.*TO 'glance'@'localhost' \ IDENTIFIED BY 'password';
CREATE DATABASE keystone;
GRANT ALL PRIVILEGES ON keystone.*TO 'keystone'@'localhost' \ IDENTIFIED BY 'password';
CREATE DATABASE quantum;
GRANT ALL PRIVILEGES ON quantum.*TO 'quantum'@'localhost' \ IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON quantum.*TO 'quantum'@'192.168.0.2' \ IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON quantum.*TO 'quantum'@'192.168.0.3' \ IDENTIFIED BY 'password';
FLUSH PRIVILEGES; EOF
RabbitMQ Messaging Service
1.安装软件包:
apt-get install rabbitmq-server
2.更改默认密码:
rabbitmqctl change_password guest password
Keystone
安装软件包:
apt-get install keystone python-keystone python-keystoneclient
2.编辑 /etc/keystone/keystone.conf:
[DEFAULT]
admin_token = password bind_host = 0.0.0.0 public_port = 5000 admin_port = 35357 compute_po
rt = 8774 verbose = True
debug = True
log_file = keystone.log log_dir = /var/log/keystone
log_config = /etc/keystone/logging.conf
[sql]
connection = mysql://keystone:password@localhost:3306/keystone idle_timeout = 200
[identity]
driver = keystone.identity.backends.sql.Identity
[catalog]
driver = keystone.catalog.backends.sql.Catalog
(...)
3.重启动Keystone并在数据库中创建表:
service keystone restart keystone-manage db_sync
4.加载环境变量:
• 创建novarc文件:
export OS_TENANT_NAME=admin export OS_USERNAME=admin export OS_PASSWORD=password
export OS_AUTH_URL="http://localhost:5000/v2.0/" export SERVICE_ENDPOINT="http://localhos
t:35357/v2.0" export SERVICE_TOKEN=password
• 导出变量:
source novarc
echo "source novarc">>.bashrc
5.下载数据脚本并向Keystone数据库填充数据(用户、租户、服务):
./keystone-data.sh
6.下载终结点脚本并(为项目)创建终结点:
./keystone-endpoints.sh
如果管理网络上的控制器节点的IP地址与此示例不同,请使用以下命令指定:
./keystone-endpoints.sh -K <ip address of the management network>
Glance
1.安装软件包:
apt-get install glance glance-api python-glanceclient glance-common
2.配置Glance :
• 编辑 /etc/glance/glance-api.conf and /etc/glance/glance-registry.conf 文件,
修改以下内容:
sql_connection = mysql://glance:password@localhost/glance admin_tenant_name = service
admin_user = glance admin_password = password
对于glance-api.conf,修改:
notifier_strategy = rabbit rabbit_password = password
• Restart Glance services :
service glance-api restart && service glance-registry restart
• 在数据库中创建Glance表:
glance-manage db_sync
• 下载并导入 Ubuntu 12.04 LTS UEC映像:
glance image-create \
--location http://uec-images.ubuntu.com/releases/12.04/release/
ubuntu-12.04-server-cloudimg-amd64-disk1.img \
--is-public true --disk-format qcow2 --container-format bare --name
"Ubuntu"
• 检查映像文件是否已在索引中:
glance image-list
+--------------------------------------+--------+-------------
+------------------+-----------+--------+
| ID
| Name
| Disk Format | Container
Format | Size
| Status |
+--------------------------------------+--------+-------------
+------------------+-----------+--------+
| 0d2664d3-cda9-4937-95b2-909ecf8ea362 | Ubuntu | qcow2
| bare
| 233701376 | active |
+--------------------------------------+--------+-------------
+------------------+-----------+--------+
Nova
• 您也可以安装Glance Replicator (Folsom的新组件).更多相关信息在这里。
1.安装软件包:
apt-get install nova-api nova-cert nova-common \
nova-scheduler python-nova python-novaclient nova-consoleauth novnc \
nova-novncproxy
2.配置Nova:
• 编辑/etc/nova/api-paste.ini 文件,并修改:
admin_tenant_name = service admin_user = nova admin_password = password
因为我们将使用Cinder来创建卷,我们还应删除有关"nova-volume"的每一个部分:
============================================================ [composite:osapi_volume]
use = call:nova.api.openstack.urlmap:urlmap_factory
/: osvolumeversions
/v1: openstack_volume_api_v1
============================================================
============================================================ [composite:openstack_volume_a
pi_v1]
use = call:nova.api.auth:pipeline_factory
noauth = faultwrap sizelimit noauth ratelimit osapi_volume_app_v1 keystone = faultwrap si
zelimit authtoken keystonecontext ratelimit
osapi_volume_app_v1
keystone_nolimit = faultwrap sizelimit authtoken keystonecontext osapi_volume_app_v1
============================================================
============================================================ [app:osapi_volume_app_v1]
paste.app_factory = nova.api.openstack.volume:APIRouter.factory
============================================================
============================================================ [pipeline:osvolumeversions]
pipeline = faultwrap osvolumeversionapp
[app:osvolumeversionapp]
paste.app_factory = nova.api.openstack.volume.versions:Versions.factory
============================================================
• Edit /etc/nova/nova.conf file and modify :
[DEFAULT]
# MySQL Connection #
sql_connection=mysql://nova:password@192.168.0.1/nova
# nova-scheduler # rabbit_password=password scheduler_driver=nova.scheduler.simple.Simple
Scheduler
# nova-api # cc_host=192.168.0.1 auth_strategy=keystone
s3_host=192.168.0.1 ec2_host=192.168.0.1 nova_url=http://192.168.0.1:8774/v1.1/ ec2_url=h
ttp://192.168.0.1:8773/services/Cloud keystone_ec2_url=http://192.168.0.1:5000/v2.0/ec2to
kens api_paste_config=/etc/nova/api-paste.ini allow_admin_api=true
use_deprecated_auth=false ec2_private_dns_show_ip=True dmz_cidr=169.254.169.254/32 ec2_dm
z_host=192.168.0.1 metadata_host=192.168.0.1 metadata_listen=0.0.0.0 enabled_apis=ec2,osa
pi_compute,metadata
# Networking # network_api_class=nova.network.quantumv2.api.API quantum_url=http://192.16
8.0.1:9696 quantum_auth_strategy=keystone quantum_admin_tenant_name=service quantum_admin
_username=quantum quantum_admin_password=password quantum_admin_auth_url=http://192.168.0.
1:35357/v2.0
libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver linuxnet_interface_
driver=nova.network.linux_net.LinuxOVSInterfaceDriver firewall_driver=nova.virt.libvirt.f
irewall.IptablesFirewallDriver
# Cinder #
volume_api_class=nova.volume.cinder.API
# Glance # glance_api_servers=192.168.0.1:9292 image_service=nova.image.glance.GlanceImag
eService
# novnc # novnc_enable=true novncproxy_base_url=http://192.168.0.1:6080/vnc_auto.html vnc
server_proxyclient_address=127.0.0.1 vncserver_listen=0.0.0.0
# Misc # logdir=/var/log/nova state_path=/var/lib/nova lock_path=/var/lock/nova
root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf verbose=true
• 在数据库中创建Nova表:
nova-manage db sync
• 重新启动Nova服务:
service nova-api restart service nova-cert restart
service nova-consoleauth restart service nova-scheduler restart service nova-novncproxy r
estart
Cinder
1.安装软件包:
apt-get install -y cinder-api cinder-scheduler cinder-volume iscsitarget \
open-iscsi iscsitarget-dkms python-cinderclient linux-headers-ùname -r`
2.由于在tgtadm中有一个bug,我们必须修改 /etc/tgt/targets.conf:
# include /etc/tgt/conf.d/*.conf
include /etc/tgt/conf.d/cinder_tgt.conf
3.配置和启动iSCSI服务:
sed -i 's/false/true/g' /etc/default/iscsitarget service iscsitarget start
service open-iscsi start
4.配置Cinder:
• Edit /etc/cinder/cinder.conf file and modify :
[DEFAULT]
sql_connection = mysql://cinder:password@localhost:3306/cinder rabbit_password = password
• Edit /etc/cinder/api-paste.ini file and modify :
admin_tenant_name = service admin_user = cinder admin_password = password
• 创建卷(在第二个磁盘上):
fdisk /dev/sdb
[Create a Linux partition]
pvcreate /dev/sdb1
vgcreate cinder-volumes /dev/sdb1
• 在数据库中创建Cinder表:
cinder-manage db sync
• 重新启动服务:
service cinder-api restart service cinder-scheduler restart service cinder-volume restart
Quantum
1.安装软件包:
apt-get install quantum-server
2.配置Quantum服务:
Edit /etc/quantum/quantum.conf file and modify :
core_plugin = \
quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPluginV2 auth_strategy = keys
tone
fake_rabbit = False rabbit_password = password
• Edit /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini file and modif
y :
[DATABASE]
sql_connection = mysql://quantum:password@localhost:3306/quantum
[OVS]
tenant_network_type = gre tunnel_id_ranges = 1:1000 enable_tunneling = True
注意
因为不需要在你的物理交换机上配置Vlan,选择 tunnel mode 更方便。
• Edit /etc/quantum/api-paste.ini file and modify :
admin_tenant_name = service admin_user = quantum admin_password = password
3.启动服务:
service quantum-server restart
Dashboard (Horizon)
安装软件包:
apt-get install apache2 libapache2-mod-wsgi openstack-dashboard \
memcached python-memcache
OpenStack Dashboard is now available at http://<controller_node>/horizon.We can
login with admin / password credentials or demo / password.