CloudFoundry Service 使用

时间:2023-08-28 10:12:02

Mysql服务在V2版本号中github上有独立的releaseproject(cf-mysql-release),该release提供了一个Mysql-broker和一个Mysql-server和(broker-registrar,broker-deregistrar,acceptance-tests)

Broker是基于CF V2 ServiceBroker API开发,用于管理内部或外部Mysql数据库

一、MysqlBroker&Mysql部署

  1. 下载cf-mysql-release
    git clone https://github.com/cloudfoundry/cf-mysql-release
    cd cf-mysql-release
    ./update
  2. 编译并上传cf-mysql-release至blobstore
    bosh create release releases/cf-mysql-8.yml
    bosh upload release releases/cf-mysql-8.tgz
  3. 创建并编写yml部署文件
    ---
    name: CFMYSQL02
    director_uuid: fdd46e30-f2c5-41dc-9662-0976fdac5716 releases:
    - name: cf-mysql
    version: 8 compilation:
    workers: 2
    cloud_properties:
    ram: 2048
    disk: 6144
    cpu: 2
    network: default
    reuse_compilation_vms: true update:
    canaries: 1
    #waiting for 60s to get update job status
    canary_watch_time: 30000-180000
    update_watch_time: 30000-180000
    max_in_flight: 4
    max_errors: 4 networks:
    - name: default
    subnets:
    - range: 192.168.2.0/24
    # Reserved IPs are the IPs that BOSH should not use in the declared range.
    reserved:
    # IP addresses which you don't want allocated by BOSH
    - 192.168.2.20 - 192.168.2.55
    - 192.168.2.140 - 192.168.2.254
    # IP addresses which you don't want allocated by BOSH
    - 192.168.2.2 - 192.168.2.10
    # Static IPs are the IPs that are statically assigned to jobs in this manifest. The BOSH director does not attempt
    # to dynamically assign these to new VMs.
    static:
    - 192.168.2.56 - 192.168.2.100
    gateway: 192.168.2.1
    # If you configured your BOSH/micro-BOSH to enable DNS, leave the DNS section empty. The BOSH director automatically uses the
    # BOSH/micro-BOSH powerDNS IP. If any jobs ever need to resolve DNS entries outside the BOSH powerDNS subdomain
    # (*.microbosh by default), configure the powerDNS recursor in your bosh release.
    dns:
    - 192.168.2.2
    cloud_properties:
    name: "VM Network"
    meta:
    # override this in your stub to set the environment name,
    # which is used for the deployment name
    #
    # i.e. cf-tabasco
    environment: ~ external_domain: acp.local
    apps_domain: acp.local
    nats:
    user: nats
    password: c1oudc0w
    port: 4222
    machines:
    - 192.168.2.43
    use_gnatsd: true resource_pools:
    - name: services-small
    network: default
    size: 5
    stemcell:
    name: bosh-vsphere-esxi-ubuntu
    # Stemcell version 2200 is the first to support errands for aws and vsphere
    version: 2366
    cloud_properties:
    ram: 2048
    disk: 20480
    cpu: 1 jobs:
    - name: mysql
    release: cf-mysql
    template: mysql
    instances: 1
    resource_pool: services-small
    persistent_disk: 10000
    networks:
    - name: default
    static_ips: 192.168.2.56
    properties:
    admin_password: c1oudc0w
    max_connections: 1500
    max_user_connections: 40
    cluster_ips:
    - 192.168.2.56
    - name: cf-mysql-broker
    release: cf-mysql
    template: cf-mysql-broker
    instances: 1
    resource_pool: services-small
    networks:
    - name: default
    static_ips: 192.168.2.57
    properties:
    auth_username: root
    auth_password: c1oudc0w
    cookie_secret: c1oudc0w
    external_host: p-mysql.acp.local
    ssl_enabled: false
    skip_ssl_validation: true
    cc_api_uri: https://api.acp.local
    nats:
    user: nats
    password: c1oudc0w
    port: 4222
    machines:
    - 192.168.2.43
    use_gnatsd: true
    networks:
    broker_network: default
    services:
    - name: p-mysql
    id: 44b26033-1f54-4087-b7bc-da9652c2a539
    description: A MySQL service for application development and testing
    tags:
    - mysql
    max_db_per_node: 250
    metadata:
    displayName: "MySQL for Pivotal CF"
    imageUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABoxJREFUeNrkW01sG0UUnkQ90FNNOfVHilvKBQS2iASHVtiCHkAqxI3ECZG4KOJGnOZQxCVxeuHnEJz0BlVjF3FCyg9UooeKOogeqBTkOEov/DlS056a2hfCASm8b3izXY/XZr07Xq/hSSs7jr2775v3vu+92Zm+vb098X+2fR2/wAeZCL0k6YjzEeHXA9pXa3SU+H2R35f++nCu0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GDeMokYHAXKZJADwuWqXIasAuLD2Yz2IDM76vbtWSgQeAZKISKdxtGNg8nG6aV0x4tT1naey1976AtxpUpgMSanTfIHJkrs/qDwGe8MhnbzAJfFDRxuaIdQBCHUoTictMAAQvpgkQYWnA3CgSSpBZfC/DnSE1uUVAFtBgIAOT84dEAiqmkNEgFOac851qwYwbZgYUQBUgooE5DTIcy1zwZoU1cmunv1/tlTikRQ/IRXDwByhRYIAIBEEAKpKhOOxw0cdSa4hRbTaH2pR8l9lluwA4I9REaDJWR86/q3TdBppyCZI1SQARREim2IJxMhvVXfE1Z9u1/3/pWMn5IyzMQCw+oqqopoIwTNAtNeYVkchNE+jrKeHmn8wUAss64XQctBp4GTo9CB/hp8JNKiyekDSryMSBmvF8OgpQII+a4N8QyHEj5Br3XZeFksjY9JBXf6UiiA9pk6/6jv8nSrBfLcBQK+A/h8yia7zwfRHDaMNbkAh5QSQGwGyPxnSmyE8O+v60je7RMJJVI7V3T+szxAFPkgw17QXYGQKYZJEkOHktSU50arKZ/kkitrmrfYnZVb1ZXROzVA2DFxQFxGbZek85iHhPPL/a4oGD7NSWf2DZusD8MXpMIGg1hzIKbnNjbbnIxDZNPppVwAwCKiUwrgg0mvjE3VaSttqPiAdtlTwYalm64j7W/TKiICJ/4DzM63WD7tZKBkKafRaVznlvdsUUJEwETZpdFvvu4lgV3OCjGKhx5xPutk/4HpStIdAKLh13hUHOHACgAjrynEQXradH3jdMhPnjios64g97x3y9FyAJRIgzIUk5KNeN0753jbHy2vQRicCdnwVtX27e4SMA2ADIsnV42gvOG4cAC0iUgyGqV5CbZ/Nmd5L3NfJ3eMMRlI82jjtNk2g4+AZjHKxkxuo+7qxfV4tUXOwkqk9wW7tbwEGAJwbJQSR3aMDAAAAAElFTkSuQmCC"
    longDescription: "Provisioning a service instance creates a MySQL database. Binding applications to the instance creates unique credentials for each application to access the database."
    providerDisplayName: "Pivotal Software"
    documentationUrl: "http://docs.gopivotal.com/"
    supportUrl: "http://gopivotal.com/support/"
    dashboard_client:
    id: p-mysql
    secret: c1oudc0w
    plans:
    - name: 100mb-dev
    id: ab08f1bc-e6fc-4b56-a767-ee0fea6e3f20
    description: Shared MySQL Server
    max_storage_mb: 100
    metadata:
    costs:
    - amount:
    usd: 0.0
    unit: MONTH
    bullets:
    - Not for production use - server is not replicated
    - Shared MySQL server
    - 100 MB storage
    - 40 concurrent connections
    displayName: "100 MB Dev"
    mysql_node:
    host: 192.168.2.56 # 也能够设置成外部的mysql节点
    admin_password: c1oudc0w
    - name: broker-registrar
    template: broker-registrar
    release: cf-mysql
    instances: 1
    resource_pool: services-small
    lifecycle: errand
    networks:
    - name: default
    properties:
    cf:
    api_url: https://api.acp.local
    admin_username: admin
    admin_password: admin
    broker:
    name: p-mysql
    host: p-mysql.acp.local
    username: root
    password: c1oudc0w
    - name: broker-deregistrar
    template: broker-deregistrar
    release: cf-mysql
    instances: 1
    resource_pool: services-small
    lifecycle: errand
    networks:
    - name: default
    properties:
    cf:
    api_url: https://api.acp.local
    admin_username: admin
    admin_password: admin
    broker:
    name: p-mysql
    host: p-mysql.acp.local
    username: root
    password: c1oudc0w
    - name: acceptance-tests
    template: acceptance-tests
    release: cf-mysql
    instances: 1
    resource_pool: services-small
    lifecycle: errand
    networks:
    - name: default
    properties:
    cf:
    api_url: https://api.acp.local
    admin_username: admin
    admin_password: admin
    apps_domain: acp.local
    skip_ssl_validation: true
    broker:
    host: p-mysql.acp.local
    service:
    name: p-mysql
    plan_name: 100mb-dev
    max_storage_mb: 100
    properties: {} # Pivotal CF cannot generate global properties
  4. 部署
    bosh deploy

    CloudFoundry Service 使用

  5. 注冊Mysql-Broker
    cf create-service-broker p-mysql root c1oudc0w http://p-mysql.acp.local

    CloudFoundry Service 使用

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3poZW55YW5nX2dv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

  6. 改动service_plan的訪问权限为public
    cf curl /v2/service_plans

    CloudFoundry Service 使用

    找到guid后边的值并复制
    改动相应权限为public
    cf curl PUT /v2/service_plans/060cb8c2-3633-493c-acf1-3b60e78aacd4 -b '{"public":'true'}'
  7. 创建service
    cf create-service

    CloudFoundry Service 使用

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3poZW55YW5nX2dv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

  8. 绑定应用至service
    cf bind-service java-hello-offline-mysql p-mysql-32d67

    CloudFoundry Service 使用

  9. 上传绑定好的应用
    cf push java-hello-offline-mysql -b java-buildpack-offline

    CloudFoundry Service 使用

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3poZW55YW5nX2dv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

  10. 检查service
    cf services

    CloudFoundry Service 使用

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3poZW55YW5nX2dv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">