ããã«ã¡ã¯ããµã¼ãã¼ã¯ã¼ã¯ã¹ æè¡1課ã®ä¸äºã§ãã ãåç¥ã®æ¹ãå¤ãã¨ã¯æãã¾ãããRDSã«ã¯ã¹ãããã·ã§ãããç°ãªããªã¼ã¸ã§ã³ã«ã³ãã¼ããæ©è½ãããã¾ãã
äºãã¹ãããã·ã§ãããå¥ãªã¼ã¸ã§ã³ã«ã³ãã¼ãã¦ããã¦ããã©ã¤ããªãªã¼ã¸ã§ã³ãå©ç¨ä¸å¯è½ã«ãªããããªé害ãèµ·ãã£ãå ´åã«ãã³ãã¼å
ãªã¼ã¸ã§ã³ã§ã¹ãããã·ã§ããããRDSããªã¹ãã¢ãããã¨ãã£ããã£ã¶ã¹ã¿ãªã«ããªç¨éã§ã®æ´»ç¨ãæå¾
ããã¦ãã¾ãã ãã¦ãã³ãã¼å
ãªã¼ã¸ã§ã³ã§RDSã¹ãããã·ã§ããããªã¹ãã¢ããããã«ã¯äºåã«ããã¤ãæºåãå¿
è¦ã«ãªãã¾ããæä½éå¿
è¦ãªã¨ããã ã¨ã
- ã»ãã¥ãªãã£ã°ã«ã¼ãã®ä½æ
- DBãµããããã»ãµããããã°ã«ã¼ãã®ä½æ
- DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ä½æ
- DBãªãã·ã§ã³ã°ã«ã¼ãã®ä½æ
ã¨ãã£ãã¨ããã§ããããããããã¯ä½æãããªã¼ã¸ã§ã³ã«åºæã®ãã®ã§ãã®ã§ããªã¹ãã¢åã«å½¢ã ãã§ãä½ã£ã¦ããå¿ è¦ãããã¾ãã
DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã¯ãªã¼ã¸ã§ã³éã³ãã¼ã§ãã¾ãããã§ãã³ãã¼ããã
ããã³ãã¼å ãªã¼ã¸ã§ã³ã§ã¹ãããã·ã§ãããããªã¹ãã¢ãããã¨ããã¨ãã«ãã©ã¡ã¼ã¿ã®å·®ç°ãããã®ã¯å ·åãæªãã§ããã¢ããªã±ã¼ã·ã§ã³ãæ³å®å¤ã®æåãããããªãã§ãããããã©ã¼ãã³ã¹ã®åé¡ã«ãç´çµãã¾ãããªã®ã§åºæ¬çã«ãDBãã©ã¡ã¼ã¿ã°ã«ã¼ãã¯ã³ãã¼å ãªã¼ã¸ã§ã³ã¨ã³ãã¼å ãªã¼ã¸ã§ã³ã¨ã§åãã«ãªãããè¨å®ãã¦ããå¿ è¦ãããã¾ããã¨ã¯ããè¨å®é ç®æ°ãå¤ãã®ã§ãæã§è¨å®ããã®ã¯ããã©ãã§ãã ã¨ããããã§ãDBãã©ã¡ã¼ã¿ã°ã«ã¼ãããªã¼ã¸ã§ã³éã³ãã¼ããããããã¨ããã®ãä»åã®ãã£ããããç®çã§ãã æ¬æ¥æç¹ã§ã¯ã¾ã ãæ¨æºæ©è½ã¨ãã¦ãDBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ã³ãã¼ãã¨ããæ©è½ã¯å®è£ ããã¦ãã¾ããããããã©ãã«ããã¦å®ç¾ããæ¹æ³ãèãã¾ãã
ã©ãããã
ç®diff
è·äººã磨ããããåãé§ä½¿ããçç·´ã®ç®ã¤ãã§RDS Management Consoleã®ç»é¢ã¨ç¨ãã£ãããããã©ãã£ã·ã§ãã«ãªã¢ããã¼ãã§ãããæã§è¨å®ããã®ã¯ããã©ãã§ããã£ã¦è¨ã£ã¦ããã¦ãããããã£ã¦ããã
MySQL5.6ã®å ´åãManagement Consoleä¸ã§ç·¨éã§ãããã©ã¡ã¼ã¿ã¯288åã
1é ç®ã®æ¯è¼ãåãã®ã«5ç§ãããã¨ä»®å®ããã¨ã288 x 5 = 1440ãå®ã«24åãããããã¨ã«ãªãã¾ããããã©ãã§ãã
è·äººã®ç¥çµããããªãã«ããæ¸ãã¾ããããã©ã¡ã¼ã¿ã°ã«ã¼ããå¤æ´ãããã³ã«ãã®ä¸æ¯æ¥µã¾ããªãä½æ¥ãçºçããã®ãã¨æãã¨æ°ãé ãªã£ã¦ããã®ã§ãã®ã¸ãã§èããã®ãããã¦ããã¾ãã
AWS CLIã使ã
çµå±ãããæ¸ãããã£ãã ããªãã§ããã©ããAWS CLIã§ãµã©ãã¨ããã¾ãããããã¨ã¯ã·ã³ãã«ã§ã
1. ã³ãã¼å
DBãã©ã¡ã¼ã¿ã°ã«ã¼ãããã¦ã¼ã¶å®ç¾©ãã©ã¡ã¼ã¿ãåºå
2. åºåãããã¼ã¿ãå
ã«ãã³ãã¼å
DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®è¨å®å¤æ´
ã¨ãããã ãã§ãã以åå¼ç¤¾ããã°ã§ãç´¹ä»ããAWS CLIã®ãªãã·ã§ã³ããã«æ´»ç¨ãã¦å®ç¾ãã¦ã¿ã¾ãã
AWS CLIã§DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ã³ãã¼ï¼ã£ã½ããã¨ï¼ããã
ä»åã®æ¤è¨¼ç¨ã«ãorig-param ã¨ããMySQL5.6ç¨ã®DBãã©ã¡ã¼ã¿ã°ã«ã¼ããä½æãã¦ããã£ããã¨ä»¥ä¸ã®ãããªè¨å®å¤æ´ãè¡ãã¾ããã
character_set_server = utf8 collation_server = utf8_general_ci general_log = TRUE(1) slow_query_log = TRUE(1) long_query_time= 30
試ãã«1ã¤ãã©ã¡ã¼ã¿åã£ã¦ã¿ã¾ãã
aws rds describe-db-parameters --profile mydev --db-parameter-group-name orig-param --query "Parameters[?ParameterName==`character_set_server`]"
ã¬ã¹ãã³ã¹ã¯ä»¥ä¸ã®éãã
[ { "Description": "The server's default character set.", "DataType": "string", "IsModifiable": true, "AllowedValues": "big5,dec8,cp850,hp8,koi8r,latin1,latin2,swe7,ascii,ujis,sjis,hebrew,tis620,euckr,koi8u,gb2312,greek,cp1250,gbk,latin5,armscii8,utf8,ucs2,cp866,keybcs2,macce,macroman,cp852,latin7,utf8mb4,cp1251,utf16,cp1256,cp1257,utf32,binary,geostd8,cp932,eucjpms", "Source": "user", "ParameterValue": "utf8", "ParameterName": "character_set_server", "ApplyType": "dynamic" } ]
ãã®JSONæ§é ããµãã£ã¨è¦ãã¦ããã¾ãã DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ä¿®æ£ã¯ modify-db-parameter-group ãµãã³ãã³ãã§è¡ãã¾ãã
--cli-input-json ã使ã£ã¦ä¸æ°ã«JSONãæµãè¾¼ããããªæ°ãããã®ã§ãã¾ãã¯æ§é ã確èªãã¹ã --generate-cli-skelton ãã¾ãã
aws rds modify-db-parameter-group --generate-cli-skeleton
以ä¸ã®ã¹ã±ã«ãã³ãæ¨æºåºåã«æ¸ãåºããã¾ãã
{ "DBParameterGroupName": "", "Parameters": [ { "ParameterName": "", "ParameterValue": "", "Description": "", "Source": "", "ApplyType": "", "DataType": "", "AllowedValues": "", "IsModifiable": true, "MinimumEngineVersion": "", "ApplyMethod": "" } ] }
è¦æ¯ã¹ã¦ã¿ãã¨ãParameters é
åã®ä¸ã®ãªãã¸ã§ã¯ãã¯ã»ã¼åãã§ããã
describe-db-parameters ãåºåããJSONãã»ã¨ãã©å å·¥ããã«é£ããããããã§ãã å·®å㯠MinimumEngineVersion, ApplyMethodã
ApplyMethod ã¯ãå¤æ´ãããã«RDSã¤ã³ã¹ã¿ã³ã¹ã«é©ç¨ããã (immediate)ãåèµ·åå¾ã¾ã§å¾
ã¤ã (pending-reboot)ããæå®ããé
ç®ã§ããã©ã¡ã¼ã¿ã°ã«ã¼ãã®è¨å®å¤æ´æã«ã¯æå®å¿
é ã®é
ç®ã§ããæ¬æ¥ãªãé¢é£ä»ãããã¦ããRDSã¤ã³ã¹ã¿ã³ã¹ã¸ã®å½±é¿ãèæ
®ãã¦æ
éã«è¨å®ãã¾ãããä»åã¯ãã¨ããããDBãã©ã¡ã¼ã¿ã°ã«ã¼ããã³ãã¼ãããã¨ããç¨éããèãã¦ããªãã®ã§ãRDSã¤ã³ã¹ã¿ã³ã¹ã«èæ
®ããå³æé©ç¨ (immediate) ã¨ãããã¨ã«ãã¾ãã
ã³ãã¼å DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®æ å ±ãåºå
ã¨ããããã§ãã¾ãã¯å
ã®DBãã©ã¡ã¼ã¿ã°ã«ã¼ããé©å½ãªãã¡ã¤ã«ã«åºåãã¾ãã
å
¨é¨ã®ãã©ã¡ã¼ã¿ãæ¸ãåºãã¨çµæ§ãªããªã¥ã¼ã ã«ãªã£ã¦ç¡é§ãå¤ãã®ã§ã--source user ã¨æå®ãã¦ãã¦ã¼ã¶ãæ示çã«å¤æ´ãããã©ã¡ã¼ã¿ãã ããåºåããããã«çµã£ãä¸ã§ãå®è¡çµæã mysqlparams.json ã¨ãããã¡ã¤ã«ã«æ¸ãåºãã¦ãã¾ãã
aws rds describe-db-parameters --profile mydev --db-parameter-group-name orig-param --source user > mysqlparams.json
å ã»ã©ç¢ºèªãã¾ããããæ¹ãã¦ãã¡ãã¨ä¸èº«ãè¦ã¦å ¨ä½ã®æ§é ã確èªãã¾ãã
{ "Parameters": [ { "Description": "The server's default character set.", "DataType": "string", "IsModifiable": true, "AllowedValues": "big5,dec8,cp850,hp8,koi8r,latin1,latin2,swe7,ascii,ujis,sjis,hebrew,tis620,euckr,koi8u,gb2312,greek,cp1250,gbk,latin5,armscii8,utf8,ucs2,cp866,keybcs2,macce,macroman,cp852,latin7,utf8mb4,cp1251,utf16,cp1256,cp1257,utf32,binary,geostd8,cp932,eucjpms", "Source": "user", "ParameterValue": "utf8", "ParameterName": "character_set_server", "ApplyType": "dynamic" }, ï¼ä»¥ä¸ç¥ï¼
å è¿°ã®å¿ é ãã©ã¡ã¼ã¿ãApplyMethod ã¯åå¨ããªãã®ã§ãããã¯ã²ã¨ã¾ãjqã§ã´ãã§ã´ãã§ãã¦æ¸ã足ãã¦ããã¾ãã
cat mysqlparams.json | jq '{Parameters:[ (.Parameters[] * {"ApplyMethod":"immediate"})]}' | cat > mysqlparams.json
ä¸å¿ç¢ºèªãã¨ãã¾ããã
{ "Parameters": [ { "Description": "The server's default character set.", "DataType": "string", "IsModifiable": true, "AllowedValues": "big5,dec8,cp850,hp8,koi8r,latin1,latin2,swe7,ascii,ujis,sjis,hebrew,tis620,euckr,koi8u,gb2312,greek,cp1250,gbk,latin5,armscii8,utf8,ucs2,cp866,keybcs2,macce,macroman,cp852,latin7,utf8mb4,cp1251,utf16,cp1256,cp1257,utf32,binary,geostd8,cp932,eucjpms", "Source": "user", "ParameterValue": "utf8", "ParameterName": "character_set_server", "ApplyType": "dynamic", "ApplyMethod": "immediate" }, ï¼ä»¥ä¸ç¥ï¼
"ApplyMethod"ã追è¨ããã¦ããã°OKã
ã³ãã¼å ã®å¨ã¨ãªãDBãã©ã¡ã¼ã¿ã°ã«ã¼ããä½ã
ååã®ã¿ãã³ãã¼å ã®DBãã©ã¡ã¼ã¿ã°ã«ã¼ããä½æãã¾ãããã§ã«ã³ãã¼å ã¨ãªãDBãã©ã¡ã¼ã¿ã°ã«ã¼ããåå¨ããå ´åã«ã¯ä¸è¦ã
aws rds create-db-parameter-group --profile mydev --db-parameter-group-family MySQL5.6 --db-parameter-group-name dest-param --description "This is destination parameter group" --region us-east-1
ä»å使ã£ã¦ããprofile mydevã¯ããã©ã«ããªã¼ã¸ã§ã³ã ap-northeast-1 ãªã®ã§ãã³ãã¼å
㯠us-east-1 ãæ示çã«æå®ãã¦ãdest-param ã¨ããDBãã©ã¡ã¼ã¿ã°ã«ã¼ããä½æãã¾ããã
DBãã©ã¡ã¼ã¿ã°ã«ã¼ãéã§ãã©ã¡ã¼ã¿ã³ãã¼ããã ããªã®ã§ãå¥ã«ãªã¼ã¸ã§ã³å¤ããå¿
è¦ã¯ãªããã§ãããã©ãããªããæ±äº¬ããã´ã¡ã¼ã¸ãã¢ã«ã³ãã¼ããã£ãã§ï¼ãã®æ¹ãçãä¸ããããããããåé ã§ãªã¼ã¸ã§ã³éã³ãã¼ãããããã£ã¦æ¸ãã¡ãã£ãããå¼ãä¸ãããªãæãã§ããããã ãã®çç±ã§ãã
ãã©ã¡ã¼ã¿è¨å®ã®æå ¥
--cli-input-json ã®å¼æ°ã«å ã»ã©æ¸ãåºããJSONãã¡ã¤ã«ãæå®ããmodify-db-parameter-group ãå®è¡ãã¾ãã
aws rds modify-db-parameter-group --profile mydev --region us-east-1 --db-parameter-group-name dest-param --cli-input-json file://mysqlparams.json
æ£å¸¸ã«ãªã¯ã¨ã¹ããå®äºããã¨DBãã©ã¡ã¼ã¿ã°ã«ã¼ãåãè¿ã£ã¦ãã¾ãã
{ "DBParameterGroupName": "dest-param" }
念ã®ãããã³ãã¼å ã§ãã orig-param ã¨ãus-east-1 ã«ã³ãã¼ãã dest-param ã®å 容ãåä¸ãã©ãããdiffã³ãã³ãã§ç¢ºèªãã¦ã¿ã¾ããæ¯åº¦ããå¿ è¦ã¯ãªãã§ãããä¸å®ãªäººã®ããã«ã
diff -s <(aws rds describe-db-parameters --profile mydev --db-parameter-group-name orig-param) <(aws rds describe-db-parameters --profile mydev --region us-east-1 --db-parameter-group-name dest-param)
以ä¸ã®ããã«identicalã¨è¡¨ç¤ºããã¦ããã°OKã
Files /dev/fd/11 and /dev/fd/12 are identical
ãããã«
ã¡ãã£ã¨ç¡çç¢çã§ã¯ããã¾ãããDBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ãªã¼ã¸ã§ã³éã³ãã¼ãã§ãã¾ããã DBãã©ã¡ã¼ã¿ã°ã«ã¼ãã®ã³ãã¼ã ãã«éãããããããã¨æã£ããã¨ãAWSå´ã®æ¨æºAPIã¨ãã¦æä¾ããã¦ããªãã±ã¼ã¹ãã¾ã ããã¾ããããã²ã¨å·¥å¤«ãã¦æ¢åã®APIããã¾ããã¨ä½¿ãã°å¤§æµã®ãã¨ã¯åºæ¥ãããªæ°ããã¦ãã¾ãã AWSå´ã§ãæ¥ã ã¨ã³ãã³ã¹ã¡ã³ããè¡ããã¦ãã¾ãããããã§ã足ããªãã¨ããã¯ã¦ã¼ã¶ã®å·¥å¤«æ¬¡ç¬¬ã§ãããã§ãè£ãããããã¯AWSã®å¤§ããªé åã®ã²ã¨ã¤ããªã¨æã£ã¦ãã¾ãã