七層 TCP 路由代理:ProxyMachine

jopen 9年前發布 | 16K 次閱讀 網絡工具包 ProxyMachine

ProxyMachine 是一個簡單的 7 層 TCP 路由代理,基于 EventMachine 構建,可使用 Ruby 語言配置路由規則。如果你需要將不同的請求內容轉發到后端不同的服務器上,那么 ProxyMachine 非常適合你。

ProxyMachine 主要為 Github 的集群架構而開發,每天可代理幾百萬請求,性能和內存占用表現良好。

安裝:

$ gem install proxymachine -s http://gemcutter.org

使用方法:

Usage:
  proxymachine -c <config file> [-h <host>] [-p <port>]

Options:
  -c, --config CONFIG              Configuration file
  -h, --host HOST                  Hostname to bind. Default 0.0.0.0
  -p, --port PORT                  Port to listen on. Default 5432

示例配置:

class GitRouter
  # Look at the routing table and return the correct address for +name+
  # Returns "<host>:<port>" e.g. "ae8f31c.example.com:9418"
  def self.lookup(name)
    ...
  end
end

# Perform content-aware routing based on the stream data. Here, the
# header information from the Git protocol is parsed to find the 
# username and a lookup routine is run on the name to find the correct
# backend server. If no match can be made yet, do nothing with the
# connection.
proxy do |data|
  if data =~ %r{^....git-upload-pack /([\w\.\-]+)/[\w\.\-]+\000host=\w+\000}
    name = $1
    { :remote => GitRouter.lookup(name) }
  else
    { :noop => true }
  end
end

項目主頁:http://www.baiduhome.net/lib/view/home/1424577804830

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!