WebSocket(node + socket.io)ãstunnel + HAProxyã§ãããã·ãã - ãã®ï¼ - HAProxyã®ã¤ã³ã¹ãã¼ã«ã¾ã§
WebSocketã®ã¹ãã¼ã¿ã¹ã¯ãæ¨å¹´12æã«RFC6455ã¨ãã¦proposed standardï¼æ¨æºåã¸ã®æå±ï¼ã®ã¹ãã¼ã¿ã¹ã«ãªãã¾ããã
node.js+socket.ioãjetty(Java)ãå§ããµã¼ãã¼ãµã¤ãã®å®è£
ã¯æ¢ã«å¤ããããã¯ã©ã¤ã¢ã³ãã¯Google Chromeã¨Safariãå®è£
ãã¦ãã¾ãã
FireFoxãªã©ã¯MozWebSocketã¨ãã¦å®è£
ããã¦ããããªãªã¼ã¹ã¯æ¨æºåãå¾
ã£ã¦ããç¶æ
ã§ãã
2æã«ãªãªã¼ã¹ãããFireFox 11ãããproposed standardã¸ã®ç§»è¡ãåãã¦WebSocketãæ£å¼ã«ãªãªã¼ã¹ãã¾ããã
https://dev.mozilla.jp/2012/02/firefox11/
ä¾ãã°ããµã¼ãã¼ã«node.jsãå©ç¨ããã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ãã¦ããå ´åãå®éã«ã¯node.jsèªä½ãã¹ã±ã¼ã«ããããWebSocket以å¤ã®æ©è½ã¯node.js以å¤ã§å®è£
ãããå ´åãããã¾ãã
ãã®å ´åã¯ããªãã¼ã¹ãããã·ãµã¼ãã¼ãå¿
è¦ã¨ãªãã¾ãããç¾å¨ããã£ã¨ãæåãªã®ã¯HAProxyã§ã*1 *2ã
ããããæ°åã«åãã§ã以ä¸ã®å³ã®ããã«ãnode.jsã¨nginxé ä¸ã«ããWebã¢ããªã±ã¼ã·ã§ã³ãHAProxyã§ã¾ã¨ãããµã¼ãã¼æ§æã®ã·ã¹ãã ãæ§ç¯ããæé ã«ã¤ãã¦ã¾ã¨ãã¦è¡ãã¾ãã
ãªãããã®å 容ã¯ä»¥ä¸ã®ããã°ãåèã«å®éã«ãco-meetingã§å®è£ ããå 容*3ãã¾ã¨ãç´ããç©ã«ãªãã¾ãã
Proxy socket.io and nginx on the same port, over SSL
Nginx, Websockets, SSL and Socket.IO deployment
ã¾ãã¯ãHAProxyã®ã¤ã³ã¹ãã¼ã«ãã
HAProxyã®ã¤ã³ã¹ãã¼ã«
HAProxyã¯ãOSã¨ãã¼ã¸ã§ã³ã®çµã¿åããã«ãã£ã¦WebSocketãéã£ããéããªãã£ãããã¾ãã
CentOS5.5ã¯ãyumã§ã¤ã³ã¹ãã¼ã«ããã1.3ç³»ã§ãWebSocketãåãã¾ãã
Ubuntu10.04ã¯1.3.22ãå
¥ãã¾ããããã¡ãã¯WebSocketãåããªãã®ã§1.4ç³»ãã¤ã³ã¹ãã¼ã«ããå¿
è¦ãããã¾ãã
Ubuntu 10.04(ã½ã¼ã¹ããã¤ã³ã¹ãã¼ã«)
$ sudo apt-get update $ sudo apt-get install gcc
$ wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.20.tar.gz $ tar xvfz haproxy-1.4.20.tar.gz $ cd haproxy-1.4.20 $ make TARGET=linux26 $ sudo make install install -d /usr/local/sbin install haproxy /usr/local/sbin install -d /usr/local/share/man/man1 install -m 644 doc/haproxy.1 /usr/local/share/man/man1 install -d /usr/local/doc/haproxy for x in configuration architecture haproxy-en haproxy-fr; do \ install -m 644 doc/$x.txt /usr/local/doc/haproxy ; \
ãã¼ã¢ã³ã¨ãã¦ç»é²
$ sudo vi /etc/init.d/haproxy
以ä¸ã®èµ·åã¹ã¯ãªãããã³ãã¼ãã¦ä¿åãã¦ãã ããã
https://gist.github.com/2224288
$ sudo chmod +x /etc/init.d/haproxy $ sudo apt-get install sysv-rc-conf # sysv-rc-confãå ¥ã£ã¦ãªãå ´å $ sudo sysv-rc-conf
èµ·åãã¹ãç¨ã®è¨å®ãã¡ã¤ã«ãä½æ
$ sudo mkdir /etc/haproxy $ sudo cp examples/haproxy.cfg /etc/haproxy/ $ sudo vi /etc/haproxy/haproxy.cfg
haproxy.cfgãããã¤ãä¿®æ£
chroot /usr/share/haproxy
#chroot /usr/share/haproxy
redispatch
option redispatch
$ sudo mkdir /etc/haproxy/errors $ sudo cp examples/errorfiles/* /etc/haproxy/errors/ $ sudo service haproxy start * Starting haproxy haproxy [ OK ]
Ubuntu 10.04(ææããã¼ã¸ã§ã³)
apt-getã§å ã«1.3.xãã¤ã³ã¹ãã¼ã«å¾ã1.4.20ãã¤ã³ã¹ãã¼ã«å¾ãèµ·åã¹ã¯ãªãããè¥å¹²ä¿®æ£ãã¦1.4.20ãå©ç¨ãã¾ãã
$ sudo apt-get install haproxy
$ sudo vi /etc/default/haproxy
#ENABLED=0 ENABLED=1
èµ·å
$ sudo /etc/init.d/haproxy start
1.4.20(2012/03/28æç¹ã§ã®ææ°)ã§ä¸æ¸ã
$ sudo apt-get update $ sudo apt-get install gcc
$ wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.20.tar.gz $ tar xvfz haproxy-1.4.20.tar.gz $ cd haproxy-1.4.20 $ make TARGET=linux26 $ sudo make install
$ haproxy -version HA-Proxy version 1.4.20 2012/03/10 Copyright 2000-2012 Willy Tarreau
apt-getã§ã¤ã³ã¹ãã¼ã«ããå ´åã«ä½æãããèµ·åã¹ã¯ãªããã¯/usr/sbin/ã®ä¸ã®haproxyãæãã¦ãã¾ãã
make installããã¨/usr/local/sbinã®ä¸ã«haproxyã³ãã³ããã¤ã³ã¹ãã¼ã«ãããã®ã§å¤æ´ããå¿
è¦ãããã¾ãã
(ã¤ã³ã¹ãã¼ã«ãªãã·ã§ã³ããããããªãã®ã§ãããããã«è¦ã¤ããã)
$ vi /ect/init.d/haproxy
HAPROXY=/usr/sbin/haproxy
ã以ä¸ã«ä¿®æ£
HAPROXY=/usr/local/sbin/haproxy
åèµ·åãã¾ãã
$ sudo /etc/init.d/haproxy restart
*1:Nginxã¯WebSocketã«å¯¾å¿ãããã©ã°ã¤ã³ãããã¾ããããã¹ããããã«ããæ¯ãåããªã©ãã§ããªãããæè»ãªæ§æã¯åãã¾ãã
*2:WebSocketã«å¯¾å¿ãããªãã¼ã¹ãããã·ãµã¼ãã¼ã¯ãä»ã«Poundãããã¾ãããã¡ãã®è¨äºã大å¤åèã«ãªãã¾ã:Railsの各種サーバーの速度ベンチマーク: Pound、Varnish、Nginx、Unicorn、Mongrel
*3:å®éã«ã¯ãco-meetingã¯node.jsã®æ¿ããã«jettyã使ã£ã¦ãã¾ã