service broker如何对接华为云
什么是service broker
通常程序员要编码数据库源语处理Mysql、PostgreSQL等数据库,逻辑复杂以后处理数据库的代码变的异常复杂,于是程序员把这些复杂的代码整理起来,就变成了service broker。在需要处理复杂sql逻辑的时候,调用service broker就可以用统一的命令实现。
service broker可以和cloudfoundry、openshift等配合使用,平台上的应用需要对接数据库,只用安装service broker,配置好service broker需要的yaml文件,告诉service broker你需要管理什么数据库,service broker就帮你创建、绑定、删除等,帮你用简单的统一的命令管理不同类型的数据库。
如何本地测试service broker功能
1、 在华为云上创建rds
如果对rds参数非常熟悉的可以跳过此步骤
图1
图2 图3
图4
rds-tt实例创建成功
图5
2、rds绑定ip
图6 图7
3、rds创建数据库
图8
4、将图中的参数值记录到config.json文件中。
git clone https://github.com/huaweicloud/huaweicloud-service-broker cd huaweicloud-service-broker vi config.json |
其他类型的数据库参数配置详见:
https://github.com/huaweicloud/huaweicloud-service-broker/blob/master/config.json
https://github.com/huaweicloud/huaweicloud-service-broker/blob/master/docs/configuration.md
{ "broker_config": { "log_level": "DEBUG", "username": "username", "password": "password" }, "back_database": { "database_type": "mysql", //图2 "database_host": "100.3.3.3", //图7 "database_port": "3306", "database_name": "broker", //图8 "database_username": "root", //图4 "database_password": "ppp" //图4 }, // 详见:https://support.huaweicloud.com/api-iam/zh-cn_topic_0057845624.html "cloud_credentials": { "auth_url": "https://iam.cn-north-4.myhuaweicloud.com", "user_name": "user_name", "password": "psword", "domain_name": "domain_name", "tenant_name": "cn-north-4", "region": "cn-north-4", "access_key": "xxxxxxxxxxxxxxxx", "secret_key": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" }, "catalog": { "services": [ { "id": "275f3e0b-86fd-4303-946c-171374d29150", "name": "rds-mysql", "description": "RDS MySQL Service", "bindable": true, "tags": [ "mysql", "relational" ], "plan_updateable": true, "plans": [ { "id": "fc1b0ebf-aabf-4ab1-87e9-83544a5902e8", "name": "5.7.21", //图2 "description": "RDS MySQL 5.7.21", "metadata": { //图2、3、4 "parameters": { "datastore_type": "MySQL", "datastore_version": "5.7", "speccode": "rds.mysql.m1.xlarge", "volume_type": "ULTRAHIGH", "volume_size": 100, "availability_zone": "cn-north-4a", "vpc_id": "0157ad02-451d-4f93-9f8d-8e9b50ca8678", "subnet_id": "30e0ecdb-8e5d-4474-b755-68681be4d182", "security_group_id": "c879a26e-a36b-48f0-a635-61c67ec2128d", "database_username": "root" } } } ] } ] } } |
5、启动服务
./huaweicloud-service-broker --config config.json |
6、创建数据库
curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Broker-Api-Version: 2.x' -X PUT "http://username:password@localhost:3000/v2/service_instances/testrdsmysql?accepts_incomplete=true" -d '{"service_id":"275f3e0b-86fd-4303-946c-171374d29150","plan_id":"fc1b0ebf-aabf-4ab1-87e9-83544a5902e8","organization_guid":"organization_id","space_guid":"space_id","parameters":{"name":"testrdsmysql", "database_password": "Mysql1234!"}}}'
{} |
绑定链接数据库
#curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Broker-Api-Version: 2.x' -X PUT "http://username:password@localhost:3000/v2/service_instances/testrdsmysql/service_bindings/testrdsmysqlbinding" -d '{"service_id":"275f3e0b-86fd-4303-946c-171374d29150","plan_id":"fc1b0ebf-aabf-4ab1-87e9-83544a5902e8"}'
{"credentials":{"host":"root","port":3306,"username":"root","password":"Mysql1234!", "uri":"root:Mysql1234!@root:3306","type":"rds-mysql"}} |
其他去绑定数据库、删除数据库等操作命令详见如下链接:
https://github.com/huaweicloud/huaweicloud-service-broker/blob/master/scripts/lifecycle.sh
- 点赞
- 收藏
- 关注作者
评论(0)