Oracle Cloud MySQL Serviceでは、GUIベースのダッシュボードだけでは無く、APIやPaaS Service Manager (PSM)コマンドライン・インタフェース(CLI)を利用してインスタンスを管理する事が可能です。GUIでの管理も使いやすくて良いのですが、Provisioningの自動化による工数削減にはAPIかCLIの活用が必用になるかと思います。
今回は、PSMを利用したインスタンスの作成と削除方法を此方で紹介します。先ずは、MySQL Cloud Serviceを検証環境等で活用してみて頂ければと思います。

Japanese Manual
https://docs.oracle.com/cd/E60665_01/jcs_gs/PSCLI/GUID-A63D73BD-4F22-472D-9E04-D998CEE68A00.htm

https://docs.oracle.com/cd/E60665_01/jcs_gs/PSCLI/toc.htm

インストール方法の詳細に関しては、シンプルですので上記マニュアルを確認下さい。
基本的には、以下の2ステップでインストールします。

STEP1:PSM用ソフトウエアのダウンロード

$ export USER=email.address@oracle.com
$ export PASSWD=password
$ export IDENTITYDOMAIN=myidentitydomain

curl -v -X GET -u ${USER}:${PASSWD} -H X-ID-TENANT-NAME:${IDENTITYDOMAIN} https://psm.europe.oraclecloud.com/paas/core/api/v1.1/cli/${IDENTITYDOMAIN}/client -o psmcli.zip

STEP2:PSM用ソフトウエアのインストール

[root@misc01 opc]# pip install -U psmcli.zip 
Processing ./psmcli.zip
Requirement already up-to-date: requests<=2.8.1,>=2.7.0 in /usr/lib/python2.7/site-packages (from psmcli==1.1.8)
Requirement already up-to-date: keyring<=5.6,>=5.4 in /usr/lib/python2.7/site-packages (from psmcli==1.1.8)
Requirement already up-to-date: colorama==0.3.3 in /usr/lib/python2.7/site-packages (from psmcli==1.1.8)
Requirement already up-to-date: PyYAML==3.11 in /usr/lib64/python2.7/site-packages (from psmcli==1.1.8)
Installing collected packages: psmcli
  Found existing installation: psmcli 1.1.8
    Uninstalling psmcli-1.1.8:
      Successfully uninstalled psmcli-1.1.8
  Running setup.py install for psmcli ... done
Successfully installed psmcli-1.1.8
[root@misc01 opc]# 

PSMインストール後の動作確認


[root@misc01 admin]# psm help

DESCRIPTION
  A command line tool to interact with Oracle Cloud Platform Services (PaaS)

SYNOPSIS
  psm <service> <command> [parameters]

AVAILABLE SERVICES
  o BDCSCE
       Oracle Big Data Cloud Service - Compute Edition
  o CONTAINER
       Oracle Container Cloud Service
  o IDCS
       Oracle Identity Cloud Service
  o MySQLCS
       Oracle MySQL Cloud Service
  o OEHCS
       Oracle Event Hub Cloud Service
  o OEHPCS
       Oracle Event Hub Cloud Service - Platform
  o accs
       Oracle Application Container Cloud Service
  o caching
       Oracle Caching Service
  o dbcs
       Oracle Database Cloud Service
  o ggcs
       Oracle GoldenGate Cloud Service
  o jcs
       Oracle Java Cloud Service
  o stack
       Oracle Cloud Stack Manager
  o setup
       Configure psm client options
  o update
       Update psm client to latest version
  o log
       View or update psm client log level
  o help
       Show help

AVAILABLE PARAMETERS
  -v, --version  
       Show current version of psm client

[root@misc01 admin]# 

自分のアイデンティティドメインが利用出来るように初期設定します。
設定が終わると、利用可能なサービスが表示されます。ここでは、MySQLを管理するのでMySQLCSを選択してコマンドを実行します。


[root@misc01 admin]# psm setup
Username: email.address@oracle.com
Password: 
Retype Password: 
Identity domain: myidentitydomain
Region [us]: 
Output format [json]: 
Please enter password for encrypted keyring: 
----------------------------------------------------
'psm setup' was successful. Available services are:

  o ANALYTICS : Oracle Analytics Cloud
  o BDCSCE : Oracle Big Data Cloud Service - Compute Edition
  o CONTAINER : Oracle Container Cloud Service
  o IDCS : Oracle Identity Cloud Service
  o IOTAssetMon : Oracle IoT Asset Monitoring Cloud Service
  o IOTEnterpriseApps : Oracle Internet of Things Cloud - Enterprise
  o IOTFleetMon : Oracle IoT Fleet Monitoring Cloud Service
  o IOTProdMonitoring : Oracle IoT Production Monitoring Cloud Service
  o MySQLCS : Oracle MySQL Cloud Service
  o OEHCS : Oracle Event Hub Cloud Service
  o OEHPCS : Oracle Event Hub Cloud Service - Platform
  o accs : Oracle Application Container Cloud Service
  o caching : Oracle Application Cache
  o dbcs : Oracle Database Cloud Service
  o ggcs : Oracle GoldenGate Cloud Service
  o jcs : Oracle Java Cloud Service
  o stack : Oracle Cloud Stack Manager
----------------------------------------------------
[root@misc01 admin]# 

補足:PSMが古い場合はアップグレードするようにプロンプトが出てきますので、必要に応じてアップデートして下さい。

[root@misc01 admin]# psm update
Please enter password for encrypted keyring: 
...Downloading the latest psm client distribution - version 1.1.12
...Updating psm client from version 1.1.11 to 1.1.12
...If prompted for password, enter sudo password
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Processing /tmp/psmcli.zip
Requirement already up-to-date: requests<=2.8.1,>=2.7.0 in /usr/lib/python3.4/site-packages (from psmcli==1.1.12)
Requirement already up-to-date: keyring<=5.6,>=5.4 in /usr/lib/python3.4/site-packages (from psmcli==1.1.12)
Requirement already up-to-date: colorama==0.3.3 in /usr/lib/python3.4/site-packages (from psmcli==1.1.12)
Requirement already up-to-date: PyYAML==3.11 in /usr/lib64/python3.4/site-packages (from psmcli==1.1.12)
Installing collected packages: psmcli
  Found existing installation: psmcli 1.1.11
    Uninstalling psmcli-1.1.11:
      Successfully uninstalled psmcli-1.1.11
  Running setup.py install for psmcli: started
    Running setup.py install for psmcli: finished with status 'done'
Successfully installed psmcli-1.1.12
...Cleaning up
[root@misc01 admin]# 

MySQLCSオプションで利用可能なコマンドは以下の通りです。
サービスを拡張中なので、適宜追加されていきます。


[root@misc01 admin]# psm MySQLCS help

DESCRIPTION
  Oracle MySQL Cloud Service

SYNOPSIS
  psm MySQLCS <command> [parameters]

AVAILABLE COMMANDS
  o services
       List all Oracle MySQL Cloud Service instances
  o service
       List Oracle MySQL Cloud Service instance
  o create-service
       Create Oracle MySQL Cloud Service
  o delete-service
       Delete operation for MySQL.
  o stop
       Stop one or more VMs that are running Oracle MySQL Cloud Service instance
  o start
       Start one or more VMs that are running Oracle MySQL Cloud Service instance
  o restart
       Restart one or more VMs that are running Oracle MySQL Cloud Service instance
  o scale
       Scale-Up or scale-Down the Compute Shape used by service hosts
  o add-storage
       Add Capacity to storage volumes
  o view-backups
       List all backups of Oracle MySQL Cloud Service instance
  o view-backup
       List a backup of Oracle MySQL Cloud Service instance
  o backup
       Backup MySQL
  o delete-backup
       Delete an existing backup.
  o view-restores
       List all restore operations for Oracle MySQL Cloud Service instance
  o view-restore
       List a specified restore operation for Oracle MySQL Cloud Service instance
  o restore
       Restore MySQL from a backup.
  o view-backup-config
       List backup configuration of Oracle MySQL Cloud Service instance
  o update-backup-config
       Update the backup configuration for the MySQL service.
  o available-patches
       List all available patches for Oracle MySQL Cloud Service instance
  o applied-patches
       List all applied patches for Oracle MySQL Cloud Service instance
  o patch
       This operation will apply a patch to the service
  o precheck-patch
       This operation will run a precheck for a patch on the given service
  o rollback
       This operation will rollback a previously applied patch
  o operation-status
       View status of Oracle MySQL Cloud Service instance operation
  o activities
       View activities for Oracle MySQL Cloud Service instance
  o access-rules
       List access rules for Oracle MySQL Cloud Service instance
  o multisite-access-rules
       List access rules for multi-site service Oracle MySQL Cloud Service instance
  o create-access-rule
       Create an access rule for Oracle MySQL Cloud Service instance
  o create-multisite-access-rule
       Create an access rule for multisite Oracle MySQL Cloud Service instance
  o delete-access-rule
       Delete an access rule for Oracle MySQL Cloud Service instance
  o delete-multisite-access-rule
       Delete an access rule for multi-site Oracle MySQL Cloud Service instance
  o enable-access-rule
       Enable an access rule for Oracle MySQL Cloud Service instance
  o enable-multisite-access-rule
       Enable an access rule for multi-site Oracle MySQL Cloud Service instance
  o disable-access-rule
       Disable an access rule for Oracle MySQL Cloud Service instance
  o disable-multisite-access-rule
       Disable an access rule for multi-site Oracle MySQL Cloud Service instance
  o help
       Show help

[root@misc01 admin]# 

MySQLインスタンスの作成
既存のインスタンスが存在していないので、MySQLCSオプションでインスタンスを作成してみます。
先ずは、MySQLCS create-serviceのオプションを確認してみます。


[root@misc01 admin]# psm MySQLCS services
Please enter password for encrypted keyring: 
{
    "services":{}
}
[root@misc01 admin]# psm MySQLCS create-service help

DESCRIPTION
  Create Oracle MySQL Cloud Service

SYNOPSIS
  psm MySQLCS create-service [parameters]
       -c, --config-payload <value>
       [-of, --output-format <value>]

AVAILABLE PARAMETERS
  -c, --config-payload    (file)
       Path to JSON file containing payload for this command. A sample payload is
       included in EXAMPLES below.

  -of, --output-format    (string)
       Desired output format. Valid values are [json, html]

EXAMPLES
  psm MySQLCS create-service -c /home/templates/create-service-payload.json

SAMPLE PAYLOAD
Required properties are indicated as "required". Replace in the actual payload with real values.
{
    "serviceName":"required",
    "serviceDescription":"",
    "backupDestination":"",
    "cloudStorageContainer":"",
    "cloudStorageUser":"",
    "cloudStoragePassword":"",
    "cloudStorageContainerAutoGenerate":"",
    "vmPublicKeyText":"required",
    "serviceLevel":"required",
    "meteringFrequency":"",
    "serviceVersion":"required",
    "edition":"required",
    "vmUser":"required",
    "region":"",
    "availabilityDomain":"",
    "noRollback":"",
    "isManaged":"",
    "ipNetwork":"",
    "components":{
        "mysql":{
            "shape":"required",
            "mysqlUserName":"required",
            "mysqlUserPassword":"required",
            "mysqlPort":"required",
            "mysqlEMPort":"",
            "dbStorage":"required",
            "dbName":"required",
            "mysqlCharset":"",
            "mysqlCollation":"",
            "enterpriseMonitor":"",
            "enterpriseMonitorManagerUser":"",
            "enterpriseMonitorManagerPassword":"",
            "enterpriseMonitorAgentUser":"",
            "enterpriseMonitorAgentPassword":""
        }
    }
}

[root@misc01 admin]# 

上記のように、事前にサーバー構成を定義した、JSONフォーマットの定義ファイルの作成が必用ですので、以下のマニュアルを見て、定義ファイルを作成して下さい。

https://docs.oracle.com/cd/E60665_01/jcs_gs/PSCLI/GUID-C7254B5C-67E5-4321-A7ED-A6376FBC7956.htm

https://docs.oracle.com/en/cloud/paas/java-cloud/pscli/mysqlcs-create-service.html

JSONファイルの作成が終わったら、ファイルを指定してインスタンスを作成してみます。

[root@misc01 opc]# cat create-service-payload.json 
{
    "serviceName":"PSM01",
    "serviceDescription":"Create instance from PSM",
    "backupDestination":"NONE",
    "vmPublicKeyText":"ssh-rsa CBBB3NzaC2yc2EBBABBJQAAAQEAlL6Ud4xUYxHcKUUijX.......",
    "serviceLevel":"PAAS",
    "serviceVersion":"5.7",
    "vmUser":"opc",
    "components":{
        "mysql":{
            "shape":"oc3",
            "mysqlUserName":"root",
            "mysqlUserPassword":"MyPass-2017",
            "mysqlPort":"3306",
            "mysqlEMPort":"18443",
            "dbStorage":"25",
            "dbName":"PSM",
            "mysqlCharset":"utf8mb4",
            "enterpriseMonitor":"Yes",
            "enterpriseMonitorManagerUser":"mem_manager",
            "enterpriseMonitorManagerPassword":"password",
            "enterpriseMonitorAgentUser":"mem_user",
            "enterpriseMonitorAgentPassword":"password"
        }
    }
}
[root@misc01 opc]# psm MySQLCS create-service -c create-service-payload.json 
Please enter password for encrypted keyring: 
{
    "details":{
        "message":"Submitted job to create service [PSM01] in domain [myidentitydomain].",
        "jobId":"10382276"
    }
}
Job ID : 10382276
[root@misc01 opc]# 

インスタンスの作成が完了したら、SSHのみ初期設定ではアクセス可能ですので、
SSHでプライベート鍵を利用してアクセスしてみて下さい。
MySQLには、JSONで定義したrootパスワードが設定されているので、指定したパスワードを利用してアクセス確認して下さい。


[oracle@psm01-mysql-1 opc]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 968
Server version: 5.7.17-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


mysql> select user,host,authentication_string from mysql.user where user = 'root';
+------+------+-------------------------------------------+
| user | host | authentication_string                     |
+------+------+-------------------------------------------+
| root | %    | *C6918734E7352333C2B35180C978E969B5CA1972 |
+------+------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> 

MySQLインスタンスの削除
PSMコマンドでインスタンスの状況を確認して、インスタンスが不要になったら以下の様にdelete-serviceオプションでインスタンスを削除して下さい。


[root@misc01 opc]# psm MySQLCS services | grep -A10 serviceId
Please enter password for encrypted keyring: 
            "serviceId":303252,
            "serviceName":"PSM01",
            "serviceType":"MySQLCS",
            "domainName":"myidentitydomain",
            "serviceVersion":"5.7",
            "releaseVersion":"5.7.17",
            "metaVersion":"17.1.5-170205",
            "serviceDescription":"Create instance from PSM",
            "serviceLevel":"PAAS",
            "subscription":"HOURLY",
            "meteringFrequency":"HOURLY",



[root@misc01 opc]# psm MySQLCS delete-service -s PSM01
Please enter password for encrypted keyring: 
{
    "details":{
        "message":"Submitted job to delete service [PSM01] in domain [myidentitydomain].",
        "jobId":"10390616"
    }
}
Job ID : 10390616
[root@misc01 opc]# 


[root@misc01 opc]# psm MySQLCS services
Please enter password for encrypted keyring: 
{
    "services":{}
}
[root@misc01 opc]# 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

Post Navigation