分享

虚拟机上安装openstack

hyj 发表于 2013-12-24 12:20:53 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 1 10153
本帖最后由 pig2 于 2014-1-11 21:02 编辑

这里以VMWare为例:
软件:
VMware® Workstation 9.0
ubuntu-12.04.1-server-amd64.iso
参考网址:
http://docs.openstack.org/essex/ ... Server1-d1e537.html

一.创建虚拟机
注意:需要2个虚拟网卡,2块硬盘,一个30G,一个10G。
用于创建nova-volume和swift。

二.安装ubuntu-server
注意:选择手动分区,对30G的硬盘进行以下分区,10G的硬盘暂时不用操作
1.创建根分区,15GB
2.创建交换分区,2GB
3.剩余空间,创建逻辑分区,在文件系统中选择最后一项不使用,留着物理卷给nova-volume.

三.开始OpenStack安装(以下操作使用root)
由于脚本比较长,所以没列出来,请http://yuky1327.iteye.com/blog/1696604在下载附件的脚本,辅助执行。
1.开启并设置root密码
  1. # This file describes the network interfaces available on your system
  2. # and how to activate them. For more information, see interfaces(5).</P>
  3. # The loopback network interface
  4. auto lo
  5. iface lo inet loopback</P>
  6. # The primary network interface
  7. auto eth0
  8. iface eth0 inet static
  9. address 192.168.1.50
  10. netmask 255.255.255.0
  11. network 192.168.1.0
  12. broadcast 192.168.1.255
  13. gateway 192.168.1.1
  14. dns-nameservers 202.96.128.166</P>
  15. auto eth1
  16. iface eth1 inet static
  17. address 10.0.1.1
  18. netmask 255.255.255.0
  19. network 10.0.1.0
  20. broadcast 10.0.1.255
  21. </font></font></font></font>
复制代码
Restart the network now
  1. sudo /etc/init.d/networking restart
复制代码
3.Install Base OS & bridge-utils
  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install bridge-utils
复制代码
4.NTP Server
  1. sudo apt-get install ntp
复制代码
Open the file /etc/ntp.conf and add the following lines to make sure that the time on the server stays in sync with an external server. If the Internet connectivity is down, the NTP server uses its own hardware clock as the fallback.
  1. server ntp.ubuntu.com
  2. server 127.127.1.0
  3. fudge 127.127.1.0 stratum 10
复制代码
Restart the NTP server
  1. sudo service ntp restart
复制代码
5.Install mysql-server and python-mysqldb package
Create the root password for mysql. The password used in this guide is "mygreatsecret"
  1. sudo apt-get install mysql-server python-mysqldb
复制代码
Change the bind address from 127.0.0.1 to 0.0.0.0 in /etc/mysql/my.cnf. It should be identical to this:
  1. bind-address = 0.0.0.0
复制代码
Restart MySQL server to ensure that it starts listening on all interfaces.


  1. sudo restart mysql
复制代码
Create MySQL databases to be used with nova, glance and keystone.


  1. sudo mysql -uroot -pmygreatsecret -e 'CREATE DATABASE nova;'
  2. sudo mysql -uroot -pmygreatsecret -e 'CREATE USER novadbadmin;'
  3. sudo mysql -uroot -pmygreatsecret -e "GRANT ALL PRIVILEGES ON nova.* TO 'novadbadmin'@'%';"
  4. sudo mysql -uroot -pmygreatsecret -e "SET PASSWORD FOR 'novadbadmin'@'%' = PASSWORD('novasecret');"
  5. sudo mysql -uroot -pmygreatsecret -e 'CREATE DATABASE glance;'
  6. sudo mysql -uroot -pmygreatsecret -e 'CREATE USER glancedbadmin;'
  7. sudo mysql -uroot -pmygreatsecret -e "GRANT ALL PRIVILEGES ON glance.* TO 'glancedbadmin'@'%';"
  8. sudo mysql -uroot -pmygreatsecret -e "SET PASSWORD FOR 'glancedbadmin'@'%' = PASSWORD('glancesecret');"
  9. sudo mysql -uroot -pmygreatsecret -e 'CREATE DATABASE keystone;'
  10. sudo mysql -uroot -pmygreatsecret -e 'CREATE USER keystonedbadmin;'
  11. sudo mysql -uroot -pmygreatsecret -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystonedbadmin'@'%';"
  12. sudo mysql -uroot -pmygreatsecret -e "SET PASSWORD FOR 'keystonedbadmin'@'%' = PASSWORD('keystonesecret');"
复制代码
6.Install Keystone


  1. sudo apt-get install keystone python-keystone python-keystoneclient
复制代码
Open /etc/keystone/keystone.conf and change the line


  1. admin_token = ADMIN
  2. 改为
  3. admin_token = admin
复制代码
Since MySQL database is used to store keystone configuration, replace the following line in /etc/keystone/keystone.conf
  1. connection = sqlite:////var/lib/keystone/keystone.db
  2. 改为
  3. connection = mysql://keystonedbadmin:keystonesecret@192.168.1.200/keystone
复制代码
Restart Keystone:


  1. sudo service keystone restart
复制代码
Run the following command to synchronise the database:


  1. sudo keystone-manage db_sync
复制代码
add these variables to ~/.bashrc


  1. export SERVICE_ENDPOINT="http://localhost:35357/v2.0"
  2. export SERVICE_TOKEN=admin
复制代码
  1. source .bashrc
复制代码
Creating Tenants,Creating Users,Creating Roles,Listing Tenants, Users and Roles,Adding Roles to Users in Tenants,Creating Services,Creating Endpoints
其中会要求输入邮箱地址和本机IP地址
  1. ./create_keystone_data.sh
复制代码
7.Install glance


  1. sudo apt-get install glance glance-api glance-client glance-common glance-registry python-glance
复制代码
Glance uses SQLite by default. MySQL and PostgreSQL can also be configured to work with Glance.
修改/etc/glance/glance-api-paste.ini 和 /etc/glance/glance-registry-paste.ini


  1. admin_tenant_name = %SERVICE_TENANT_NAME%
  2. admin_user = %SERVICE_USER%
  3. admin_password = %SERVICE_PASSWORD%
  4. 改为
  5. admin_tenant_name = service
  6. admin_user = glance
  7. admin_password = glance
复制代码
Open the file /etc/glance/glance-registry.conf and edit the line which contains the option "sql_connection =" to this:
  1. sql_connection = mysql://glancedbadmin:glancesecret@192.168.1.200/glance
  2. ....
  3. #末尾追加
  4. [paste_deploy]
  5. flavor = keystone
复制代码
Open /etc/glance/glance-api.conf and add the following lines at the end of the document.
  1. [paste_deploy]
  2. flavor = keystone
复制代码
Create glance schema in the MySQL database.:


  1. sudo glance-manage version_control 0
  2. sudo glance-manage db_sync
复制代码
Restart glance-api and glance-registry after making the above changes.


  1. sudo restart glance-api
  2. sudo restart glance-registry
复制代码
add these variables to ~/.bashrc
  1. export OS_TENANT_NAME=admin
  2. export OS_USERNAME=admin
  3. export OS_PASSWORD=admin
  4. export OS_AUTH_URL="http://localhost:5000/v2.0/"
复制代码
  1. source .bashrc
复制代码
To test if glance is setup correectly execute the following command.

  1. glance index
复制代码
成功是不会显示任何信息,不成功则会显示错误信息.
8.Install nova

  1. sudo apt-get install nova-api nova-cert nova-compute nova-compute-kvm nova-doc nova-network nova-objectstore nova-scheduler nova-volume rabbitmq-server novnc nova-consoleauth
复制代码
Run edit_nova_conf.sh to edit the /etc/nova/nova.conf file
  1. ./edit_nova_conf.sh
  2. 输入mysql的地址
  3. 输入本机IP
  4. 输入浮动IP的开始,默认192.168.1.225
复制代码
Create a Physical Volume.


  1. sudo pvcreate /dev/sda5
复制代码
Create a Volume Group named nova-volumes.


  1. sudo vgcreate nova-volumes /dev/sda5
复制代码
Change the ownership of the /etc/nova folder and permissions for /etc/nova/nova.conf:


  1. sudo chown -R nova:nova /etc/nova
  2. sudo chmod 644 /etc/nova/nova.conf
复制代码
Open /etc/nova/api-paste.ini and at the end of the file, edit the following lines:


  1. admin_tenant_name = %SERVICE_TENANT_NAME%
  2. admin_user = %SERVICE_USER%
  3. admin_password = %SERVICE_PASSWORD%
  4. 改为
  5. admin_tenant_name = service
  6. admin_user = nova
  7. admin_password = nova
复制代码
设置ipv4转发,否则外面能连接虚拟机,虚拟机访问不了外面


  1. sysctl -w net.ipv4.ip_forward=1
复制代码
Create nova schema in the MySQL database.


  1. sudo nova-manage db sync
复制代码
创建网络


  1. nova-manage network create private --fixed_range_v4=10.0.1.1/27 --num_networks=1 --bridge=br100 --bridge_interface=eth1 --network_size=32
复制代码
设定floating IP,与输入的floating_range值一致


  1. nova-manage floating create --ip_range=192.168.1.225/27
复制代码
Restart nova services.


  1. sudo restart libvirt-bin; sudo restart nova-network; sudo restart nova-compute; sudo restart nova-api; sudo restart nova-objectstore; sudo restart nova-scheduler; sudo restart nova-volume; sudo restart nova-consoleauth;
复制代码
To test if nova is setup correctly run the following command.


  1. sudo nova-manage service list
  2. Binary Host Zone Status State Updated_At
  3. nova-network server1 nova enabled :-) 2012-04-20 08:58:43
  4. nova-scheduler server1 nova enabled :-) 2012-04-20 08:58:44
  5. nova-volume server1 nova enabled :-) 2012-04-20 08:58:44
  6. nova-compute server1 nova enabled :-) 2012-04-20 08:58:45
  7. nova-cert server1 nova enabled :-) 2012-04-20 08:58:43
复制代码
7.1  Install OpenStack Dashboard

  1. sudo apt-get install openstack-dashboard
复制代码
Restart apache with the following command:


  1. sudo service apache2 restart
复制代码
打开浏览器,输入http://192.168.1.200,输入admin@admin登录。
7.2 Install Swift
  1. sudo apt-get install swift swift-proxy swift-account swift-container swift-object
  2. sudo apt-get install xfsprogs curl python-pastedeploy
复制代码
Swift Storage Backends For Partition as a storage device
If you had set aside a partition for Swift during the installation of the OS, you can use it directly. If you have an unused/unpartitioned physical partition (e.g. /dev/sdb5), you have to format it to xfs filesystem using parted or fdisk and use it as the backend. You need to specify the mount point in /etc/fstab.
CAUTION: Replace /dev/sdb to your appropriate device. I'm assuming that there is an unused/un-formatted partition section in /dev/sdb
  1. root@begon:/dev# sudo fdisk /dev/sdb
  2. Command (m for help): n
  3. Partition type:
  4. p primary (0 primary, 0 extended, 4 free)
  5. e extended
  6. Select (default p): e
  7. Partition number (1-4, default 1): 3
  8. First sector (2048-20971519, default 2048):
  9. Using default value 2048
  10. Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
  11. Using default value 20971519
  12. Command (m for help): n
  13. Partition type:
  14. p primary (0 primary, 1 extended, 3 free)
  15. l logical (numbered from 5)
  16. Select (default p): l
  17. Adding logical partition 5
  18. First sector (4096-20971519, default 4096):
  19. Using default value 4096
  20. Last sector, +sectors or +size{K,M,G} (4096-20971519, default 20971519):
  21. Using default value 20971519
  22. Command (m for help): w
  23. The partition table has been altered!
  24. Calling ioctl() to re-read partition table.
  25. Syncing disks.
复制代码
查看是否创建成功


  1. root@bogon:/dev# fdisk /dev/sdb
  2. Command (m for help): p
  3. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  4. 107 heads, 17 sectors/track, 11529 cylinders, total 20971520 sectors
  5. Units = sectors of 1 * 512 = 512 bytes
  6. Sector size (logical/physical): 512 bytes / 512 bytes
  7. I/O size (minimum/optimal): 512 bytes / 512 bytes
  8. Disk identifier: 0x937847e1
  9. Device Boot Start End Blocks Id System
  10. /dev/sdb1 2048 20971519 10484736 5 Extended
  11. /dev/sdb5 4096 20971519 10483712 83 Linux
复制代码
This would have created a partition (something like /dev/sdb5) that we can now format to XFS filesystem. Do 'sudo fdisk -l' in the terminal to view and verify the partion table. Find the partition Make sure that the one that you want to use is listed there. This would work only if you have xfsprogs installed.
  1. sudo mkfs.xfs -i size=1024 /dev/sdb5
复制代码
Create a directory /mnt/swift_backend that can be used as a mount point to the partion tha we created.


  1. sudo mkdir /mnt/swift_backend
复制代码
以下添加到 /etc/fstab


  1. /dev/sdb5 /mnt/swift_backend xfs noatime,nodiratime,nobarrier,logbufs=8 0 0
复制代码
Now before mounting the backend that will be used, create some nodes to be used as storage devices and set ownership to 'swift' user and group.
  1. sudo mount /mnt/swift_backend
  2. pushd /mnt/swift_backend
  3. sudo mkdir node1 node2 node3 node4
  4. popd
  5. sudo chown swift.swift /mnt/swift_backend/*
  6. for i in {1..4}; do sudo ln -s /mnt/swift_backend/node$i /srv/node$i; done;
  7. sudo mkdir -p /etc/swift/account-server /etc/swift/container-server /etc/swift/object-server /srv/node1/device /srv/node2/device /srv/node3/device /srv/node4/device
  8. sudo mkdir /run/swift
  9. sudo chown -L -R swift.swift /etc/swift /srv/node[1-4]/ /run/swift
复制代码
把下面添加到/etc/rc.local ,在"exit 0"前;


  1. sudo mkdir /run/swift
  2. sudo chown swift.swift /run/swift
复制代码
打开/etc/default/rsync 设置  RSYNC_ENABLE=true


  1. RSYNC_ENABLE=true
复制代码
创建并写入以下内容到/etc/rsyncd.conf


  1. # General stuff
  2. uid = swift
  3. gid = swift
  4. log file = /var/log/rsyncd.log
  5. pid file = /run/rsyncd.pid
  6. address = 127.0.0.1
  7. # Account Server replication settings
  8. [account6012]
  9. max connections = 25
  10. path = /srv/node1/
  11. read only = false
  12. lock file = /run/lock/account6012.lock
  13. [account6022]
  14. max connections = 25
  15. path = /srv/node2/
  16. read only = false
  17. lock file = /run/lock/account6022.lock
  18. [account6032]
  19. max connections = 25
  20. path = /srv/node3/
  21. read only = false
  22. lock file = /run/lock/account6032.lock
  23. [account6042]
  24. max connections = 25
  25. path = /srv/node4/
  26. read only = false
  27. lock file = /run/lock/account6042.lock
  28. # Container server replication settings
  29. [container6011]
  30. max connections = 25
  31. path = /srv/node1/
  32. read only = false
  33. lock file = /run/lock/container6011.lock
  34. [container6021]
  35. max connections = 25
  36. path = /srv/node2/
  37. read only = false
  38. lock file = /run/lock/container6021.lock
  39. [container6031]
  40. max connections = 25
  41. path = /srv/node3/
  42. read only = false
  43. lock file = /run/lock/container6031.lock
  44. [container6041]
  45. max connections = 25
  46. path = /srv/node4/
  47. read only = false
  48. lock file = /run/lock/container6041.lock
  49. # Object Server replication settings
  50. [object6010]
  51. max connections = 25
  52. path = /srv/node1/
  53. read only = false
  54. lock file = /run/lock/object6010.lock
  55. [object6020]
  56. max connections = 25
  57. path = /srv/node2/
  58. read only = false
  59. lock file = /run/lock/object6020.lock
  60. [object6030]
  61. max connections = 25
  62. path = /srv/node3/
  63. read only = false
  64. lock file = /run/lock/object6030.lock
  65. [object6040]
  66. max connections = 25
  67. path = /srv/node4/
  68. read only = false
  69. lock file = /run/lock/object6040.lock
复制代码
Restart rsync.


  1. sudo service rsync restart
复制代码
Configure Swift Components
运行以下命令获取一个随机码
  1. root@bogon:/srv# od -t x8 -N 8 -A n < /dev/random
  2. 7736e3116c693239
复制代码
创建 /etc/swift/swift.conf and 把随机码写入:


  1. [swift-hash]
  2. # random unique string that can never change (DO NOT LOSE). I'm using 7736e3116c693239.
  3. # od -t x8 -N 8 -A n < /dev/random
  4. # The above command can be used to generate random a string.
  5. swift_hash_path_suffix = 7736e3116c693239
复制代码
把以下内容写入到/etc/swift/proxy-server.conf


  1. [DEFAULT]
  2. bind_port = 8080
  3. user = swift
  4. swift_dir = /etc/swift
  5. [pipeline:main]
  6. # Order of execution of modules defined below
  7. pipeline = catch_errors healthcheck cache authtoken keystone proxy-server
  8. [app:proxy-server]
  9. use = egg:swift#proxy
  10. allow_account_management = true
  11. account_autocreate = true
  12. set log_name = swift-proxy
  13. set log_facility = LOG_LOCAL0
  14. set log_level = INFO
  15. set access_log_name = swift-proxy
  16. set access_log_facility = SYSLOG
  17. set access_log_level = INFO
  18. set log_headers = True
  19. account_autocreate = True
  20. [filter:healthcheck]
  21. use = egg:swift#healthcheck
  22. [filter:catch_errors]
  23. use = egg:swift#catch_errors
  24. [filter:cache]
  25. use = egg:swift#memcache
  26. set log_name = cache
  27. [filter:authtoken]
  28. paste.filter_factory = keystone.middleware.auth_token:filter_factory
  29. auth_protocol = http
  30. auth_host = 127.0.0.1
  31. auth_port = 35357
  32. auth_token = admin
  33. service_protocol = http
  34. service_host = 127.0.0.1
  35. service_port = 5000
  36. admin_token = admin
  37. admin_tenant_name = service
  38. admin_user = swift
  39. admin_password = swift
  40. delay_auth_decision = 0
  41. [filter:keystone]
  42. paste.filter_factory = keystone.middleware.swift_auth:filter_factory
  43. operator_roles = admin, swiftoperator
  44. is_admin = true
复制代码
Configure Swift Account Server,Swift Container Server,Swift Object Server


  1. ./swift_account_server.sh
  2. ./swift_container_server.sh
  3. ./swift_object_server.sh
复制代码
vi /etc/swift/container-server.conf 在末尾添加以下


  1. [container-sync]
复制代码
Configure Swift Rings


  1. pushd /etc/swift
  2. sudo swift-ring-builder object.builder create 18 3 1
  3. sudo swift-ring-builder container.builder create 18 3 1
  4. sudo swift-ring-builder account.builder create 18 3 1
  5. sudo swift-ring-builder object.builder add z1-127.0.0.1:6010/device 1
  6. sudo swift-ring-builder object.builder add z2-127.0.0.1:6020/device 1
  7. sudo swift-ring-builder object.builder add z3-127.0.0.1:6030/device 1
  8. sudo swift-ring-builder object.builder add z4-127.0.0.1:6040/device 1
  9. sudo swift-ring-builder object.builder rebalance
  10. sudo swift-ring-builder container.builder add z1-127.0.0.1:6011/device 1
  11. sudo swift-ring-builder container.builder add z2-127.0.0.1:6021/device 1
  12. sudo swift-ring-builder container.builder add z3-127.0.0.1:6031/device 1
  13. sudo swift-ring-builder container.builder add z4-127.0.0.1:6041/device 1
  14. sudo swift-ring-builder container.builder rebalance
  15. sudo swift-ring-builder account.builder add z1-127.0.0.1:6012/device 1
  16. sudo swift-ring-builder account.builder add z2-127.0.0.1:6022/device 1
  17. sudo swift-ring-builder account.builder add z3-127.0.0.1:6032/device 1
  18. sudo swift-ring-builder account.builder add z4-127.0.0.1:6042/device 1
  19. sudo swift-ring-builder account.builder rebalance
复制代码
To start swift and the REST API, run the following commands.


  1. sudo swift-init main start
  2. sudo swift-init rest start
复制代码
Testing Swift


  1. sudo chown -R swift.swift /etc/swift
复制代码
Then run the following command and verify if you get the appropriate account information. The number of containers and objects stored within are displayed as well.
  1. root@server1:~# swift -v -V 2.0 -A http://127.0.0.1:5000/v2.0/ -U service:swift -K swift stat
  2. StorageURL: http://192.168.1.200:8080/v1/AUTH_4b0de95572044eb49345930225d81752
  3. Auth Token: e6955ec2e6ca4059aba6bafc6c0d6473
  4. Account: AUTH_4b0de95572044eb49345930225d81752
  5. Containers: 0
  6. Objects: 0
  7. Bytes: 0
  8. Accept-Ranges: bytes
  9. X-Trans-Id: tx051c25a362534266a4583f49fa44558d
复制代码
到这里已经完成安装OpenStack了,里面提到的脚本,可以在附件下载.本次操作主要参考官方例子,有几个小地方与官网不一致.
打开http://192.168.1.200,输入admin@admin登录到系统中,可以通过这个平台创建镜像,实例等操作。
希望以上对大家有所帮助


































已有(1)人评论

跳转到指定楼层
howtodown 发表于 2013-12-24 20:53:41
string2020 发表于 2013-12-24 20:13
我一直不明白,安装openstack为什么需要两个网卡

你可能对这个还没有了解透彻。为什么你会觉得需要两个网卡
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条