微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ProxyMachine 7 层 TCP 路由代理

程序名称:ProxyMachine

授权协议: MIT

操作系统: Linux

开发语言: Ruby

ProxyMachine 介绍

Proxy Machine 是一个简单的 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 @R_156_4045@ion 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

ProxyMachine 官网

https://github.com/mojombo/proxymachine

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐