表åé.rb #4 ã§çºè¡¨ãããã¨æã£ã¦è³æãä½ã£ããã®ã®åå ã§ããªããªã£ãã®ã§è³æã ãä¸ãã¦ããã¾ãã
ã¹ã©ã¤ãç
ã¹ã©ã¤ãã®ã½ã¼ã¹ã³ã¼ã https://github.com/sue445/omotesandorb-04
以ä¸ã¯ã¹ã©ã¤ãæ¬æã§ããã¹ã©ã¤ããmarkdownã§æ¸ãã¦ããã¨ããã°ã«ããã®ã¾ã¾è²¼ãä»ãããã¦ä¾¿å©
è¬ã®ãã©ãã«ã§capstrano3移è¡ã«å¤±æãã話 #omotesandorb
sue445
2015/09/03 表åé.rb #4
èªå·±ç´¹ä»
- sue445
- æ ªå¼ä¼ç¤¾ããªã³ã æå±
- ãµã¼ããµã¤ãå
¨è¬ã®éç¨
- ã¤ã³ãã©ãã¢ããªãã©ã¤ãã©ãªã社å ãã¼ã«etc
- éç ²çãªã®ã§ãã®ä¼ç¤¾ã§ä¸çªæåã«cap3ã®äººæ±ã«ãªã£ãï¼2013å¹´æ«ãããï¼ï¼
- TDDãããã
- ããªãã¥ã¢ãããã
ãä»æã®å«ããã¥ã¢ãã¥ã¤ã³ã¯ã«
ãæ¬å¦»ããã¥ã¢ãã¼ã¹
Agenda
- ã¾ã¨ã
- åç½®ã
- cap2ã§ã¤ããã£ããã¨
- cap3ã«ç§»è¡ããæã®æé
- æ¬çªãªãªã¼ã¹æã«èµ·ãã£ããã©ãã«
- ããã¾ããå é±èµ·ãã£ãæã話
ã¾ã¨ã
- é å¼µã£ã¦cap2ããcap3ã«ç§»è¡ãããã©æ¬çªã§è¬ã¨ã©ã¼ãåºã¦cap2ã«æ»ãã
åç½®ã
- ã¨ããã¢ããª(iOSã¨Androidã§å ¬éããã¦ããã½ã¼ã·ã£ã«ã²ã¼ã )ã§ã¨ã³ã¸ãã¢ã®äººæ°ã足ããªãã¦ããã£ã¨ã«å ¥ã£ã
- Ruby 2.2.2, Rails 4.0.6
- ãã¹ãã1年以ä¸æ´æ°ããã¦ããªãã£ã
- åããªãç¶æ ãããrspec3ã«ã¢ããã°ã¬ã¼ããã¦åãã¬ãã«ã¾ã§ç´ããï¼500åè¿ããã¹ããpendingï¼
- æ°ããã³ã¼ãã«é¢ãã¦ã¯åããã¹ãã³ã¼ããæ¸ãã¦ãã£ããä»ã®ã¨ã³ã¸ãã¢ããã¹ããæ¸ãããã«ãªã£ãï¼ä»åå¯ä¸ã®ããã¯ãªãï¼
- ãããªã¢ããªã§åã«ä¸ããããæåã®ããã·ã§ã³ãcap2ãã3ã¸ã®ã¢ãããã¼ã
cap2ã§ã¤ããã£ããã¨
- cap2ãããããã¡ã³ãããã¦ãªã
- capistrano-drecom-deploy ã capistrano-drecom-sidekiq(社å gem)ãcap3åæãªã®ã§cap2ã ã¨ç¤¾å gemã®æ©æµãåããããªã
- capistrano-drecom-deploy ã¯nginx, unicorn ç³»ã®Railsã¢ããªã§ãããã便å©taskãæã£ã¦ã
drecom:unicorn:setup
ã§/etc/init.d/unicorn-appname
ãçæãã¦ãµã¼ãã«ã¢ãããã¼ããã
cap3ã«ç§»è¡ããæã®æé
- config/ã«ãã£ãæ¢åã®cap2ã¿ã¹ã¯ãconfig_old/ ã«ç§»å
- Capfileãåé¤ãã¦cap3ã«ã¢ãããã¼ããã¦
cap init
- cap3æ¤è¨¼ç¨ã®ãµã¼ããæ§ç¯
- OpenStackã®æ¢åã®ãµã¼ãã®ã¹ãããã·ã§ãããä½ã£ã¦ã³ãã¼
- capistrano-drecom-deployãé©ç¨ï¼1æ¥ï¼
- ãã®ä»ã®ã¿ã¹ã¯ãcap3ã«å°éã«ç§»è¡ï¼1ã2é±éï¼
æ¢åã®éçºãµã¼ã
- cap deploy
- æ¬çªã¨åããã±ã¼ã·ã§ã³ã«ããéçºãµã¼ãããgit cloneããæã«7GBãããªãã¸ããªã®git cloneã15åã ã£ãã®ã§æ¬çªã¯ãã以ä¸ããããªãã ããã¨äºæ³
- ã¡ã³ãæéãç縮ããããã«äºã1å°ãã¤git cloneãã¦ãããã¨ã«ï¼å¾è¿°ï¼
- ãã®ä»initã¹ã¯ãªããç³»ãcapistrano-drecom-deployã«è¿½å¾
ãå°ãã¿ãcap3ã§äºãcap deployåã«git cloneãã¦ããæ¹æ³
cap deploy
æã«git clone
ãããã®ã§ãæ®éã«ããã¨ãªãã¸ããªãã§ããã¨cloneã«æéãæããã®ã§å¯è½ãªãã¡ã³ãå ¥ããåã«git cloneã ãã¯ãããã£ã- v3.3.4ãããã§åä½ç¢ºèª
æé
Capfileã«ä¸è¨ã追å
require "capistrano/git"
- git cloneã ãããã³ãã³ãã¯capistranoã«åå¨ããã®ã ãåå¥ã«ä½¿ãããã«ã¯
capistrano/git
ãrequire
ãã¦ãããªãã¨ä½¿ããªã
ã³ãã³ã
bundle exec cap xxxx git:update HOSTS=xxx.xxx.xxx.xxx
cap git:clone
ã ã¨git clone
ããã ãã ãã©ãcap git:update
ã ã¨ãªãã¸ããªããªãå ´åã«ã¯git clone
ãã¦ãªãã¸ããªãããå ´åã«ã¯git fetch
ãã¦ãããã®ã§åªçæ§ãããã®ããã- HOSTSãã¤ãããã¨ã§ãã®hostã ãã«capã³ãã³ããå®è¡ã§ããã®ã§webãµã¼ã1å°ãã¤ä½æ¥ãããã¨ãã«ã¯ä½¿ãã
- å®ã¯åæ¹ä¸è´ãªã®ã§
HOSTS=xx.yy.zz.0
ã£ã¦æ¸ãã¨xx.yy.zz.01
ãxx.yy.zz.09
ã«å¯¾ãã¦å®è¡ããã - ä¸æ©ééããã¨ãµã¼ã1å°ãã¤å®è¡ããã¤ããããµã¼ãå ¨å°ã§capå®è¡ã¨ããæããã¨ã«ãªã
- å®ã¯åæ¹ä¸è´ãªã®ã§
å½æã®ã¡ã³ãã¹ã±ã¸ã¥ã¼ã«
- 9:30é ï¼ã¡ã³ãã¤ã³ããåã«1å°ãã¤git clone
- web x 14, admin x 1, job x 2
- 1å°15åã¨ãããã¡ã³ãã¤ã³ã¾ã§ã«ã®ãªã®ãªçµããè¨ç®
- 13:00é ï¼ã¡ã³ãã¤ã³
- 16:00é ï¼ã¡ã³ãã¢ã¦ã
ãæ¬é¡ãæ¬çªãªãªã¼ã¹æã«èµ·ãã£ããã©ãã«
- git cloneãæã£ãããæéãããã£ã
- ä¸å®ç¢ºçã§ã¡ã³ãç»é¢ãã¨ã©ã¼ã«ãªãï¼ãã®1ï¼
- ä¸å®ç¢ºçã§ã¡ã³ãç»é¢ãã¨ã©ã¼ã«ãªãï¼ãã®2ï¼
git cloneãæã£ãããæéãããã£ã
- æ¬çªã¨åä¸ãã±ã¼ã·ã§ã³ã®ã¹ãã¼ã¸ã³ã°ãµã¼ãã§git cloneããæã¯10ã15åãããã ã£ãã®ã«ãæ¬çªã ã¨30åå¼±ããã£ã
- ä¸åº¦ã«2ã3å°ãã¤git cloneãããã¨ãããéã«æéã伸ã³ã¦ãã¾ã£ãï¼3å°åæã§90åãããï¼
- 社å GitLabã®ãã©ãã£ãã¯ãè©°ã¾ã£ãï¼
- 1å°ã ãgit cloneãã¦ããã¦æ®ãã¯rsyncã§ããã£ããããããªããæªæ¤è¨¼ã ã£ãã®ã§å®æ½ãã
- ï¼æåéãï¼ã¶ã£ã¤ãæ¬çªã§å®è¡ããã¨ä½è¨æªåããå¯è½æ§ããã£ããã
- ã¡ã³ãä¸ã«ãã¤ãè¾¼ãã ã®ã§ã¡ã³ãä¸ãgit cloneãã¤ã¤ãcap3åãã¦ãããµã¼ãã®ã¿ã§ãµã¼ãã¹ã¤ã³ãããã¨ç®è«ã
ä¸å®ç¢ºçã§ã¡ã³ãç»é¢ãã¨ã©ã¼ã«ãªãï¼ãã®1ï¼
ã¡ã³ãç»é¢ã®ãªãã¼ããã¿ã³ãæ¼ãã¨2ã3åã«1åã®ç¢ºçã§ã¨ã©ã¼ã«ãªã
åå
- ã13:00ã16:00ã¾ã§ã¡ã³ããã³ã¹ä¸ã§ããã¿ãããªãã¡ã¤ã«ã
/var/www/app/current/public/system/maintenance.json
ã«ç½®ãã¦ããã®ã ããcap3ã§ãããã¤ããæã«ãã®ãã¡ã¤ã«ãå¹ã£é£ãã - LBã«ã¯cap2ã§ã¡ã³ãå
¥ã£ã¦ãããµã¼ãã¨cap3ã§ã¡ã³ãå
¥ã£ã¦ããµã¼ããæ··å¨ãã¦ããã®ã§ã¨ã©ã¼ã«ãªã£ãããªããªãã£ãã±ã¼ã¹ãçºç
- cap3ã§ãããã¤ãããµã¼ãã«ã¢ã¯ã»ã¹ãæ¥ãæã«ã¨ã©ã¼ã«ãªã
- å度ãã¡ã¤ã«ãè¨ç½®ãããã¨ã§ã¨ã©ã¼ã¯è§£æ¶
ä¸å®ç¢ºçã§ã¡ã³ãç»é¢ãã¨ã©ã¼ã«ãªãï¼ãã®2ï¼
ã¡ã³ãç»é¢ã®ãªãã¼ããã¿ã³ãæ¼ãã¨3ã4åã«1åã®ç¢ºçã§ã¨ã©ã¼ã«ãªãï¼ãã£ãããã¡ããé »åº¦ã¯å°ãªããã©ããã§ãçµæ§å¤ãï¼
äºè±¡
- nginxã®ã¨ã©ã¼ãã°ã«ãSSL_do_handshake() failed (SSL: error:140A1175:SSL routines:SSL_BYTES_TO_CIPHER_LIST:inappropriate fallback) while SSL handshakingãã大éã«çºç
- æ®æ®µã§ãã¡ããã¡ããåºã¦ããã ãã©ï¼1æ¥æ°å件ï¼ãã¡ã³ãä¸ã®ãã20åéã ãã§800件çºç
- nginxã®è¨å®ãã¡ã¤ã«ãæ´æ°ãã¦ãããæ¹è¡ã¨ã³ã¡ã³ãã¢ã¦ãã®åé¤ãããããå·®åããªã
- ãã£ã¨èª¿ã¹ã¦ãã¦ãæéããããã ãã ã£ãã®ã§ãcap2ã«åãæ»ãã¦ãªãªã¼ã¹ä½æ¥ãç¶ç¶ãããã¨ã«
- cap3ã«ãããµã¼ãã¯LBããåãé¢ãã¦cap2ã®ã¾ã¾ã®ãµã¼ãããµã¼ãã¹ã§ä½¿ã
- ã½ã¼ã¹ã³ã¼ãä¸ã¯cap3ãªã®ã§ã¡ã³ãä¸ã«cap2ã«æ»ãã
- config_old/ ã config/ ã«ä¸æ¸ãããã ããªã®ã§åãæ»ãä½æ¥ã¯20åããã
ã¡ã³ãç¿æ¥ã®èª¿æ»
/etc/hosts
ãæ¸ãæãã¦LBãéããã«ãµã¼ãã¹ã¢ã¦ããã¦ãæ¬çªã®webãµã¼ãã«ç´æ¥ãªã¯ã¨ã¹ãæãããã©SSL_do_handshakeã®ã¨ã©ã¼ã¯ä¸åçºçããªãã£ã- webãµã¼ããåå ã§ãªããã¨ãåãã£ãã®ã§ã¤ã³ãã©ã«LBã®ãã°ã調ã¹ã¦ããã£ã
åå
- ãã¾ãã¾å¤ãæ©ç¨®ã§æ¥ç¶ãå¤ãã£ãï¼ï¼ã¨ããæããªãã¨ã®ã¤ã³ãã©åçï¼
- cap3ã¨å ¨ç¶é¢ä¿ãªãã£ãï¼ã¤ããï¼
çµæ
20æé ã¡ã³ãéãï¼4æé延é·ï¼
ããã¾ããå é±èµ·ãã£ãæã話
æ¬çªã§çªç¶ã®å¤§éã¨ã©ã¼ãåºã¦ã²ã¼ã ã«ãã°ã¤ã³ã§ããªãã®ã§ç·æ¥ã¡ã³ãå ¥ãã
åå ã®ã³ã¼ã
Rails.cache.fetch(key_name, expires_in: 1.day) do SomeModel.find_by(key: key_name) end
- cacheã«ããã°ãããè¿ãã¦ããªããã°ãããã¯å ãè©ä¾¡ãã¤ã¤çµæãcacheã«ä¿åãã
- ãã®çµæãç¹å®ã®keyã®ã¿
nil
ã«ãªã£ã¦ã¦å¼ã³åºãå ã§NoMethodError
ã«ãªã£ã¦ã模æ§
調æ»
- DBã«ã¯ã¬ã³ã¼ããã£ã
- cacheã®ã¨ã©ã¼ãã°ã«ãç¹ã«ä½ããªãã£ã
- ãããã調æ»ãã¦ããã¡ã«10åãããã§ã¨ã©ã¼ã¯è§£æ¶ãã¦ãã°ã¤ã³åºæ¥ãããã«ãªã£ã
- ãã¾ã ã«åå ä¸æï¼æãï¼
ã¾ã¨ã
- ã§ãããªãã¸ããªãcap3移è¡ããå ´åã«ã¯å ¨ãµã¼ãã§git cloneãããããã1å°ã ãgit cloneãã¦ããä»ãµã¼ãã«ã¯rsyncããæ¹ããã¶ãæ©ã
- ãªãããã£ãæã®ããã«åãæ»ãæé ãç¨æãã¹ã