版本说明:
CloudFoundry:V2版本-v149+(本文后续章节中的Manifest适用于149+版本的CF Release)
OpenStack:Grizzly版本+nova-network
CloudFoundry部署交流QQ群: 176302388Mysql服务现在在CloudFoundry的Github上有独立的工程支持,工程名称:cf-mysql-release,是基于V2 Broker API开发的新版Service,功能相当强大,可以通过Broker对内部或者外部的Mysql数据库进行管理,该服务最新的发布版本为Release-V5,本文介绍下如何使用BOSH部署两个独立的mysql服务,其中一个是纯Broker接口服务,另一个包括Mysql-Server,使用同一个release包,只是yml配置文件有差别。
git clone https://github.com/cloudfoundry/cf-mysql-release.git
cd cf-mysql-release
./update
方式一:先将release打包成一个压缩包,然后再执行上传命令,如
bosh create release releases/cf-mysql-5.yml
打包完成后,执行:
bosh upload release releases/cf-mysql-5.tgz
方式二:直接通过yml执行上传操作
bosh upload release releases/cf-mysql-5.yml
鉴于国内的网络环境速度慢且不太稳定,建议使用方式一。创建过程中要求输入release名称,这个自己取,本例中为:cf-mysql
Broker & Mysql-Server部署方案:
---
name: cf-mysql
director_uuid: 785aa0a6-87c7-4452-a862-c118afc90b37 # CHANGE
releases:
- name: cf-mysql
version: latest
compilation:
workers: 3
network: default
reuse_compilation_vms: true
cloud_properties:
instance_type: v1.compile # CHANGE
update:
canaries: 1
canary_watch_time: 30000-60000
update_watch_time: 30000-60000
max_in_flight: 4
networks:
- name: floating
type: vip
cloud_properties: {}
- name: default
type: dynamic
cloud_properties:
security_groups:
- default # CHANGE
resource_pools:
- name: small
network: default
size: 2
stemcell:
name: bosh-openstack-kvm-ubuntu
version: latest
cloud_properties:
instance_type: v1.small # CHANGE
jobs:
- name: cf-mysql
release: cf-mysql
template:
- mysql
instances: 1
resource_pool: small
persistent_disk: 100000
networks:
- name: default
default: [dns, gateway]
- name: floating
static_ips:
- 10.68.19.134 # CHANGE
properties:
admin_password: c1oudc0w
max_connections: 1500
max_user_connections: 40
- name: cf-mysql-broker
release: cf-mysql
template:
- cf-mysql-broker
instances: 1
resource_pool: small
networks:
- name: default
default: [dns, gateway]
properties:
auth_username: vsc
auth_password: c1oudc0w
services:
- name: mysql
id: 44b26033-1f54-4087-b7bc-da9652c2a539
description: MySQL service for application development and testing
tags:
- mysql
- relational
max_db_per_node: 250
metadata:
provider:
name:
listing:
imageUrl:
blurb: MySQL service for application development and testing
plans:
- name: default
id: ab08f1bc-e6fc-4b56-a767-ee0fea6e3f20
description: Shared MySQL Server, 100mb persistent disk, 40 max concurrent connections
max_storage_mb: 100
metadata:
cost: 0
bullets:
- content: Shared MySQL server
- content: 100 MB storage
- content: 40 concurrent connections
mysql_node:
host: 10.68.19.134
admin_password: c1oudc0w
properties: {}
说明:Bosh创建两个虚拟机实例,cf-mysql和cf-mysql-broker,cf-mysql作为mysql-server的运行和数据存储环境,cf-mysql-broker用于提供管理接口。
Broker Only部署方案:---
name: cf-mysql-ex
director_uuid: 785aa0a6-87c7-4452-a862-c118afc90b37 # CHANGE
releases:
- name: cf-mysql
version: latest
compilation:
workers: 3
network: default
reuse_compilation_vms: true
cloud_properties:
instance_type: v1.compile # CHANGE
update:
canaries: 1
canary_watch_time: 30000-60000
update_watch_time: 30000-60000
max_in_flight: 4
networks:
- name: floating
type: vip
cloud_properties: {}
- name: default
type: dynamic
cloud_properties:
security_groups:
- default # CHANGE
resource_pools:
- name: small
network: default
size: 1
stemcell:
name: bosh-openstack-kvm-ubuntu
version: latest
cloud_properties:
instance_type: v1.small # CHANGE
jobs:
- name: cf-mysql-broker
release: cf-mysql
template:
- cf-mysql-broker
instances: 1
resource_pool: small
networks:
- name: default
default: [dns, gateway]
properties:
auth_username: vsc
auth_password: c1oudc0w
services:
- name: mysql-ex
id: 44836033-1f54-4087-b7bc-da9652c2a539
description: MySQL service for application development and testing
tags:
- mysql
- relational
max_db_per_node: 250
metadata:
provider:
name:
listing:
imageUrl:
blurb: MySQL service for application development and testing
plans:
- name: default
id: ku08f1bc-e6fc-4b56-a767-ee0fea6e3f20
description: Shared MySQL Server, 100mb persistent disk, 40 max concurrent connections
max_storage_mb: 100
metadata:
cost: 0
bullets:
- content: Shared MySQL server
- content: 100 MB storage
- content: 40 concurrent connections
mysql_node:
host: 10.68.19.62
admin_password: c1oudc0w
properties: {}
说明:Bosh只创建了一个虚拟机实例cf-mysql-broker用于提供管理mysql数据库的接口,本方案中并没有提供mysql-server服务,而是采用外部的mysql数据库,IP:10.68.19.62就是外部mysql数据库的访问地址,而admin_password就是root用户的密码。注意:需要mysql数据库对root用户进行“%”授权,否则不能远程访问。
Broker & Mysql-Server方案部署:
bosh deployment cf-mysql.yml
bosh deploy
Broker Only 方案部署:
bosh deployment cf-mysql-ex.yml
bosh deploy
部署结果:
bosh vms
Deployment `cf-mysql'
Director task 167
Task 167 done
+-------------------+---------+---------------+--------------------------+
| Job/index | State | Resource Pool | IPs |
+-------------------+---------+---------------+--------------------------+
| cf-mysql/0 | running | small | 50.50.0.27, 10.68.19.134 |
| cf-mysql-broker/0 | running | small | 50.50.0.26 |
+-------------------+---------+---------------+--------------------------+
VMs total: 2
Deployment `cf-mysql-ex'
Director task 168
Task 168 done
+-------------------+---------+---------------+------------+
| Job/index | State | Resource Pool | IPs |
+-------------------+---------+---------------+------------+
| cf-mysql-broker/0 | running | small | 50.50.0.28 |
+-------------------+---------+---------------+------------+
VMs total: 1
root@bosh-cli:~# cf add-service-broker mysql
URL> http://50.50.0.26
Username> vsc
Password> c1oudc0w
说明:URL--Mysql-Broker实例的访问地址,IP可以使用bosh vms查看,Username--Broker认证用户,在YAML配置文件中设置,Password--Broker认证用户的密码,在YAML配置文件中设置。
root@bosh-cli:~# cf add-service-broker mysql-ex
URL> http://50.50.0.28
Username> vsc
Password> c1oudc0w
V2 Broker创建后默认没有开放访问权限,所以需要手动打开,先查看Service Plan 的URL
cf curl /v2/service_plans
在输出的JSON数据中找到Service Plan的URL:
"service_plans": [
{
"metadata": {
"guid": "ac75ce76-dfe5-409a-84a2-42a654dd0ff8",
"url": "/v2/service_plans/ac75ce76-dfe5-409a-84a2-42a654dd0ff8",
"created_at": "2013-12-20T09:31:08+00:00",
"updated_at": null
},
"entity": {
"name": "100mb",
"free": true,
"description": "Shared MySQL Server, 100mb persistent disk, 40 max concurrent connections",
"service_guid": "fea49494-0953-4374-a668-3b9593fe14cb",
"extra": "{\"cost\":0,\"bullets\":[{\"content\":\"Shared MySQL server\"},{\"content\":\"100 MB storage\"},{\"content\":\"40 concurrent connections\"}]}",
"unique_id": "ab08f1bc-e6fc-4b56-a767-ee0fea6e3f20",
"public": false,
"service_url": "/v2/services/fea49494-0953-4374-a668-3b9593fe14cb",
"service_instances_url": "/v2/service_plans/ac75ce76-dfe5-409a-84a2-42a654dd0ff8/service_instances"
}
}
]
执行以下语句开放权限:
cf curl PUT /v2/service_plans/ac75ce76-dfe5-409a-84a2-42a654dd0ff8 -b '{"public":'true'}'
说明:mysql-ex同理操作
root@bosh-cli:~# cf create-service
1: blob 0.51
2: elasticsearch 0.20
3: memcached 1.4
4: mongodb 2.2
5: mysql , via
6: mysql-ex , via
7: postgresql 9.3
8: rabbitmq 3.0
9: redis 2.6
10: user-provided , via
What kind?> 5
Name?> mysql-166e6
1: default: Shared MySQL Server, 100mb persistent disk, 40 max concurrent connections
Which plan?> 1
Creating service mysql-166e6... OK
root@bosh-cli:~# cf create-service
1: blob 0.51
2: elasticsearch 0.20
3: memcached 1.4
4: mongodb 2.2
5: mysql , via
6: mysql-ex , via
7: postgresql 9.3
8: rabbitmq 3.0
9: redis 2.6
10: user-provided , via
What kind?> 6
Name?> mysql-ex-5a8a7
1: default: Shared MySQL Server, 100mb persistent disk, 40 max concurrent connections
Which plan?> 1
Creating service mysql-ex-5a8a7... OK
服务创建完毕,可以绑定到具体的应用APP上进行使用。