service broker如何对接华为云

举报
zhongjun2 发表于 2020/01/21 16:57:34 2020/01/21
【摘要】 什么是service broker通常程序员要编码数据库源语处理Mysql、PostgreSQL等数据库,逻辑复杂以后处理数据库的代码变的异常复杂,于是程序员把这些复杂的代码整理起来,就变成了service broker。在需要处理复杂sql逻辑的时候,调用service broker就可以用统一的命令实现。 service broker可以和cloudfoundry、openshift等配...

什么是service broker

通常程序员要编码数据库源语处理MysqlPostgreSQL等数据库,逻辑复杂以后处理数据库的代码变的异常复杂,于是程序员把这些复杂的代码整理起来,就变成了service broker。在需要处理复杂sql逻辑的时候,调用service broker就可以用统一的命令实现。

 

service broker可以和cloudfoundryopenshift等配合使用,平台上的应用需要对接数据库,只用安装service broker,配置好service broker需要的yaml文件,告诉service broker你需要管理什么数据库,service broker就帮你创建、绑定、删除等,帮你用简单的统一的命令管理不同类型的数据库。

 

 

如何本地测试service broker功能

 

1、  在华为云上创建rds

如果对rds参数非常熟悉的可以跳过此步骤

image.png

                   图1

image.pngimage.png

                   图2                                     3

 image.png

                  图4

rds-tt实例创建成功

image.png

                 图5

2rds绑定ip


image.pngimage.png

           图6                                           图7

3rds创建数据库

image.png

            图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": {

                            //234

                            "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


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。