在IBM Cloud中使用IBM Cloud Shell进行Databases for PostgreSQL的预配并尝试连接

简要概述

使用命令行(IBM Cloud命令)部署和连接PostgreSQL服务实例。
感想:在执行时输出命令的帮助信息,但是配置比我想象的更简单、容易。

概要步骤

    1. 启动IBM Cloud Shell。

 

    1. 使用ibmcloud命令设置资源组。

 

    1. 搜索目录。

 

    1. 创建服务实例。

 

    1. 设置PostgreSQL的admin用户密码。

 

    使用admin用户登录。

1. 启动IBM云壳

image.png

2. 在IBM云Shell上设置资源组。

在IBM Cloud Shell启动后,由于没有设置资源组,因此我们需要进行设置。

TSOTA@cloudshell:~$ ibmcloud target 


API endpoint:      https://cloud.ibm.com   
Region:            jp-tok   
User:              xxxx   
Account:           xxxx 
Resource group:    No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'   
CF API endpoint:      
Org:                  
Space:
TSOTA@cloudshell:~$ ibmcloud resource groups
Retrieving all resource groups under account xxxx as xxxx...
OK
Name      ID                                 Default Group   State   
Default   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   true            ACTIVE  
TSOTA@cloudshell:~$ ibmcloud target -g Default
Targeted resource group Default

API endpoint:      https://cloud.ibm.com   
Region:            jp-tok   
User:              xxxx  
Account:           xxxx
Resource group:    Default   
CF API endpoint:      
Org:                  
Space:

搜索目录

在创建服务实例时,需要提供服务ID和计划ID,因此需要搜索并确认目录。

TSOTA@cloudshell:~$ ibmcloud catalog search postgreSQL
Getting offerings...
OK
Name                                                                      ID                                     Kind   
Databases for EnterpriseDB                                                databases-for-enterprisedb-group       service   
Databases for PostgreSQL                                                  databases-for-postgresql-group         service   
Hyper Protect DBaaS for PostgreSQL                                        024d3260-5cf4-11e9-90a2-37a496589afc   service   
OSS Record: Compose for PostgreSQL(compose-for-postgresql)                oss.compose-for-postgresql             oss   
OSS Record: Databases for PostgreSQL(databases-for-postgresql)            oss.databases-for-postgresql           oss   
OSS Record: Hyper Protect DBaaS for PostgreSQL(hyperp-dbaas-postgresql)   oss.hyperp-dbaas-postgresql            oss   
TSOTA@cloudshell:~$ 
TSOTA@cloudshell:~$ ibmcloud catalog service databases-for-postgresql-group  
Getting catalog entry...
OK

ID                 databases-for-postgresql-group   
Name               databases-for-postgresql-group   
Kind               service   
Provider           IBM   
Tags               apidocs_enabled, big_data, data_management, database, eu_access, gc_migrate, group, hipaa, ibm_created, service_endpoint_supported   
Active             true   
Description        PostgreSQL is a powerful, open source object-relational database that is highly customizable.   
Bindable           true   
Original Name         
RC Compatible      true   
RC Provisionable   false   
IAM Compatible     false   
Children           Name                        Kind         ID                                           Location   Original Location   Target      
                   compose-for-postgresql      service      ComposePostgreSQL-P                                                               
                   |__enterprise               plan         ComposePostgresqlEnterprise                                                       
                   |  |__enterprise-au-syd     deployment   ComposePostgresqlEnterprise:au-syd           au-syd                         bluemix-au-syd      
                   |  |__enterprise-eu-de      deployment   ComposePostgresqlEnterprise:eu-de            eu-de                          bluemix-eu-de      
                   |  |__enterprise-eu-gb      deployment   ComposePostgresqlEnterprise:eu-gb            eu-gb                          bluemix-eu-gb      
                   |  |__enterprise-us-east    deployment   ComposePostgresqlEnterprise:us-east          us-east                        bluemix-us-east      
                   |  |__enterprise-us-south   deployment   ComposePostgresqlEnterprise:us-south         us-south                       bluemix-us-south      
                   |__standard                 plan         ComposePostgresqlStandard                                                         
                      |__standard-au-syd       deployment   ComposePostgresqlStandard:au-syd             au-syd                         bluemix-au-syd      
                      |__standard-eu-de        deployment   ComposePostgresqlStandard:eu-de              eu-de                          bluemix-eu-de      
                      |__standard-eu-gb        deployment   ComposePostgresqlStandard:eu-gb              eu-gb                          bluemix-eu-gb      
                      |__standard-us-east      deployment   ComposePostgresqlStandard:us-east            us-east                        bluemix-us-east      
                      |__standard-us-south     deployment   ComposePostgresqlStandard:us-south           us-south                       bluemix-us-south      
                   databases-for-postgresql    service      databases-for-postgresql                                                          
                   |__standard                 plan         databases-for-postgresql-standard                                                 
                      |__standard-au-syd       deployment   databases-for-postgresql-standard:au-syd     au-syd                         bluemix-au-syd      
                      |__standard-che01        deployment   databases-for-postgresql-standard:che01      che01                          bluemix-che01      
                      |__standard-eu-de        deployment   databases-for-postgresql-standard:eu-de      eu-de                          bluemix-eu-de      
                      |__standard-eu-gb        deployment   databases-for-postgresql-standard:eu-gb      eu-gb                          bluemix-eu-gb      
                      |__standard-jp-tok       deployment   databases-for-postgresql-standard:jp-tok     jp-tok                         bluemix-jp-tok      
                      |__standard-osl01        deployment   databases-for-postgresql-standard:osl01      osl01                          bluemix-osl01      
                      |__standard-seo01        deployment   databases-for-postgresql-standard:seo01      seo01                          bluemix-seo01      
                      |__standard-us-east      deployment   databases-for-postgresql-standard:us-east    us-east                        bluemix-us-east      
                      |__standard-us-south     deployment   databases-for-postgresql-standard:us-south   us-south                       bluemix-us-south      
TSOTA@cloudshell:~$ 

创建服务实例

使用先前步骤中确认的服务ID和计划ID指定创建服务实例。创建一个名为postgreSQL2的服务实例。

TSOTA@cloudshell:~$ ibmcloud resource service-instance-create postgreSQL2 databases-for-postgresql standard jp-tok
Creating service instance postgreSQL2 in resource group Default of account ibmj-cloud-freeusage-p035 as TSOTA@jp.ibm.com...
OK
Service instance postgreSQL2 was created.

Name:                postgreSQL2   
ID:                  xxxx 
GUID:                xxxx  
Location:            jp-tok   
State:               provisioning   
Type:                service_instance   
Sub Type:            Public   
Service Endpoints:   public   
Allow Cleanup:       false   
Locked:              false   
Created at:          2020-12-12T05:06:54Z   
Updated at:          2020-12-12T05:06:54Z   
Last Operation:                      
                     Status    create in progress      
                     Message   Started create instance operation      

列出服务实例并检查其配置状态。等待状态变为Active。

TSOTA@cloudshell:~$ ibmcloud resource service-instances
Retrieving instances with type service_instance in resource group Default in all locations under account xxxx as xxxx...
OK
Name                              Location   State          Type   
・・・・
postgreSQL2                       jp-tok     provisioning   service_instance   
Retrieving instances with type service_instance in resource group Default in all locations under account xxxx as xxxx
OK
Name                              Location   State    Type   
・・・・
postgreSQL2                       jp-tok     active   service_instance   
TSOTA@cloudshell:~$ ibmcloud cdb ls
Retrieving instances for all database types in resource group Default in all locations under xxxx as xxxx...
OK
Name                          Location   State    
postgreSQL2                   jp-tok     active   

5. 设置PostgreSQL的admin用户密码。

设定 admin 用户的密码。

TSOTA@cloudshell:~$ ibmcloud cdb user-password postgreSQL2 admin
User Password>> 
Confirm User Password>> 
The user's password is being changed with this task:

Key                   Value   
ID                    xxxx   
Deployment ID         xxxx 
Description           Updating user.   
Created At            2020-12-12T05:21:46Z   
Status                running   
Progress Percentage   0   

Status                completed   
Progress Percentage   100   
Location              xxxx  
OK

以admin用户连接

您可以使用ibmcloud命令连接到数据库并执行SQL语句和命令。

TSOTA@cloudshell:~$ ibmcloud cdb deployment-connections postgreSQL2 --start
Database Password>> 
psql (10.15 (Ubuntu 10.15-0ubuntu0.18.04.1), server 12.5)
WARNING: psql major version 10, server major version 12.
         Some psql features might not work.
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

ibmclouddb=> select user;
 user  
-------
 admin
(1 row)

ibmclouddb=> create user user1 password 'isepassword';
CREATE ROLE
ibmclouddb=> create table t1(c1 int);
CREATE TABLE
ibmclouddb=> insert into t1 values (1);
INSERT 0 1
ibmclouddb=> select * from t1;
 c1 
----
  1
(1 row)

ibmclouddb=> \dt
 public | t1   | table | admin
ibmclouddb=> \q
TSOTA@cloudshell:~$ 

上面的内容。

广告
将在 10 秒后关闭
bannerAds