2015-04-21
NginxのTCP Load BalancingがOSS版でも使えるらしいので試す
NginxのTCP Load Balancing(ngx_stream_core_module)
もともとNginx+で利用できたTCP Load Balancing機能というものがある
http://nginx.com/products/application-load-balancing/
HTTPにかぎらずTCPレイヤでロードバランシグ機能を提供する。つまりMySQLやMemcachedのロードバランサとしても使用することができるようになる。
OSS版でも使用できるようになったらしい
http://hg.nginx.org/nginx/rev/61d7ae76647d
試しにMemcachedのロードバランサを構築してみた(環境はubuntu14.04)
nginxビルド
ざっと適当にインストール
sudo apt-get install libpcre3 libpcre3-dev build-essential
http://hg.nginx.org/nginx/ より最新リビジョンをダウンロードしてビルドする。
wget http://hg.nginx.org/nginx/archive/61d7ae76647d.tar.gz tar zxvf ./61d7ae76647d.tar.gz cd nginx-61d7ae76647d ./auto/configure --with-stream make sudo make install
どうやら、--with-stream_ssl_module なんてのもあるぽい
conf
nginx.confに以下の設定をする。
バックエンドとして、memcachedを立てたサーバを別途用意した。
ココらへんを参考に
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
stream {
upstream backend {
server 192.168.0.2:11211 weight=5 max_fails=3 fail_timeout=30s;
server 192.168.0.3:11211 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 11211;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass backend;
}
}
接続してみる
nginxを起動し、nginxを立てたサーバよりtelnetをする。
数回statsを見ると、別のpidであり別々のサーバに繋がっている事が確認できる。
vagrant@dev:~$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. stats STAT pid 3556 ...
vagrant@dev:~$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. stats STAT pid 11249 ...
トラックバック - http://d.hatena.ne.jp/ASnoKaze/20150421/1429621022
リンク元
- 13 https://www.google.co.jp/
- 7 http://t.co/OYlRHtzlDM
- 3 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCAQFjAA&url=http://d.hatena.ne.jp/ASnoKaze/20130207/1360249692&ei=q3I2Vb7CAYPw8gWF84GYDw&usg=AFQjCNG6U39T_6eson3cAMiSQpaN1psIYA&sig2=943zK7atkkUsFblL0Q-Grw&bvm=bv.91071109,
- 1 http://api.twitter.com/1/statuses/show/590521009603653632.json
- 1 http://api.twitter.com/1/statuses/show/590646069094129664.json
- 1 http://api.twitter.com/1/statuses/show/590650253906415617.json
- 1 http://d.hatena.ne.jp
- 1 http://search.yahoo.co.jp/search;_ylt=A3xTtNXEzTZVB2EAx5uJBtF7?p=mySQL プロトコル&search.x=1&fr=top_ga1_sa&tid=top_ga1_sa&ei=UTF-8&aq=4&oq=&afs=
- 1 http://www.google.co.jp/search?hl=ja&lr=lang_ja&output=rss&q=(apache|squid|delegate|nginx|lighttpd)&tbm=blg
- 1 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&sqi=2&ved=0CDkQFjAD&url=http://d.hatena.ne.jp/ASnoKaze/20140423/1398270171&ei=QI42Ve6sLZD68QX9sIHoDg&usg=AFQjCNFBofo7tc328BtlEboPu0FN_AXe2A&bvm=bv.91071109,d.dGc