分享

源码安装 OpenStack icehouse Trove 项目

本帖最后由 hochikong 于 2014-7-28 15:15 编辑
问题导读:
1.什么是Trove?
2.如何把Trove服务做成系统服务?
3.如何通过命令行方式创建Trove实例?




关于 Trove 这个 DbaaS 项目介绍可以看官方 wiki 里介绍。本文主要目的就是把 Trove 能安装上、并且用起来。
详见:https://wiki.openstack.org/wiki/Trove

同时 Trove 有一个项目专门负责安装 Trove-integration,基本上通过几条命令就可以安装好一个 trove 环境,装了几次,一直没能成功的创建过一个 db instance。
这个项目会自动把 devstack 安装一遍,然后安装 trove,build 一个镜像,上传到 glance 镜像库中,网络好有耐心的朋友可以尝试一下:https://github.com/openstack/trove-integration


Trove 默认把数据库目录挂载到了 cinder 卷上面,同时备份的数据库会存放到 swift 对象存储中,也可以选择使用 heat 模版,对其它组建依赖性比较强,本文是基于一个 icehouse openstack 环境上(包含所有的核心项目)扩展了 trove。

目录
  • 1 下载,安装包
  • 2 创建 Trove 用户
  • 3 配置 Trove
    • 3.1 事先准备
    • 3.2 trove-api 配置
    • 3.3 trove-conductor 配置
    • 3.4 trove-taskmanager 配置
    • 3.5 同步数据库
    • 3.6 制作系统服务
    • 3.7 启动服务
    • 3.8 自定义 heat 模版
  • 4 定义 Trove
  • 5 命令行方式创建 trove 实例
  • 6 界面创建方式 trove 实例





下载、安装包
先把 trove 的源代码下载下来:
  1. git clone https://github.com/openstack/trove.git /opt/trove
  2. git clone https://github.com/openstack/python-troveclient.git /opt/python-troveclient
复制代码
安装 troveclient:
  1. cd /opt/python-troveclient
  2. python setup.py egg_info
  3. pip install -r python_troveclient.egg-info/requires.txt
  4. python setup.py develop
复制代码
安装 Trove icehouse release:
  1. cd /opt/trove
  2. git checkout stable/icehouse
  3. python setup.py egg_info
  4. pip install -r trove.egg-info/requires.txt
  5. python setup.py develop
复制代码
创建 Trove 用户 我使用了环境变量,省得敲一堆 –os 参数,而 trove 的租户最好和 nova 的租户相同,trove 会使用 nova-compute 资源,下面用来创建 trove 用户:
  1. keystone user-create \
  2.          --name=trove \
  3.          --pass=password \
  4.          --tenand-id=$(keystone tenant-get service | awk '/ id / {print $4}') \
  5.          --email=trove@thstack.com
复制代码
给 trove 用户添加 admin 角色:
  1. keystone user-role-add --tenand-id=$(keystone tenant-get service | awk '/ id / {print $4}') \
  2.                        --user-id=$(keystone user-get trove | awk '/ id / {print $4}') \
  3.                        --role-id=$(keystone role-get admin | awk '/ id / {print $4}')
复制代码
创建 trove 服务,类型为 databases:
  1. keystone service-create --name=trove --type=database --description='OpenStack Trove Service'
复制代码
给 trove 服务添加 api 访问地址:
  1. keystone endpoint-create --region RegionOne \
  2.                          --service-id=$(keystone service-get trove | awk '/ id / {print $4}') \
  3.                          --publicurl 'http://127.0.0.1:8779/v1.0/$(tenant_id)s' \
  4.                          --adminurl 'http://127.0.0.1:8779/v1.0/$(tenant_id)s' \
  5.                          --internalurl 'http://127.0.0.1:8779/v1.0/$(tenant_id)s'
复制代码

配置 Trove事先准备
创建 trove 需要的目录:
  1. mkdir /etc/trove /var/log/trove /var/lib/trove
复制代码
使用 mysql 作为 trove 后端 db:
  1. mysql -uroot -p
  2. > create database trove default character set utf8;
  3. > grant all on trove.* to 'trove'@'localhost' identified by 'trove';   
复制代码
指定 trove 使用的 neutron 网络:
如果还没有创建网络,需要用 admin 账号创建一个共享的外部网络和一共享的内部网络,接上路由器。
目前 trove 在 horizon 上还不支持选择网络,只能在配置文件中指定一个网络 id
  1. neutron net-list
  2. +-----------------------------------------------------+------------------+-------------------------------------------------------------------------------+
  3. | id                                                                 | name              | subnets                                                                                       |
  4. +-----------------------------------------------------+------------------+-------------------------------------------------------------------------------+
  5. | 30190693-9150-46e1-af48-9ab90fbd4a3e | Public               | 947c4e3e-ab1e-46b8-b5a1-1c238828e776 192.168.8.0/24      |
  6. | 9cbae051-78c7-4574-968e-2cb9b0f410ad | Internal            | fded8a32-f850-4e2e-8532-3326872204a7 10.0.0.0/24             |
  7. +-----------------------------------------------------+------------------+-------------------------------------------------------------------------------+   
复制代码
从上面网络信息中把内部网络的 id 号提取出来,在 trove.conf 中和命令行创建都会用到:
  1. default_neutron_networks = 9cbae051-78c7-4574-968e-2cb9b0f410ad   
复制代码

trove 三个服务的配置文件主要参考了 cfg.py 和 *.sample,虽然有些参数不太确定,但是目前服务运行正常. 下面的配置文件可能并不适合每个人,需要自己修改密码、ip 地址之类的。
trove-api 配置 /etc/trove/api-paste.init 内容如下:
  1. [composite:trove]
  2. use = call:trove.common.wsgi:versioned_urlmap
  3. /: versions
  4. /v1.0: troveapi
  5. [app:versions]
  6. paste.app_factory = trove.versions:app_factory
  7. [pipeline:troveapi]
  8. pipeline = faultwrapper authtoken authorization contextwrapper ratelimit extensions troveapp
  9. #pipeline = debug extensions troveapp
  10. [filter:extensions]
  11. paste.filter_factory = trove.common.extensions:factory
  12. [filter:authtoken]
  13. paste.filter_factory = keystoneclient.middleware.auth_token:filter_factory
  14. auth_host = 127.0.0.1
  15. auth_port = 35357
  16. auth_protocol = http
  17. auth_uri = http://127.0.0.1:5000/v2.0
  18. admin_user = trove
  19. admin_tenant_name = service
  20. admin_password = password
  21. # signing_dir is configurable, but the default behavior of the authtoken
  22. # middleware should be sufficient.  It will create a temporary directory
  23. # in the home directory for the user the trove process is running as.
  24. signing_dir = /var/lib/trove/keystone-signing
  25. [filter:authorization]
  26. paste.filter_factory = trove.common.auth:AuthorizationMiddleware.factory
  27. [filter:contextwrapper]
  28. paste.filter_factory = trove.common.wsgi:ContextMiddleware.factory
  29. [filter:faultwrapper]
  30. paste.filter_factory = trove.common.wsgi:FaultWrapper.factory
  31. [filter:ratelimit]
  32. paste.filter_factory = trove.common.limits:RateLimitingMiddleware.factory
  33. [app:troveapp]
  34. paste.app_factory = trove.common.api:app_factory
  35. #Add this filter to log request and response for debugging
  36. [filter:debug]
  37. paste.filter_factory = trove.common.wsgi:Debug
复制代码
/etc/trove/trove.conf 内容如下:
  1. [DEFAULT]
  2. # Show more verbose log output (sets INFO log level output)
  3. verbose = True
  4. # Show debugging output in logs (sets DEBUG log level output)
  5. debug = True
  6. default_datastore = mysql
  7. datastore_manager = mysql
  8. # Address to bind the API server
  9. bind_host = 0.0.0.0
  10. # Port the bind the API server to
  11. bind_port = 8779
  12. # Number of child processes to run
  13. #trove_api_workers=5
  14. # AMQP Connection info
  15. rabbit_host = 127.0.0.1
  16. rabbit_password = guest
  17. # SQLAlchemy connection string for the reference implementation
  18. # registry server. Any valid SQLAlchemy connection string is fine.
  19. # See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
  20. # sql_connection = sqlite:///trove_test.sqlite
  21. sql_connection = mysql://trove:trove@127.0.0.1/trove?charset=utf8
  22. #sql_connection = postgresql://trove:trove@127.0.0.1/trove
  23. # Period in seconds after which SQLAlchemy should reestablish its connection
  24. # to the database.
  25. #
  26. # MySQL uses a default `wait_timeout` of 8 hours, after which it will drop
  27. # idle connections. This can result in 'MySQL Gone Away' exceptions. If you
  28. # notice this, you can lower this value to ensure that SQLAlchemy reconnects
  29. # before MySQL can drop the connection.
  30. sql_idle_timeout = 3600
  31. mysql.usage_timeout = 600
  32. # Maximum line size of message headers to be accepted.
  33. # max_header_line may need to be increased when using large tokens
  34. # (typically those generated by the Keystone v3 API with big service
  35. # catalogs)
  36. # max_header_line = 16384
  37. #DB Api Implementation
  38. db_api_implementation = "trove.db.sqlalchemy.api"
  39. # Path to the extensions
  40. api_extensions_path = trove/extensions/routes
  41. guest_config = /etc/trove/conf.d/guest_info
  42. cloudinit_location = /etc/trove/cloudinit
  43. # Configuration options for talking to nova via the novaclient.
  44. trove_auth_url = http://0.0.0.0:5000/v2.0
  45. nova_compute_url = http://127.0.0.1:8774/v2
  46. cinder_url = http://127.0.0.1:8776/v1
  47. swift_url = http://127.0.0.1:8080/v1/AUTH_
  48. heat_url = http://127.0.0.1:8004/v1
  49. use_heat = True
  50. template_path = /etc/trove/templates/
  51. # Config option for showing the IP address that nova doles out
  52. default_neutron_networks = 9cbae051-78c7-4574-968e-2cb9b0f410ad
  53. network_label_regex = ^private$
  54. #ip_regex = ^(15.|123.)
  55. # Config options for enabling volume service
  56. trove_volume_support = True
  57. block_device_mapping = vdb
  58. device_path = /dev/vdb
  59. # Maximum volume size for an instance
  60. max_accepted_volume_size = 10
  61. max_instances_per_user = 5
  62. # Maximum volume capacity (in GB) spanning across all trove volumes per tenant
  63. max_volumes_per_user = 100
  64. max_backups_per_user = 5
  65. volume_time_out=30
  66. # Config options for rate limits
  67. http_get_rate = 200
  68. http_post_rate = 200
  69. http_put_rate = 200
  70. http_delete_rate = 200
  71. # Trove DNS
  72. trove_dns_support = False
  73. dns_account_id = 123456
  74. dns_auth_url = http://127.0.0.1:5000/v2.0
  75. dns_username = user
  76. dns_passkey = password
  77. dns_ttl = 3600
  78. dns_domain_name = 'trove.com.'
  79. dns_domain_id = 11111111-1111-1111-1111-111111111111
  80. dns_driver = trove.dns.designate.driver.DesignateDriver
  81. dns_instance_entry_factory = trove.dns.designate.driver.DesignateInstanceEntryFactory
  82. dns_endpoint_url = http://127.0.0.1/v1/
  83. dns_service_type = dns
  84. # Taskmanager queue name
  85. taskmanager_queue = taskmanager
  86. # Auth
  87. admin_roles = admin
  88. # Users to ignore for user create/list/delete operations
  89. ignore_users = os_admin, root
  90. ignore_dbs = lost+found, mysql, information_schema
  91. # Guest related conf
  92. agent_heartbeat_time = 10
  93. agent_call_low_timeout = 5
  94. agent_call_high_timeout = 150
  95. # Reboot time out for instances
  96. reboot_time_out = 60
  97. # Trove api-paste file name
  98. api_paste_config = /etc/trove/api-paste.ini
  99. # ============ notifer queue kombu connection options ========================
  100. notifier_queue_hostname = 127.0.0.1
  101. notifier_queue_userid = guest
  102. notifier_queue_password = guest
  103. notifier_queue_ssl = False
  104. notifier_queue_port = 5672
  105. notifier_queue_virtual_host = /
  106. notifier_queue_transport = memory
  107. control_exchange = trove
  108. # ============ Logging information =============================
  109. log_dir = /var/log/trove
  110. log_file = trove-api.log
  111. # ============ SSL configuration (and enablement) =============================
  112. # In order to enable SSL for the trove api server, uncomment
  113. # the cert_file and key_file - and of course have those files
  114. # accessible. The existence of those setting and files will
  115. # enable SSL.
  116. [ssl]
  117. #cert_file = /path/to/server.crt
  118. #key_file = /path/to/server.key
  119. #optional:
  120. #ca_file = /path/to/ca_file
  121. [mysql]
  122. root_on_create = False
  123. # ================= Security groups related ========================
  124. # Each future datastore implementation should implement
  125. # its own oslo group with defined in it:
  126. # - tcp_ports; upd_ports;
  127. [mysql]
  128. # Format (single port or port range): A, B-C
  129. # where C greater than B
  130. tcp_ports = 3306
  131. [redis]
  132. # Format (single port or port range): A, B-C
  133. # where C greater than B
  134. tcp_ports = 6379
  135. [cassandra]
  136. tcp_ports = 7000, 7001, 9042, 9160
  137. [couchbase]
  138. tcp_ports = 8091, 8092, 4369, 11209-11211, 21100-21199
复制代码
trove-conductor 配置
/etc/trove/trove-conductor.conf 内容如下:
  1. [DEFAULT]
  2. verbose = True
  3. debug = True
  4. control_exchange = trove
  5. trove_auth_url = http://127.0.0.1:5000/v2.0
  6. sql_connection = mysql://trove:trove@localhost/trove?charset=utf8
  7. rabbit_host = 127.0.0.1
  8. rabbit_password = guest
复制代码
trove-taskmanager 配置
/etc/trove/trove-taskmanager.conf 内容如下:
  1. [DEFAULT]
  2. # Show more verbose log output (sets INFO log level output)
  3. verbose = True
  4. # Show debugging output in logs (sets DEBUG log level output)
  5. debug = True
  6. # Updates service and instance task statuses if instance failed become active
  7. update_status_on_fail = False
  8. # AMQP Connection info
  9. rabbit_host=127.0.0.1
  10. rabbit_password=guest
  11. # SQLAlchemy connection string for the reference implementation
  12. # registry server. Any valid SQLAlchemy connection string is fine.
  13. # See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
  14. sql_connection = mysql://trove:trove@localhost/trove?charset=utf8
  15. # sql_connection = mysql://root:root@localhost/trove
  16. # Period in seconds after which SQLAlchemy should reestablish its connection
  17. # to the database.
  18. #
  19. # MySQL uses a default `wait_timeout` of 8 hours, after which it will drop
  20. # idle connections. This can result in 'MySQL Gone Away' exceptions. If you
  21. # notice this, you can lower this value to ensure that SQLAlchemy reconnects
  22. # before MySQL can drop the connection.
  23. sql_idle_timeout = 3600
  24. #DB Api Implementation
  25. db_api_implementation = trove.db.sqlalchemy.api
  26. # Configuration options for talking to nova via the novaclient.
  27. trove_auth_url = http://0.0.0.0:5000/v2.0
  28. nova_compute_url = http://127.0.0.1:8774/v2
  29. cinder_url = http://127.0.0.1:8776/v1
  30. swift_url = http://127.0.0.1:8080/v1/AUTH_
  31. heat_url = http://127.0.0.1:8004/v1
  32. use_heat = True
  33. # Config options for enabling volume service
  34. trove_volume_support = True
  35. block_device_mapping = vdb
  36. device_path = /dev/vdb
  37. mount_point = /var/lib/mysql
  38. volume_time_out=30
  39. server_delete_time_out=480
  40. # Configuration options for talking to nova via the novaclient.
  41. # These options are for an admin user in your keystone config.
  42. # It proxy's the token received from the user to send to nova via this admin users creds,
  43. # basically acting like the client via that proxy token.
  44. nova_proxy_admin_user = admin
  45. nova_proxy_admin_pass = password
  46. nova_proxy_admin_tenant_name = admin
  47. # Manager impl for the taskmanager
  48. taskmanager_manager=trove.taskmanager.manager.Manager
  49. # Manager sends Exists Notifications
  50. exists_notification_transformer = trove.extensions.mgmt.instances.models.NovaNotificationTransformer
  51. exists_notification_ticks = 30
  52. #notification_service_id = mysql:2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b
  53. # Trove DNS
  54. trove_dns_support = False
  55. dns_account_id = 123456
  56. dns_auth_url = http://127.0.0.1:5000/v2.0
  57. dns_username = user
  58. dns_passkey = password
  59. dns_ttl = 3600
  60. dns_domain_name = 'trove.com.'
  61. dns_domain_id = 11111111-1111-1111-1111-111111111111
  62. dns_driver = trove.dns.designate.driver.DesignateDriver
  63. dns_instance_entry_factory = trove.dns.designate.driver.DesignateInstanceEntryFactory
  64. dns_endpoint_url = http://127.0.0.1/v1/
  65. dns_service_type = dns
  66. # Trove Security Groups for Instances
  67. trove_security_groups_support = True
  68. trove_security_group_rule_cidr = 0.0.0.0/0
  69. # Guest related conf
  70. agent_heartbeat_time = 10
  71. agent_call_low_timeout = 5
  72. agent_call_high_timeout = 150
  73. # Whether to use nova's contrib api for create server with volume
  74. use_nova_server_volume = False
  75. # Config option for filtering the IP address that DNS uses
  76. network_label_regex = ^private$
  77. #ip_regex = ^(15.|123.)
  78. # Datastore templates
  79. template_path = /etc/trove/templates/
  80. # ============ notifer queue kombu connection options ========================
  81. notifier_queue_hostname = 127.0.0.1
  82. notifier_queue_userid = guest
  83. notifier_queue_password = guest
  84. notifier_queue_ssl = False
  85. notifier_queue_port = 5672
  86. notifier_queue_virtual_host = /
  87. notifier_queue_transport = memory
  88. # usage notifications
  89. notification_driver=trove.openstack.common.notifier.rpc_notifier
  90. control_exchange=trove
  91. # ============ Logging information =============================
  92. log_dir = /var/log/trove
  93. log_file = trove-taskmanager.log
  94. # ============ PyDev remote dubugging =============================
  95. # Enable or disable pydev remote debugging.
  96. # There are three values allowed: 'disabled', 'enabled' and 'auto'
  97. # If value is 'auto' tries to connect to remote debugger server,
  98. # but in case of error continue running with disabled debugging
  99. pydev_debug = disabled
  100. # remote debug server host and port options
  101. #pydev_debug_host = localhost
  102. #pydev_debug_port = 5678
  103. # path to pydevd library. It will be used if pydevd is absent in sys.path
  104. #pydev_path = <path>
  105. # ================= Guestagent related ========================
  106. #guest_config = $pybasedir/etc/trove/trove-guestagent.conf.sample
  107. #cloudinit_location = /etc/trove/cloudinit
  108. # ================= Security groups related ========================
  109. # Each future datastore implementation should implement
  110. # its own oslo group with defined in it:
  111. # - tcp_ports; upd_ports;
  112. [mysql]
  113. # Format (single port or port range): A, B-C
  114. # where C greater than B
  115. tcp_ports = 3306
  116. [redis]
  117. # Format (single port or port range): A, B-C
  118. # where C greater than B
  119. tcp_ports = 6379
  120. [cassandra]
  121. tcp_ports = 7000, 7001, 9042, 9160
  122. [couchbase]
  123. tcp_ports = 8091, 8092, 4369, 11209-11211, 21100-21199
复制代码
同步数据库
  1. trove-manage --config-file=/etc/trove/trove.conf db_sync
复制代码
制作系统服务 把 trove 三个服务做成系统服务,方便点。


/etc/init/trove-api.conf:
  1. description "Trove API Server"
  2. author "Longgeek <longgeek@gmail.com>"
  3. start on (local-filesystems and net-device-up IFACE!=lo)
  4. stop on runlevel [016]
  5. respawn
  6. exec su -s /bin/sh -c "exec trove-api --config-file=/etc/trove/trove.conf" root
复制代码
/etc/init/trove-conductor.conf:
  1. description "Trove Conductor Server"
  2. author "Longgeek <longgeek@gmail.com>"
  3. start on (local-filesystems and net-device-up IFACE!=lo)
  4. stop on runlevel [016]
  5. respawn
  6. exec su -s /bin/sh -c "exec trove-conductor --config-file=/etc/trove/trove-conductor.conf --log-file /var/log/trove/trove-conductor.log" root
复制代码
/etc/init/trove-taskmanager.conf:
  1. description "Trove TaskManager Server"
  2. author "Longgeek <longgeek@gmail.com>"
  3. start on (local-filesystems and net-device-up IFACE!=lo)
  4. stop on runlevel [016]
  5. respawn
  6. exec su -s /bin/sh -c "exec trove-taskmanager --config-file=/etc/trove/trove-taskmanager.conf --log-file /var/log/trove/trove-taskmanager.log" root
复制代码
upstart 脚本链接:
  1. ln -s /lib/init/upstart-job /etc/init.d/trove-api
  2. ln -s /lib/init/upstart-job /etc/init.d/trove-conductor
  3. ln -s /lib/init/upstart-job /etc/init.d/trove-taskmanager
复制代码
加入到开启启动:
  1. update-rc.d trove-api defaults
  2. update-rc.d trove-conductor defaults
  3. update-rc.d trove-taskmanager defaults  
复制代码
启动服务
  1. for serv in api conductor taskmanager; do /etc/init.d/trove-$serv restart; done
复制代码
自定义 heat 模版上面在配置文件中指定了 heat 模版的路径,如下:
  1. template_path = /etc/trove/templates/
复制代码
需要拷贝源代码目录中的 templates 所有 heat 模版到 trove 目录中:

  1. cp -r /opt/trove/trove/templates /etc/trove/
复制代码
自定义 heat 模版,这时候你需要读些trove 镜像文章,应该会明白为什么要自定义 heat 模版:http://longgeek.com/2014/05/19/openstack-trove-dedicated-mirror-making


修改 heat 模版,在模版中可以看到 sudo service trove-guest start 这个 trove-guest 服务,它其实是一个 cli,只存在与 trove-integration 项目中,所以需要改为 trove-guestagent,同样可以添加多条命令,下面的 see 我用来替换了配置文件中 change_me 这个关键字为我的服务具体的 IP 地址,同样可以使用类似方法修改 rabbit_passwd、nova 密码之类的:
  1. vim /etc/trove/templates/mysql/heat.template
  2. 56       UserData:
  3. 57         Fn::Base64:
  4. 58           Fn::Join:
  5. 59           - ''
  6. 60           - ["#!/bin/bash -v\n",
  7. 61               "/opt/aws/bin/cfn-init\n",
  8. 62               "sudo sed -i 's/change_me/192.168.8.242/g' /etc/trove/trove-guestagent.conf\n",
  9. 63               "sudo /etc/init.d/trove-guestagent restart\n"]
复制代码
定义 Trovetrove 用来启动不同数据库,需要事先定义不同类型数据库,在 trove 里叫 datastore。
下面是定义一个 mysql type的过程,前提做好了 trove 的镜像,且已上传:

创建 datastore type:
  1. trove-manage datastore_update mysql ''
复制代码
查看 datastore:
  1. trove datastore-list
  2. +-------------------------------------------------------+-------------------+
  3. |                  id                                                                   |     name                |
  4. +-------------------------------------------------------+-------------------+
  5. | 10000000-0000-0000-0000-000000000001 | Legacy MySQL |
  6. | ea341501-c134-4a62-ab4f-47813a74d190    |    mysql              |
  7. +-------------------------------------------------------+-------------------+
复制代码
给 datastore 指定专属镜像、mysql 具体的版本,同时启用这个 datastore:
  1. glance image-list | grep 'Ubuntu-12.04.4-Server-Trove-Mysql-5.5' | awk '{print $2}'
  2. bb23f309-64d6-40ae-8d19-4d8404aabc39
  3. trove-manage --config-file=/etc/trove/trove.conf \
  4.                        datastore_version_update \
  5.                        mysql 5.5 mysql \
  6.                        bb23f309-64d6-40ae-8d19-4d8404aabc39 \
  7.                        mysql-server-5.5 1
复制代码
指定默认的版本:
  1. trove-manage --config-file=/etc/trove/trove.conf datastore_update mysql 5.5
复制代码
查看 datastore 信息:
  1. trove datastore-show mysql
  2. +-------------------+------------------------------------------------------+
  3. |     Property           |                Value                                                            |
  4. +-------------------+------------------------------------------------------+
  5. | default_version | 8bacae40-c1ab-4444-9720-6d574901dbb5 |
  6. |        id                      | ea341501-c134-4a62-ab4f-47813a74d190  |
  7. |       name                |                mysql                                                           |
  8. +-------------------+------------------------------------------------------+
复制代码
查看 datastore 有哪些版本:
  1. trove datastore-version-list mysql
  2. +------------------------------------------------------+-------+
  3. |                  id                                                                  | name |
  4. +------------------------------------------------------+-------+
  5. | 8bacae40-c1ab-4444-9720-6d574901dbb5 | 5.5    |
  6. +------------------------------------------------------+-------+
复制代码
查看 datastore 某个版本的详细信息:
  1. trove datastore-version-show 8bacae40-c1ab-4444-9720-6d574901dbb5
  2. +-----------+-------------------------------------------------------+
  3. |  Property |                Value                                                             |
  4. +------------+------------------------------------------------------+
  5. |   active       |                 True                                                             |
  6. | datastore | ea341501-c134-4a62-ab4f-47813a74d190  |
  7. |     id             | 8bacae40-c1ab-4444-9720-6d574901dbb5 |
  8. |   image       | cc3a7b02-5346-4d9f-8b94-7519c7429eee  |
  9. |    name        |                 5.5                                                               |
  10. |  packages  |           mysql-server-5.5                                          |
  11. +------------+-------------------------------------------------------+
复制代码
命令行方式创建 trove 实例先看看 trove create 需要哪些参数:
  1. trove create
  2. usage: trove create <name> <flavor_id>
  3.                                [--size <size>]
  4.                                [--databases <databases> [<databases> ...]]
  5.                                [--users <users> [<users> ...]] [--backup <backup>]
  6.                                [--availability_zone <availability_zone>]
  7.                                [--datastore <datastore>]
  8.                                [--datastore_version <datastore_version>]
  9.                                [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,port-id=port-uuid>]
  10.                                [--configuration <configuration>]
  11. error: too few arguments
  12. Try 'trove help create' for more information.
复制代码
一次性创建三个数据库: trovedba、trovedbb、trovedbc,并设置数据库用户和密码:
  1. trove create TROVE_INSTANCE_NAME 2 --size 2 \
  2.                                                                --databases trovedba trovedbb trovedbc \
  3.                                                                --users longgeek:password \
  4.                                                                --datastore_version 5.5 \
  5.                                                                --datastore mysql \
  6.                                                                --nic net-id=9cbae051-78c7-4574-968e-2cb9b0f410ad
复制代码
查看 trove instance 信息:
  1. trove list
  2. trove show INSTANCE_ID
  3. trove user-list INSTANCE_ID
  4. trove database-list INSTANCE_ID
复制代码
界面创建方式 trove 实例界面创建有一些缺陷,不能去指定 instance 所使用的网络、要创建数据库的类型,当然 horizon 的进度在 trove API 之后,估计 juno rc1、rc2 差不多就可以出来。现在的情况是界面上创建的 instance 后使用配置文件中指定的网络 id,用户没有办法去选择,同时创建的数据库类型也是在配置文件指定了默认的类型 default_datastore = mysql:

先上图看看 Trove 界面:
trove-database.jpg

创建一个 trove instance,输入 instance 名字,选择一个 flavor,以及使用的 cinder volume 大小:
trove-create-1.jpg

填入要创建的数据库名字、用户名、密码,以及访问限制:
trove-create-2.jpg

创建完成了,状态显示正在 Build…:
trove-create-done.jpg

那就看看它调用其它组件都做了什么,Heat 界面上自动生成了一个 stack,定义了 zone、volume、neutron、SecurityGroup、instance 等:
trove-heat.jpg

在来看看网络拓扑,绿色名为 Internal 是 admin 用户创建的一个共享内网网络,同时也写在了 trove.conf 中:
trove-neutron.jpg

在创建 trove instance 时候,分配了 5G 的 volume 给 vm:
trove-cinder.jpg

在 nova instance 界面中看到如下:
trove-nova-instance.jpg
创建 trove instance 时候会自动根据 datastore type 来指定一个单独的安全组,默认开了相关数据库服务端口号:
trove-instance-SG.jpg

刚才在 nova instance 界面中看到 vm 状态已经 Active,在回到 trove 的 database instance 上看到 vm 还是在 build 中,那就是 vm 正在启动,执行 cloud-init 自动扩展根分区、metadata 以及 heat 模版中自定义的脚本,最后重启了 trove-guestagent 服务,而 trove-guestagent 会监听 rpc 消息队列,trove-guestagent 服务启动后,更新状态为 Running,发送 rpc 消息,taskmanager 收到消息后,发送创建 db 请求,trove-guestagent 收到请求后创建相应 db,最后发送 Active 状态消息给 rpc,trove-taskmanager 收到 Active 消息后,不再发送创建数据库消息,而 trove-conductor 同时收到 trove-guestagent Active 消息后,去数据库里更新 trove instance 的状态,在界面就可以看到 instance Active 的状态了:
trove-database-active.jpg

现在就可以验证数据库和用户到底有没有创建成功,heat 模版会自动给 instance 添加 floating ip,可以通过 floating ip 连接到数据库:
  1. longgeek:~ Longgeek$ mysql -ulonggeek -ppassword -h 192.168.8.65
  2. Warning: Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 55
  5. Server version: 5.5.37-0ubuntu0.12.04.1 (Ubuntu)
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show databases;
  12. +-------------------------+
  13. | Database                  |
  14. +-------------------------+
  15. | information_schema |
  16. | dbname1                 |
  17. | dbname2                 |
  18. | dbname3                 |
  19. | dbname4                 |
  20. +------------------------+
  21. 5 rows in set (0.01 sec)
  22. mysql>
复制代码
在来看看备份操作,输入一个备份名字、选择备份的 trove instance:
trove-database-backup-create.jpg

trove-guestagent 会执行命令去备份数据库:
trove-database-backup-done.jpg

默认备份的数据是放在了 swift 对象存储上,增加了数据的冗余性:
trove-database-backup-swift.jpg

trove-guestagent 需要使用 keystone、amqp、swift,所在在创建 keystone、swift 的 endpoint 时候别弄成 127.0.0.1。
至于其它类型的数据库,还没有来得及做测试,后期有时间会记录一下。


##################################################################################
本文转自:http://longgeek.com/2014/05/22/source-installation-openstack-icehouse-trove-project/
参考文献与资料:
1.DBaaS与Trove:
http://www.wzxue.com/dbaas%E4%B8%8Etrove/





欢迎加入about云群9037177932227315139327136 ,云计算爱好者群,亦可关注about云腾讯认证空间||关注本站微信

没找到任何评论,期待你打破沉寂

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

本版积分规则

关闭

推荐上一条 /2 下一条