Google Cloud SQL 2nd Generationã®FailOverãªã©
GAEã®ããã«åºæ¥ããã¨ããæ´å²çãªèæ¯ããããã¾ãGCEãã使ããã¨ããªãã£ã Cloud SQL (1st generation)ã§ãããæ¨å¹´ 2nd generation ããã¼ã¿ã¨ãªãã¾ãããããã©ã¼ãã³ã¹ã®é«ãã«ã¤ãã¦ã¯ã¢ãã¦ã³ã¹ããã¦ãã¾ããããã®è¨äºã¯FailOverãä¸å¿ã«ã2nd generationãæ¢ã£ã¦ããã¾ãã
Cloud SQLã¨ã¯
AWSã§è¨ãã¨ããã®RDSãããã¼ã¸ãSQL(RDB ãã£ã¨è¨ã㨠MySQL)ã§ããVMã¤ã³ã¹ã¿ã³ã¹ã«èªåã§MySQLãå ¥ãããããå¿è«å²é«ã§ãããããã¯ã¢ããã¨ããã§ã¤ã«ãªã¼ãã¨ãã®é¢åãGoogleãè¦ã¦ãããã¨ãããã®ã§ãã
æåã«çµè«
- ã¢ã¯ã»ã¹IPã¢ãã¬ã¹ã¯ãç¸å¤ããã Global IPã®ã¿
- ã¢ã¯ã»ã¹å IPã¢ãã¬ã¹ã§å¶é
- GCEã®å é¨ãããã¯ã¼ã¯ã«ä½æã¯åºæ¥ãªãããGCEå ããæ¥ç¶ããåã«ã¯ããããã¯ã¼ã¯é度çãªããã«ãã£ã¼ã¯ãªã(å¤å)
- RDSã®Multi-AZã«ç¸å½ããæ©è½ã¯ãããããããããGCEã¯Zone (AZ) ãã©ãä½é¢ãã¦ãããã¨ãæè¨ããã¦ããªã
- Multi-AZã¨æ¸ããããActive/Standbyã§ã¯ãªããActive/Active(RO) ãªã®ã§ãã©ã¡ããã¨è¨ã㨠AWS Auroraã«è¿ã (èªå¼ãçãä¹±æ´ãªè¨ãæ¹ã ããæ§æã¨ãã¦ã¯)
- FailOverã®æ©è½ã¯ããããã
èªåçã«ã¨ã³ããã¤ã³ããæ¸ãæããæ©è½ã¯ç¡ã
- ã¬ããªã±ã¼ã·ã§ã³æ§æ(semisync)
æ§æã¨å½¹å²
1ã¤ã®DBã¯ã©ã¹ã¿ã¨ãã¦ç®¡çãã¾ããåãã¼ã«ã«ã¤ãã¦
- ãã¹ã¿ãµã¼ã
æåéã ãã§ã¤ã«ãªã¼ãã¬ããªã«(RO)
ã¬ããªã«ã§ããããã§ã¤ã«ãªã¼ãæã«ãã¹ã¿ææ ¼ã®å¯¾è±¡ã¨ãªããã®ã§ããå¿ ããã¹ã¿ãµã¼ãã¨åãã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã¨ãªãã¾ã
ãªã¼ãã¬ããªã«(RO)
æåéãã®ã¬ããªã«ããã¹ã¿ãæ»ãã§ãããã¤ã¯ãã¹ã¿ææ ¼ããªãããã¹ã¿ãµã¼ãã¨ç°ãªãã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ãã§ãOKã§ã
ãã§ã¤ã«ãªã¼ãã¬ããªã«
ã¯Auroraã®Readerã«è¿ãåå¨ã§ããããã«å ãã¦ã絶対ã«ãã¹ã¿(Writer)ã«ææ ¼ããªããã¼ãããªã¼ãã¬ããªã«ã§ãã
å®è·µ
Developers Consoleãããããããã¦ããã°åºæ¥ã¾ãããã注æç¹ã®ã¿è¨è¼ãã¾ã
1) GCEããã®æ¥ç¶åæã§ããã°ãå¿è«ãªã¼ã¸ã§ã³ããããããã¨
2) ãã¹ã¿ã®ããã¯ã¢ãããåããªãã¨ãã¬ããªã«ãä½ããªã ãã㯠ãã§ã¤ã«ãªã¼ãã¬ããªã«ã§ããªã¼ãã¬ããªã«ã§ãåã
æ¥ç¶ç¢ºèª
mysqlã³ãã³ãã§æ¥ç¶ã§ãã¾ããåæã¦ã¼ã¶ã¯ root & ãã¹ç¡ããªã®ã§ãã¨ã£ã¨ã¨ãã¹ã¯ã¼ããæå®ãã¾ãããã
ã¬ããªã±ã¼ã·ã§ã³ã®æ§å
- ãã¹ã¿ã¼ãã¼ã
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000006 | 120 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.08 sec) mysql> select @@binlog_format; +-----------------+ | @@binlog_format | +-----------------+ | ROW | +-----------------+ 1 row in set (0.09 sec)
- ãã§ã¤ã«ãªã¼ãã¬ããªã«
mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: [master global ip] Master_User: cloudsqlreplica Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000006 Read_Master_Log_Pos: 120 Relay_Log_File: relay-log.000005 Relay_Log_Pos: 283 Relay_Master_Log_File: mysql-bin.000006 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 120 Relay_Log_Space: 613 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: Yes Master_SSL_CA_File: master_server_ca.pem Master_SSL_CA_Path: /mysql/datadir Master_SSL_Cert: replica_cert.pem Master_SSL_Cipher: Master_SSL_Key: replica_pkey.pem Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: [master server id] Master_UUID: 5c40936b-cca9-11e5-8416-0242ac110009 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.14 sec) mysql> select @@read_only; +-------------+ | @@read_only | +-------------+ | 1 | +-------------+ 1 row in set (0.12 sec)
- ãªã¼ãã¬ããªã«
# show slave statusã¯ã»ã¼åã mysql> select @@read_only; +-------------+ | @@read_only | +-------------+ | 1 | +-------------+ 1 row in set (0.12 sec)
FailOver
2016/02/06ç¾å¨ãgcloiudã³ãã³ãã§ãFailOverçºåã®ã³ãã³ãã¯ããã¾ããããã ããCloud SQL APIãå©ãã°çºååºæ¥ã¾ãã https://cloud.google.com/sql/docs/high-availability#test
FailOveræåçºå
curlã§å©ãã¨æ¸ãã¦ããã¾ãããã¡ãã£ã¨ãããããã®ã§ API Exprolerã§ç°¡åã«æã¡ã¾ãã ã¾ããCloud SQL API ãæå¹åããã¾ãã
ãä¸å¯§ã«èªå°ãªã³ã¯ãããã®ã§ããã®ã¾ã¾Go
ä¸è¨ã®ããã¥ã¡ã³ãéãã«æã¤ã®ã§ãããSettingsVersion
ã£ã¦ãªããããï¼ ã¨ãããã¨ã§ããããå
ã«åå¾ãã¾ããgcloudã§åå¾å¯è½
gcloud sql instances describe <your master instance-name> .... kind: sql#settings locationPreference: kind: sql#locationPreference pricingPlan: PER_USE replicationType: SYNCHRONOUS settingsVersion: '19' tier: db-g1-small state: RUNNABLE
ãã®å ´åã 㨠19ã§ãã
ããã§å®è¡å¯è½ã§ã
Failoverã®æå
ãããªæãã§ã
- ãã¹ã¿ã¼æ¢ã¾ã
- ãã§ã¤ã«ãªã¼ãã¬ããªã«ãææ ¼
- å ãã¹ã¿ã¼å¾©å¸°
- å ãã¹ã¿-ããã¹ã¿ã¼ã«ææ ¼ãåæã«ãã§ã¤ã«ãªã¼ãã¬ããªã«ãã¦ã³
- ãã§ã¤ã«ãªã¼ãã¬ããªã«ãã¹ã¬ã¼ãã«æ»ã
AWSã¨ã¯ç°ãªããDNSã«ä¾åããªãIPãã¼ã¹ã¨è¨ãããªã·ã¼ã¯ãæªãæå³ã§ãä¸è²«ãã¦ãã¾ããããã¾ã§ãæå³çã«ãã§ã¤ã«ãªã¼ããèµ·ãããå ´åã®åãã§ãããå®éã®é害æãåãåä½ã«ãªãã¨æãã¾ãã
ç¹çãããã¨ã¯ããã¹ã¿ã¼ã®IPãã¨ã³ããã¤ã³ããä¸å®ã§ã¯ãªã
ã¨ããç¹ã§ããä¸è¨ãã¿ã¼ã³ã§ããã¹ã¿ã¼ã¯ ãã¹ã¿ã¼ -> ã¹ã¬ã¼ã -> ãã¹ã¿ã¼ã¨åãæ¿ãã£ã¦ãã¾ãããã¨ã³ããã¤ã³ã(IP)ã¯ããã追å¾ãã¦ãã¾ãããæåéãDBã®ãã§ã¤ã«ãªã¼ãã®ã¿ãå®è¡ããã¦ãã¾ãã
ãã®ç¹ãã©ãæ±ã(ãã)ãã1ã¤ã®å°å
¥ã¸ã®é害ã¨ãªããã¾ãããã§ã¤ã«ãªã¼ãã®ä¸é£ã®ä½æ¥ã®ä¸ã§ãåãµã¼ãã®ãã¹ã¿ææ ¼ã®ã¤ãã³ããæã¾ãããã¨ãåºæ¥ãªãã®ã§ãHAPoxyã®è¨å®ãå¤ãã¦ã¨ã³ããã¤ã³ããå¤æ´ããããconsulã¨ããé£ããã¨æãã¾ãã
ãã ãããã¯ã¨ã³ã¸ãã¢ã®åã§ãããæè¿ãã®æã®ã¨ã³ããã¤ã³ãåé¡ã¯ãã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªå´ã§å¸åããã®ã主æµã¨ãªã£ã¦ããæ°ããã¾ã(mongoãé¤ã) ããã§ã«PHPã§ãmysqlnd-msãªã© Read/Write spplitingãå«ãã¦HAæ§æã®ã¨ã³ããã¤ã³ãæ¢ãã¯ãã©ã¤ãã©ãªå´ã®æ¹ãæè»ã§ãã¤è³¢ãå®è£
ããã§ã«åºæãã¤ã¤ããã¨æãã¦ãã¾ãã
ãã¨ããå¤ããããï¼
1st ã«æ¯ã¹ã¦ããªãã®é¨åã Pre-Provisionãªæãã«ãªãã¾ããããã
ãã£ã¹ã¯
å¢ããã¾ãããæ¸ããã¾ããã1st-genã®æã¯å®å ¨ãªã³ããã³ãã ã£ãã®ã§ããã¡ããé¸ã¹ãã°ããã£ãã®ã§ããã10 -> 15GBãã試ãã¦ãã¾ããã - ãã¦ã³ã¿ã¤ã ã¯ã¼ã - ãã£ã¹ã¯æ¡å¼µä¸ã®ããã©ã¼ãã³ã¹ã¯è¨åããã¦ããªã
ãªãã容éã¢ããã«ãããæéã¯ãæãããã¨ãã¨ã®ãã£ã¹ã¯å®¹éã«ä¾åãããã¯è©¦ãã¦ãã¾ããããã ãã10 -> 15GB ã®å ´åã¯ãä¸ç¬ã§ããã
ã§ãããåé¡ãããã¾ãï¼ããã¯å¾è¿°
ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ã
å¤æ´ã§ãã¾ãããããã¡ãããµã¼ãã¹ææãã§ããæç¨æé㯠2 - 4 åç¨åº¦ã§ãçµæ§é ããª-
ãã®ä»
以å¤ãªã¨ããã§ã¯ãã©ã° = ãµã¼ããã©ã¡ã¼ã¿ã®å¤æ´ã§ãåèµ·åãå¿ é ãªç¹ã§ãããããä¸è¨ãã¤ã¢ãã°ãåºã¾ã
ãã§ã¤ã«ãªã¼ãã¬ããªã«ã¨å¤æ´
ãããçµæ§åé¡
ã§ãããã¹ã¿ã¼ã®ãã£ã¹ã¯ãã§ããããããåæã«ã¹ã¬ã¼ã(ãã§ã¤ã«ãªã¼ãã¬ããªã«)ããã«ããã¦ãããããªããã§ãããï¼
ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããå¤ãããã¹ã¬ã¼ããå¤ãããããªããã§ãããï¼æåã«ä¸ç·ã«ããªãã¨ãã¡ã¨ãè¨ããªãã
ãããå¤ãããªããã§ããã
ã¨ãããã¨ã¯ããã¹ã¿ã¼ã®ã¹ããã¯ãå¤ããããã§ã¤ã«ãªã¼ãã¬ããªã«ä½ãç´ã
ã¨ãããã¨ã«ãªãã¾ããããã¯ã¤ã±ã¦ãªããªã¼
ã¡ãªã¿ã«ãã®ç¹ã¯ããã¥ã¡ã³ãã¨çç¾ãã¦ãã¾ãã
After the failover replica is created, you can change all configuration settings of the instance, except that you can not enable backups or change the activation policy.
ã¾ã¨ã Pros/Cons
Pros
- 1stãããDBéçãã¼ã¿ãµã¤ãºãå¤§å¹ UP
- ãªã¼ãã¬ããªã«å°æ°èª¿æ´å¯è½
- èªåFailOver
- ã¤ã³ã¹ã¿ã³ã¹ã¿ã¤ããæ確GCEã¨åãæè¦ã§æå®ã§ãã
Cons
- 1stã«ãã£ããã¼ã¿å¾é課éãç¡ããªã£ã
- IPå¶éãGlobal IPã®ã¿ãªã®ã§ãã¿ã°ã¨ãã§å¶éåºæ¥ãªããå ·ä½çã«GCEã§ãã¨ãã§ã¡ã©ã«IPã使ã£ã¦ããå ´åã¯ãCloud SQL Proxyã¨ããã®ã使ãå¿ è¦ããããhttps://cloud.google.com/sql/docs/sql-proxy
- èªåFailOverããããã¨ã³ããã¤ã³ãæ¸ãæãã¯ãªã
- ãã§ã¤ã«ãªã¼ãã¬ããªã«ã®ã¹ããã¯å¤æ´ãã§ããªã(ããã¥ã¡ã³ãã¯ã§ããã£ã½ããã¨ããã¦ããããã)