ProxyMachine —— 7 层 TCP 路由代理

简介:

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 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.oschina.net]

相关文章
|
负载均衡 网络协议 应用服务中间件
CentOS7下使用nginx实现TCP和UDP代理
CentOS7下使用nginx实现TCP和UDP代理
922 0
CentOS7下使用nginx实现TCP和UDP代理
|
网络协议 Shell 网络虚拟化
第九章 TCP/IP-trunk排错和单臂路由(二)
前言:了解思科交换机接口协商,以及单臂路由和DHCP配置
193 0
第九章 TCP/IP-trunk排错和单臂路由(二)
|
网络协议 网络虚拟化
第九章 TCP/IP-trunk排错和单臂路由(一)
前言:了解思科交换机接口协商,以及单臂路由和DHCP配置
96 0
第九章 TCP/IP-trunk排错和单臂路由(一)
|
网络协议
Wireshark抓包分析/TCP/Http/Https及代理IP的识别
前言   坦白讲,没想好怎样的开头。辗转三年过去了。一切已经变化了许多,一切似乎从没有改变。   前段时间调研了一次代理相关的知识,简单整理一下分享之。如有错误,欢迎指正。 涉及 Proxy IP应用 原理/层级wireshark抓包分析 HTTP head: X-Forwarded-For/ Proxy-Connection/伪造  X-Forwarded-For/ 以及常见的识别手段等几个方面。
2402 0
|
网络协议 应用服务中间件 容器
Istio流量管理实践之(1): 通过Istio规则来实现TCP入口流量路由的统一管理
本文通过一个示例来讲述如何通过一个简单且标准的Istio规则来控制TCP入口流量的路由,从而实现TCP入口流量路由的统一管理。
5191 0
|
网络协议 应用服务中间件 nginx
nginx代理socket tcp/udp
准备一台linux服务器。nginx官网:http://nginx.org/ 。在网上搜到大致用的是 ngx_stream_core_module 这个模块,这里你也可以关注一下官方文档中的其他模块都是做什么的,那么这有相关的启用配置说明,与示例配置。
3637 0
|
网络协议 应用服务中间件 nginx
|
Web App开发 测试技术 应用服务中间件
|
网络协议 运维 网络架构