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]# 


バックアップをリモートのPublic Cloud上のオブジェクトストレージに直接送り、DR, BCP対策を行う事が可能ですが、mysqlbackupにもオブジェクトストレージに直接バックアップを送るオプションがあるので、OracleのPublic Cloudを利用して動作確認しました。

※ 2017年3月現在、MySQL Serviceが日本のデータセンタでは提供して無い為、EUの検証環境に対して検証を行いました。
開発環境としては、Enterprise版のモジュール、サポート、コンサルティングサポート含めて利用する事が可能ですので、TCOの削減が可能ですが。レスポンスが要求される本番環境としては、日本のデータセンターでのサービスが待ち遠しい所です。

  

検証したmysqlbackupのバージョン
最新は、mysqlbackup4.1です。

[root@misc01 opc]# /usr/local/mysqlbackup/bin/mysqlbackup --version
MySQL Enterprise Backup version 4.0.3 Linux-2.6.18-194.el5-x86_64 [2016/08/04] 
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All Rights Reserved.

クラウドストレージへのバックアップは此方のマニュアルを参照下さい。
https://dev.mysql.com/doc/mysql-enterprise-backup/4.1/en/meb-backup-cloud.html

バックアップの実行
ローカルのMySQLインスタンス上のサンプルデータベース(world)のみをオラクルのストレージクラウドサービスにバックアップ


[root@misc01 temp_dir]# /usr/local/mysqlbackup/bin/mysqlbackup --include=world.* -uroot -p --cloud-service=openstack \
> --cloud-container=objectstoragename --cloud-object=mysqlbackup_opc.img \
> --cloud-user-id=Storage-myidentitydomain:myaccount@oracle.com \
> --cloud-password=mypassword --cloud-ca-info=/etc/ssl/certs/ca-bundle.crt \
> --cloud-tempauth-url=https://myidentitydomain.storage.oraclecloud.com \
> --encrypt-password='encryptpass' --backup-dir=/home/admin/opc/temp_dir --backup-image=- backup-to-image
MySQL Enterprise Backup version 4.0.3 Linux-2.6.18-194.el5-x86_64 [2016/08/04] 
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 /usr/local/mysqlbackup/bin/mysqlbackup --include=world.* -uroot -p 
        --cloud-service=openstack --cloud-container=objectstoragename 
        --cloud-object=mysqlbackup_opc.img 
        --cloud-user-id=Storage-myidentitydomain:myaccount@oracle.com 
        --cloud-password=xxxxxxxxxx 
        --cloud-ca-info=/etc/ssl/certs/ca-bundle.crt 
        --cloud-tempauth-url=https://myidentitydomain.storage.oraclecloud.com 
        --encrypt-password=xxxxxxxxxxx --backup-dir=/home/admin/opc/temp_dir 
        --backup-image=- backup-to-image 

 mysqlbackup: INFO: 
Enter password: 
 mysqlbackup: INFO: MySQL server version is '5.7.17-enterprise-commercial-advanced-log'
 mysqlbackup: INFO: MySQL server compile os version is 'linux-glibc2.5'
 mysqlbackup: INFO: Got some server configuration information from running server.

 mysqlbackup: INFO: Validating cloud parameters.
IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'backup-to-image' run mysqlbackup
           prints "mysqlbackup completed OK!".

170313 21:15:25 mysqlbackup: INFO: MEB logfile created at /home/admin/opc/temp_dir/meta/MEB_2017-03-13.21-15-25_image_backup.log

--------------------------------------------------------------------
                       Server Repository Options:
--------------------------------------------------------------------
  datadir = /usr/local/mysql/data/
  innodb_data_home_dir = 
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /usr/local/mysql/data/
  innodb_log_files_in_group = 2
  innodb_log_file_size = 268435456
  innodb_page_size = 16384
  innodb_checksum_algorithm = crc32
  innodb_buffer_pool_filename = ib_buffer_pool
  innodb_undo_directory = /usr/local/mysql/data/
  innodb_undo_tablespaces = 0
  innodb_undo_logs = 128

--------------------------------------------------------------------
                       Backup Config Options:
--------------------------------------------------------------------
  datadir = /home/admin/opc/temp_dir/datadir
  innodb_data_home_dir = /home/admin/opc/temp_dir/datadir
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /home/admin/opc/temp_dir/datadir
  innodb_log_files_in_group = 2
  innodb_log_file_size = 268435456
  innodb_page_size = 16384
  innodb_checksum_algorithm = crc32
  innodb_buffer_pool_filename = ib_buffer_pool
  innodb_undo_directory = /home/admin/opc/temp_dir/datadir
  innodb_undo_tablespaces = 0
  innodb_undo_logs = 128

 mysqlbackup: INFO: Backup Image Path = 'stdout'
 mysqlbackup: INFO: Unique generated backup id for this is 14894073252216434

 mysqlbackup: INFO: Creating 14 buffers each of size 16777216.
 mysqlbackup: INFO: Checking if object already exists.
 mysqlbackup: INFO: This backup has encrypted tables, encrypt password is set.
New object(segment) name :/objectstoragename/mysqlbackup_opc.img_part_1.
170313 21:15:31 mysqlbackup: INFO: Full Image Backup operation starts with following threads
                1 read-threads    6 process-threads    1 write-threads
170313 21:15:31 mysqlbackup: INFO: System tablespace file format is Barracuda.
170313 21:15:31 mysqlbackup: INFO: Starting to copy all innodb files...
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/backup-my.cnf.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/meta/backup_create.xml.
170313 21:15:31 mysqlbackup: INFO: Found checkpoint at lsn 4984955644.
170313 21:15:31 mysqlbackup: INFO: Starting log scan from lsn 4984955392.
170313 21:15:31 mysqlbackup: INFO: Copying log...
170313 21:15:31 mysqlbackup: INFO: Log copied, lsn 4984955653.
170313 21:15:31 mysqlbackup: INFO: Copying /usr/local/mysql/data/ibdata1 (Barracuda file format).
Uploading part %:10 20 30 40 50 60 70 80 90 

Uploading part %:10 20 30 40 50 60 70 80 90 

Uploading part %:10 20 30 40 50 60 70 80 90 

Uploading part %:10 20 30 40 50 60 70 80 90 

170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/City.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/City_Sample.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/Country.ibd (Antelope file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/CountryLanguage.ibd (Antelope file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/T_STAT_SAMPLE.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world/T_TDE.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/City2.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/City3.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/City_Master.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/City_SnapShot.ibd (Barracuda file format).
Uploading part %:170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/City_Summary.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/T_GC_UK.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/T_JSON_FROM_TABLE_SCHEMA.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/T_Pump01.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/t1.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world2/t2.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world_x/City.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world_x/Country.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world_x/CountryInfo.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Copying /usr/local/mysql/data/world_x/CountryLanguage.ibd (Barracuda file format).
170313 21:26:15 mysqlbackup: INFO: Completing the copy of innodb files.
170313 21:26:16 mysqlbackup: INFO: Starting to copy Binlog files...
170313 21:26:16 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002623.
170313 21:26:16 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002624.
10 20 30 40 50 60 70 80 90 

170313 21:28:37 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002625.
170313 21:28:37 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002626.
170313 21:28:37 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002627.
170313 21:28:37 mysqlbackup: INFO: Preparing to lock tables: Connected to mysqld server.
170313 21:28:37 mysqlbackup: INFO: Starting to lock all the tables...
170313 21:28:37 mysqlbackup: INFO: All tables are locked and flushed to disk
170313 21:28:37 mysqlbackup: INFO: Copying /usr/local/mysql/data/mysql-bin.002628.
170313 21:28:37 mysqlbackup: INFO: Completed the copy of binlog files...
170313 21:28:37 mysqlbackup: INFO: Opening backup source directory '/usr/local/mysql/data'
170313 21:28:37 mysqlbackup: INFO: Starting to backup all non-innodb files in 
        subdirectories of '/usr/local/mysql/data'
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:37 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Adding database directory: datadir
170313 21:28:38 mysqlbackup: INFO: Completing the copy of all non-innodb files.
170313 21:28:38 mysqlbackup: INFO: A copied database page was modified at 4984955604.
          (This is the highest lsn found on page)
          Scanned log up to lsn 4984955653.
          Was able to parse the log up to lsn 4984955653.
170313 21:28:38 mysqlbackup: INFO: All tables unlocked
170313 21:28:38 mysqlbackup: INFO: All MySQL tables were locked for 0.546 seconds.
170313 21:28:38 mysqlbackup: INFO: Reading all global variables from the server.
170313 21:28:38 mysqlbackup: INFO: Completed reading of all global variables from the server.
 mysqlbackup: INFO: Writing config file for server '5.7.17-enterprise-commercial-advanced-log'.
170313 21:28:38 mysqlbackup: INFO: Creating server config files server-my.cnf and server-all.cnf in /home/admin/opc/temp_dir
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/meta/backup_variables.txt.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/datadir/ibbackup_logfile.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/server-all.cnf.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/server-my.cnf.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/meta/backup_gtid_executed.sql.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/meta/backup_content.xml.
 mysqlbackup: INFO: Copying meta file /home/admin/opc/temp_dir/meta/image_files.xml.
 mysqlbackup: INFO: OS: Flushing buffers.
Uploading part %:10 20 30 40 50 60 70 80 90  mysqlbackup: INFO: Received response code 201. 

 mysqlbackup: INFO: Uploading the manifest file.
 mysqlbackup: INFO: Cloud operation complete.
170313 21:29:48 mysqlbackup: INFO: Full Image Backup operation completed successfully.
170313 21:29:48 mysqlbackup: INFO: Backup image created successfully.
 mysqlbackup: INFO: Image Path = 'stdout'
170313 21:29:48 mysqlbackup: INFO: MySQL binlog position: filename mysql-bin.002628, position 194

-------------------------------------------------------------
   Parameters Summary         
-------------------------------------------------------------
   Start LSN                  : 4984955392
   End LSN                    : 4984955653
-------------------------------------------------------------

mysqlbackup completed OK!
[root@misc01 temp_dir]# 

Storage CloudサービスのAPIを利用してバックアップが出来ているか確認
例) myidentitydomain = 自分のIdentity Domain, objectstoragename = オブジェクトストレージ名

 curl -X GET -H "X-Auth-Token: $XAuth" https://myidentitydomain.storage.oraclecloud.com/v1/Storage-myidentitydomain/objectstoragename/ 

マニュアル

https://docs.oracle.com/cd/E60665_01/storagecs_common/CSSTO/GUID-5778ADBB-A0E8-4451-B886-362A3B7237DB.htm
https://docs.oracle.com/cloud/latest/mysql-cloud/CSMCS/api-Backups.html

バックアップイメージとして指定した、mysqlbackup_opc.imgが出来ている事が確認出来ました。

[root@misc01 opc]# ./opc_backup_confirm.sh | grep mysqlbackup
Press [Enter] key to resume.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   847  100   847    0     0    271      0  0:00:03  0:00:03 --:--:--   271
mysqlbackup_opc.img
mysqlbackup_opc.img_part_1
[root@misc01 opc]# 

補足:mysqldumpを利用する場合

■ mysqldumpでリモートサーバーにバックアップする場合

[admin@misc01 .ssh]$ mysqldump world -uroot -ppassword | gzip | ssh migration@xxx.xxx.xxx.xxx -i authorized_keys 'cat > /home/migration/mysqldump.sql.gz'
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed 
suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --al
l-databases --triggers --routines --events. 
Enter passphrase for key 'authorized_keys': 
[admin@misc01 .ssh]$ 

■ OPCのサーバーにてバックアップファイルの確認

bash-4.1$ hostname
shinyatest-mysql-1
bash-4.1$ pwd
/home/migration
-bash-4.1$ ls -l
total 152
-rw-r--r-- 1 migration migration 152518 Mar 14 02:08 mysqldump.sql.gz
-bash-4.1$ zcat mysqldump.sql.gz | grep CREATE
CREATE TABLE `City` (
CREATE TABLE `City_Sample` (
CREATE TABLE `Country` (
CREATE TABLE `CountryLanguage` (
CREATE TABLE `T_STAT_SAMPLE` (
CREATE TABLE `T_TDE` (
/*!50001 CREATE VIEW `V_Region` AS SELECT 
/*!50001 CREATE ALGORITHM=UNDEFINED */
-bash-4.1$ 

MySQL Router2.1βがリリースされていたので、念の為にMySQL Group Replicationとの連携を確認しました。まだ、βなので機能が全部追加されている訳ではないので、今後のGAに期待したいと思います。

1: Group Replication基本設定と動作
2: MySQL Router2.1βの基本動作確認
3: Single Primaryモードの場合のFailOverの挙動確認

検証で利用したMySQLのバージョン


[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot -S/home/mysql/gr/mysql1/my.sock -e "select @@version"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------------------------------------+
| @@version                                 |
+-------------------------------------------+
| 5.7.17-enterprise-commercial-advanced-log |
+-------------------------------------------+

グループレプリケーションメンバーのオプションファイル(my.cnf)の設定


[root@replications gr]# cat my1.cnf 
[mysqld]
socket     = /home/mysql/gr/mysql1/my.sock
port       = 63301
innodb_buffer_pool_size=32MB
datadir    = /home/mysql/gr/mysql1
user       = mysql
log_error   = /home/mysql/gr/mysql1/error.log
log-bin    = master-bin
server-id   =   1 
gtid-mode  = on
enforce-gtid-consistency = on
log-slave-updates = on
binlog-checksum = NONE
binlog-format = row
master-info-repository = TABLE
relay-log-info-repository = TABLE

slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=ON
slave_parallel_workers=8

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="00000000-1111-2222-3333-123456789ABC"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="127.0.0.1:63201"
loose-group_replication_group_seeds="127.0.0.1:63201,127.0.0.1:63202,127.0.0.1:63203"
loose-group_replication_bootstrap_group=off

### Option for Multi Master Mode
#loose-group_replication_single_primary_mode=FALSE
#loose-group_replication_enforce_update_everywhere_checks= TRUE
#tx_isolation = READ-COMMITTED

[root@replications gr]# cat my2.cnf 
[mysqld]
socket     = /home/mysql/gr/mysql2/my.sock
port       = 63302
innodb_buffer_pool_size=32MB
datadir    =/home/mysql/gr/mysql2
user       = mysql
log_error   = /home/mysql/gr/mysql2/error.log
log-bin    = master-bin
server-id   =   2 
gtid-mode  = on
enforce-gtid-consistency
log-slave-updates
binlog-checksum = NONE
binlog-format = row
master-info-repository = TABLE
relay-log-info-repository = TABLE

slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=ON
slave_parallel_workers=8

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="00000000-1111-2222-3333-123456789ABC"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="127.0.0.1:63202"
loose-group_replication_group_seeds="127.0.0.1:63201,127.0.0.1:63202,127.0.0.1:63203"
loose-group_replication_bootstrap_group=off

### Option for Multi Master Mode
#loose-group_replication_single_primary_mode=FALSE
#loose-group_replication_enforce_update_everywhere_checks= TRUE
#tx_isolation = READ-COMMITTED

[root@replications gr]# cat my3.cnf 
[mysqld]
socket     = /home/mysql/gr/mysql3/my.sock
port       = 63303
innodb_buffer_pool_size=32MB
datadir    = /home/mysql/gr/mysql3
user       = mysql 
log_error   = /home/mysql/gr/mysql3/error.log
log-bin    = master-bin
binlog-format = row
server-id   =   3 
gtid-mode  = on
enforce-gtid-consistency = on
log-slave-updates = on
binlog-checksum = NONE
master-info-repository = TABLE
relay-log-info-repository = TABLE

slave_parallel_type=LOGICAL_CLOCK
slave_preserve_commit_order=ON
slave_parallel_workers=8

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="00000000-1111-2222-3333-123456789ABC"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="127.0.0.1:63203"
loose-group_replication_group_seeds="127.0.0.1:63201,127.0.0.1:63202,127.0.0.1:63203"
loose-group_replication_bootstrap_group=off

### Option for Multi Master Mode
#loose-group_replication_single_primary_mode=FALSE
#loose-group_replication_enforce_update_everywhere_checks= TRUE
#tx_isolation = READ-COMMITTED
[root@replications gr]# 

MySQLインスタンスの起動

/usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/gr/my1.cnf &
/usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/gr/my2.cnf &
/usr/local/mysql/bin/mysqld --defaults-file=/home/mysql/gr/my3.cnf &

MySQLインスタンスへのアクセス

/usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql1/my.sock
/usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql2/my.sock
/usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql3/my.sock

■ 全てのサーバーにプラグインインストールとアカウント作成

INSTALL PLUGIN group_replication SONAME 'group_replication.so';
SET SQL_LOG_BIN=0;
CREATE USER gr_user@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO gr_user@'%';
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='gr_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';

■ マスターノードでグループ設定

SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;

■ セカンダリーノードをグループに参加させる

 
START GROUP_REPLICATION; 

Group Replicationの状態確認


mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST  | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| group_replication_applier | 698f11c8-0397-11e7-aae1-080027d65c57 | replications |       63301 | ONLINE       |
| group_replication_applier | 713ad572-0397-11e7-aca3-080027d65c57 | replications |       63302 | ONLINE       |
| group_replication_applier | 78b1d98a-0397-11e7-aef2-080027d65c57 | replications |       63303 | ONLINE       |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM performance_schema.replication_group_member_stats\G
*************************** 1. row ***************************
                      CHANNEL_NAME: group_replication_applier
                           VIEW_ID: 14889395677991618:3
                         MEMBER_ID: 698f11c8-0397-11e7-aae1-080027d65c57
       COUNT_TRANSACTIONS_IN_QUEUE: 0
        COUNT_TRANSACTIONS_CHECKED: 0
          COUNT_CONFLICTS_DETECTED: 0
COUNT_TRANSACTIONS_ROWS_VALIDATING: 0
TRANSACTIONS_COMMITTED_ALL_MEMBERS: 00000000-1111-2222-3333-123456789abc:1-3
    LAST_CONFLICT_FREE_TRANSACTION: 
1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE '%single_primary%';
+---------------------------------------+-------+
| Variable_name                         | Value |
+---------------------------------------+-------+
| group_replication_single_primary_mode | ON    |
+---------------------------------------+-------+
1 row in set (0.00 sec)

mysql> SELECT * FROM performance_schema.global_status WHERE VARIABLE_NAME='group_replication_primary_member';
+----------------------------------+--------------------------------------+
| VARIABLE_NAME                    | VARIABLE_VALUE                       |
+----------------------------------+--------------------------------------+
| group_replication_primary_member | 698f11c8-0397-11e7-aae1-080027d65c57 |
+----------------------------------+--------------------------------------+
1 row in set (0.00 sec)

mysql> 

メモ:シングルプライマリーモードのみで利用する場合は、auto_incrementの値がぶつかる事は無いので、以下の値は1に調整しても問題無い。


[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql1/my.sock -e "show variables like 'auto_inc%'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 7     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql2/my.sock -e "show variables like 'auto_inc%'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 7     |
| auto_increment_offset    | 2     |
+--------------------------+-------+
[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql3/my.sock -e "show variables like 'auto_inc%'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 7     |
| auto_increment_offset    | 3     |
+--------------------------+-------+
[root@replications gr]# 

[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql1/my.sock -e "show variables like 'group_replication_auto%';"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| group_replication_auto_increment_increment | 7     |
+--------------------------------------------+-------+
[root@replications gr]# 

シングルプライマリーモードでは以下のように、PRIMARYノードのみで書き込みが可能になっている。(SECONDARYは、read_only & super_read_only)


[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql1/my.sock -e "SHOW VARIABLES LIKE '%read_only'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_read_only | OFF   |
| read_only        | OFF   |
| super_read_only  | OFF   |
| tx_read_only     | OFF   |
+------------------+-------+
[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql2/my.sock -e "SHOW VARIABLES LIKE '%read_only'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_read_only | OFF   |
| read_only        | ON    |
| super_read_only  | ON    |
| tx_read_only     | OFF   |
+------------------+-------+
[root@replications gr]# /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql3/my.sock -e "SHOW VARIABLES LIKE '%read_only'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_read_only | OFF   |
| read_only        | ON    |
| super_read_only  | ON    |
| tx_read_only     | OFF   |
+------------------+-------+
[root@replications gr]# 

参考: http://mysqlhighavailability.com/gr/doc/getting_started.html

MySQL Router2.1(β)でInnoDB Clusterを利用しないで検証
MEMO: InnoDB Clusterを使わない場合は、GR内部にレプリケーション管理用のメタデータが出来ていない。


[root@replications bin]# ./mysqlrouter --version
MySQL Router v2.1.2 on Linux (64-bit) (GPL community edition)
[root@replications bin]# 

[root@replications mysql]# /home/mysql/mysqlrouter/bin/mysqlrouter --bootstrap 127.0.0.1:63301 --directory /home/mysql/mysqlrouter/tmp --conf-usePlease enter MySQL password for root: 
Error: The provided server does not seem to contain metadata for a MySQL InnoDB cluster
[root@replications mysql]# 

※ こちらは、別途確認します。

InnoDB Clusterに関しては、以前のブログ投稿を確認下さい。
http://variable.jp/2016/09/28/mysql-innodb-cluster%E6%A6%82%E8%A6%81/

以下、MySQL Routerの動作検証で利用した定義ファイル設定 
シングルプライマリーモードの場合の設定は、以下のルールになっているので63302をFailOver先に設定。

In the event the primary member is removed from the group, then an election is performed and a new primary is chosen from the remaining servers in the group. This election is performed by looking at the new view, ordering the server UUIDs in lexicographical order and by picking the first one.

https://dev.mysql.com/doc/refman/5.7/en/group-replication-single-primary-mode.html


[root@replications gr]# cat /etc/mysqlrouter/mysqlrouter.conf
[DEFAULT]
logging_folder=/home/mysql/mysqlrouter/tmp

[logger]
level = INFO

[routing:failover]
bind_port = 7001
mode = read-write
destinations = 127.0.0.1:63301,127.0.0.1:63302

[routing:balancing]
bind_port = 7002
mode = read-only
destinations = 127.0.0.1:63302,127.0.0.1:63303

#[metadata_cache]
#bootstrap_server_addresses=mysql://127.0.0.1:63301,mysql://127.0.0.1:63302,mysql://127.0.0.1:63303
#user=mysql_innodb_cluster_reader
#password=dtRSPqn
#metadata_cluster=test
#ttl=300
#metadata_replicaset=default

#[routing:default_rw]
#bind_port=6446
#destinations=metadata-cache:///default?role=PRIMARY
#mode=read-write

#[routing:default_ro]
#bind_port=6447
#destinations=metadata-cache:///default?role=SECONDARY
#mode=read-only
[root@replications gr]# 

MySQL Routerの起動

[root@replications bin]# ./mysqlrouter --config=/etc/mysqlrouter/mysqlrouter.conf &
[1] 2449
[root@replications bin]#

read-writeはFailOverモード、read-Onlyはラウンドロビン


[admin@replications ~]$ /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63301 |
+--------+
[admin@replications ~]$ /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63301 |
+--------+
[admin@replications ~]$ /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7002 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63302 |
+--------+
[admin@replications ~]$ /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7002 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63303 |
+--------+
[admin@replications ~]$ /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7002 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63302 |
+--------+
[admin@replications ~]$ 

PRIMARYをダウンさせた場合に、Single Primary Modeの仕様に従って、マスターが切り替わっている事が確認出来る。


[root@replications bin]# /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63301 |
+--------+
[root@replications bin]# /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63301 |
+--------+
[root@replications bin]#  /usr/local/mysql/bin/mysql -uroot -proot -S/home/mysql/gr/mysql1/my.sock -e "shutdown"
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@replications bin]# /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63302 |
+--------+
[root@replications bin]# /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "select @@port"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|  63302 |
+--------+

[root@replications bin]# /usr/local/mysql/bin/mysql -uroot -proot -h 127.0.0.1 -P 7001 -e "SELECT * FROM performance_schema.global_status WHERE VARIABLE_NAME='group_replication_primary_member'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------------------------+--------------------------------------+
| VARIABLE_NAME                    | VARIABLE_VALUE                       |
+----------------------------------+--------------------------------------+
| group_replication_primary_member | 713ad572-0397-11e7-aca3-080027d65c57 |
+----------------------------------+--------------------------------------+

[root@replications bin]#  /usr/local/mysql/bin/mysql -uroot -proot  -S/home/mysql/gr/mysql2/my.sock -e "SHOW VARIABLES LIKE '%read_only'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_read_only | OFF   |
| read_only        | OFF   |
| super_read_only  | OFF   |
| tx_read_only     | OFF   |
+------------------+-------+
[root@replications bin]# 


補足: 停止していた旧PRIMARYを起動すると、停止中に処理されたDDL、DMLも伝搬され復旧している事が確認出来る。


mysql> select @@port;
+--------+
| @@port |
+--------+
|  63301 |
+--------+
1 row in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected (2.40 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| GR                 |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

MySQL Router2.1を利用する場合は、上記のようにGRのメタデータを参照しなくても利用出来ますが、
やはり状況によって運用でカバーしなければいけない事を考えると、MySQL Router2.1がInnoDB Clusterのメタデータ無しで利用出来るようになるのを待つか、
MySQL Router2.1がGAになったタイミングでMySQLShellも合わせてGAになるのを待って、InnoDB Clusterとして利用した方が良さそうです。

MySQL Routerマニュアル:
https://downloads.mysql.com/docs/mysql-router-2.1-en.a4.pdf

MySQL Router以外のHAアプリケーション (HAProxy, SQLProxy)
※ MySQL Router2.1がβが外れる前や、使い慣れている場合は以下のようなバランサーも良いかと思います。
http://lefred.be/content/ha-with-mysql-group-replication-and-proxysql/
http://lefred.be/content/mysql-group-replication-as-ha-solution/