Your SlideShare is downloading. ×
0
Inside Sqale’s Backend   Sapporo Ruby Kaigi 2012      Gosuke Miyashita      paperboy&co. Inc.
A little bit about me
Technical Manager        at  paperboy&co.
https://github.com/mizzy    http://mizzy.org/      @gosukenator
Inside Sqale’s Backend
http://www.facebook.com/sqalejp
WARNINGThere are little topicsabout Ruby in this talk
What is Sqale?
Cloud ApplicationPlatform like Heroku
Architecture Overview
SFTP       Git over SSH         HTTP/HTTPSAWS    SSH                             Web Proxy      SSH Router                ...
Containers
SFTP       Git over SSH         HTTP/HTTPSAWS    SSH                             Web Proxy      SSH Router                ...
Virtual Environments  Assigned To Users
Similar to Dynos of      Heroku
Containers made byLXC (Linux Containers)
EC2 Instance (1 Virtual Machine)Container   Container   Container   Container   Container   for         for         for   ...
Nginx     Unicorn      sshd   supervisrodon each container
Amazon Linux          +Patched kernel(3.2.16)
grsecurity kernel patchfor various restrictions
original kernel patches  to restrict tcp port bind and fork bomb
Anti fork bomb patchmakes some changes tocgroup and fork process
Seepaperboy-sqale/sqale-patches         on GitHub
Web Proxy
SFTP       Git over SSH         HTTP/HTTPSAWS    SSH                             Web Proxy      SSH Router                ...
HTTP/HTTPS                               ELB                nginx                           nginxContainer   Container   C...
nginx  lua-nginx-moduleredis2-nginx-module
http://lokka-mizzy.sqale.jp/                        Which containers?           Redis                                     ...
nginx.conf (excerpt)location / {    set $container "";    set $next_containers "";    error_page 502 = @failover;    rewri...
dynamic-proxy.lua (excerpt)local reply = ngx.location.capture("/redis")if reply.status ~= ngx.HTTP_OK then  ngx.exit(503)e...
dynamic-proxy.lua (excerpt)while #containers > 0 do  tmp = table.remove(    containers,    math.random(#containers))  if n...
dynamic-proxy.lua (excerpt)ngx.var.container = containerngx.var.next_containers  = luabins.save(containers)
nginx.conf (again)location / {    set $container "";    set $next_containers "";    error_page 502 = @failover;    rewrite...
nginx.conf (excerpt)location @failover {    error_page 502 = @failover;    rewrite_by_lua_file failover.lua;    proxy_pass...
failover.lua (excerpt)local downed_container = ngx.var.containerif downed_container then  ngx.shared.downed_containers:set...
failover.lua (excerpt)while #containers > 0 do  tmp = table.remove(    containers,    math.random(#containers))  if ngx.sh...
failover.lua (excerpt)if not container then  ngx.exit(503)endngx.var.container = containerngx.var.next_containers  = luabi...
nginx.conf (agin)location @failover {    error_page 502 = @failover;    rewrite_by_lua_file failover.lua;    proxy_pass ht...
Seehttp://bit.ly/UHbHIb    by @hiboma
SSH Router
SFTP       Git over SSH         HTTP/HTTPSAWS    SSH                             Web Proxy      SSH Router                ...
Git           SFTP            SSH Login               SSH Router    File            FileRepositories   Repositories       ...
How implement this     routing?
OpenSSH with scriptauthentication patch
Seemizzy/openssh-script-auth       on GitHub
Change routes bySSH_ORIGNAL_COMMAND
In case ofSSH_ORIGINAL_COMMAND        is “git-*”
git push        (ssh sqale@gateway.sqale.jp git-recieve-pack        ‘/mizzy/lokka.git’)                Run AuthorizedKeys ...
In case ofSSH_ORIGINAL_COMMAND     is “sftp-server”
sftp sqale@gateway.sqale.jp        (ssh sqale@gateway.sqale.jp sftp-server)                Run AuthorizedKeys             ...
In case ofSSH_ORIGINAL_COMMAND        is empty
ssh sqale@gateway.sqale.jp             Run AuthorizedKeys             ScriptSSH Router                                 MyS...
Deploy Servers
SFTP       Git over SSH         HTTP/HTTPSAWS    SSH                             Web Proxy      SSH Router                ...
Please ask to  @kyanny
Other
About Sqale’s Server Build Automationhttp://bit.ly/NBbj9F by @lamanotrama
Thanks
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Inside Sqale's Backend at Sapporo Ruby Kaigi 2012
Upcoming SlideShare
Loading in...5
×

Inside Sqale's Backend at Sapporo Ruby Kaigi 2012

9,354

Published on

Published in: Technology

Transcript of "Inside Sqale's Backend at Sapporo Ruby Kaigi 2012"

  1. 1. Inside Sqale’s Backend Sapporo Ruby Kaigi 2012 Gosuke Miyashita paperboy&co. Inc.
  2. 2. A little bit about me
  3. 3. Technical Manager at paperboy&co.
  4. 4. https://github.com/mizzy http://mizzy.org/ @gosukenator
  5. 5. Inside Sqale’s Backend
  6. 6. http://www.facebook.com/sqalejp
  7. 7. WARNINGThere are little topicsabout Ruby in this talk
  8. 8. What is Sqale?
  9. 9. Cloud ApplicationPlatform like Heroku
  10. 10. Architecture Overview
  11. 11. SFTP Git over SSH HTTP/HTTPSAWS SSH Web Proxy SSH Router to Containers File Deploy Containers Repositories Servers
  12. 12. Containers
  13. 13. SFTP Git over SSH HTTP/HTTPSAWS SSH Web Proxy SSH Router to Containers File Deploy Containers Repositories Servers
  14. 14. Virtual Environments Assigned To Users
  15. 15. Similar to Dynos of Heroku
  16. 16. Containers made byLXC (Linux Containers)
  17. 17. EC2 Instance (1 Virtual Machine)Container Container Container Container Container for for for for for user A user A user B user B user BContainer Container Container Container Container for for for for for user C user D user D user E user EContainer Container Container Container Container for for for for for user E user F user F user F user F
  18. 18. Nginx Unicorn sshd supervisrodon each container
  19. 19. Amazon Linux +Patched kernel(3.2.16)
  20. 20. grsecurity kernel patchfor various restrictions
  21. 21. original kernel patches to restrict tcp port bind and fork bomb
  22. 22. Anti fork bomb patchmakes some changes tocgroup and fork process
  23. 23. Seepaperboy-sqale/sqale-patches on GitHub
  24. 24. Web Proxy
  25. 25. SFTP Git over SSH HTTP/HTTPSAWS SSH Web Proxy SSH Router to Containers File Deploy Containers Repositories Servers
  26. 26. HTTP/HTTPS ELB nginx nginxContainer Container Container Container Container Container for for for for for for user A user B user B user C user C user C
  27. 27. nginx lua-nginx-moduleredis2-nginx-module
  28. 28. http://lokka-mizzy.sqale.jp/ Which containers? Redis nginx host001:8083, host001:8084 orhost001 nginx port 8081 nginx port 8082 nginx port 8083 nginx port 8084 Container Container Container Container for for for for i4pc-mizzy i4pc-mizzy lokka-mizzy lokka-mizzy
  29. 29. nginx.conf (excerpt)location / { set $container ""; set $next_containers ""; error_page 502 = @failover; rewrite_by_lua_file dynamic-proxy.lua; proxy_pass http://$container;}
  30. 30. dynamic-proxy.lua (excerpt)local reply = ngx.location.capture("/redis")if reply.status ~= ngx.HTTP_OK then ngx.exit(503)endlocal containers, type = parser.parse_reply(reply.body)
  31. 31. dynamic-proxy.lua (excerpt)while #containers > 0 do tmp = table.remove( containers, math.random(#containers)) if ngx.shared.downed_containers:get(tmp) then ngx.log(ngx.DEBUG, tmp .. " is down") else container = tmp break endend
  32. 32. dynamic-proxy.lua (excerpt)ngx.var.container = containerngx.var.next_containers = luabins.save(containers)
  33. 33. nginx.conf (again)location / { set $container ""; set $next_containers ""; error_page 502 = @failover; rewrite_by_lua_file dynamic-proxy.lua; proxy_pass http://$container;}
  34. 34. nginx.conf (excerpt)location @failover { error_page 502 = @failover; rewrite_by_lua_file failover.lua; proxy_pass http://$container;}
  35. 35. failover.lua (excerpt)local downed_container = ngx.var.containerif downed_container then ngx.shared.downed_containers:set( downed_container, 1, sqale.NEGATIVE_CACHE_SECONDS )end
  36. 36. failover.lua (excerpt)while #containers > 0 do tmp = table.remove( containers, math.random(#containers)) if ngx.shared.downed_containers:get(tmp) then ngx.log(ngx.DEBUG, tmp .. " is down") else container = tmp break endend
  37. 37. failover.lua (excerpt)if not container then ngx.exit(503)endngx.var.container = containerngx.var.next_containers = luabins.save(containers)
  38. 38. nginx.conf (agin)location @failover { error_page 502 = @failover; rewrite_by_lua_file failover.lua; proxy_pass http://$container;}
  39. 39. Seehttp://bit.ly/UHbHIb by @hiboma
  40. 40. SSH Router
  41. 41. SFTP Git over SSH HTTP/HTTPSAWS SSH Web Proxy SSH Router to Containers File Deploy Containers Repositories Servers
  42. 42. Git SFTP SSH Login SSH Router File FileRepositories Repositories Containers(Git Server) (File Server)
  43. 43. How implement this routing?
  44. 44. OpenSSH with scriptauthentication patch
  45. 45. Seemizzy/openssh-script-auth on GitHub
  46. 46. Change routes bySSH_ORIGNAL_COMMAND
  47. 47. In case ofSSH_ORIGINAL_COMMAND is “git-*”
  48. 48. git push (ssh sqale@gateway.sqale.jp git-recieve-pack ‘/mizzy/lokka.git’) Run AuthorizedKeys ScriptSSH Router MySQL Verify the public key and get the user’s git server command=“ssh sqale@git001.sqale.lan git-recieve-pack File ‘/var/repos/mizzy/lokka.git’”Repository(Git Server)
  49. 49. In case ofSSH_ORIGINAL_COMMAND is “sftp-server”
  50. 50. sftp sqale@gateway.sqale.jp (ssh sqale@gateway.sqale.jp sftp-server) Run AuthorizedKeys ScriptSSH Router MySQL Verify the public key and get the user’s file server command=“ssh sqale@file001.sqale.lan sftp-server” File git push File Repository Repository(File Server) (Git Server)
  51. 51. In case ofSSH_ORIGINAL_COMMAND is empty
  52. 52. ssh sqale@gateway.sqale.jp Run AuthorizedKeys ScriptSSH Router MySQL Verify the public key and get the user’s cotainers list Display the user’s containers list and wait the user’s selection command=“ssh sqale@Container users001.sqale.lan -p 8081”
  53. 53. Deploy Servers
  54. 54. SFTP Git over SSH HTTP/HTTPSAWS SSH Web Proxy SSH Router to Containers File Deploy Containers Repositories Servers
  55. 55. Please ask to @kyanny
  56. 56. Other
  57. 57. About Sqale’s Server Build Automationhttp://bit.ly/NBbj9F by @lamanotrama
  58. 58. Thanks
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×