假设我有一个具有以下要求的REST API系统:
The API that can be accessed via this URL http://<ipaddress>/api/ I have three computers with three IP addresses: IP A, B and C respectively. Each of this computer can be accessed via URL API specified earlier. to access A the URL is http://<IP A>/api. to access B the URL is http://<IP B>/api. to access C the URL is http://<IP C>/api. Each computer may have different information / resources. A has resource X B has resource Y C has resource Z Client 1 has access in resource X Client 2 has access in resource Y Client 3 has access in resource Z
问题:我可以使用域名在一个URL中构build这三个API访问权限吗? 例如, http://这三台计算机的示例/ api (单个URL中的A,B和C http:// example / api )?
我知道的是,DNS可能会返回多个IP,客户端可以循环方式select1个IP。 但是,在这种情况下,A,B和C具有不同的资源。 所以客户端需要被映射到特定的机器。 例如,来自客户端1的请求需要被映射到资源X所在的计算机A.
后续问题:如果DNS不合适,是否有另一种分布式协议来实现这种系统?
谢谢。
你有多种select,最简单的select:
以循环方式使用DNSlogging(例如api.yourcompany.com),以便所有客户端都可以通过http://api.yourcompany.com/api访问api,并且由于循环访问将会或多或less地达到平衡。 然后,对于每个服务X,Y,Z,您可以使用指向正确服务器的CNAME创buildDNSlogging,如servicex.yourcompany.com,servicey.yourcompany.com。
正如Ian Bamforth所说,你也可以在它们前面有一个反向代理(nginx,apache,haproxy …),并根据所用的URLredirect到所需的服务。
编辑:
Apache的示例configuration
<Proxy "balancer://apicluster"> BalancerMember "http://serverx.yourcompany.com:80" BalancerMember "http://servery.yourcompany.com:80" BalancerMember "http://serverz.yourcompany.com:80" </Proxy> ProxyPass /api/ balancer://apicluster/api/ ProxyPass /servicex/ http://serverx.yourcompany.com/servicex/ ProxyPass /servicex/ http://servery.yourcompany.com/servicey/ ProxyPass /servicex/ http://serverz.yourcompany.com/servicez/
这样,通过URL / api访问您的服务器的请求将通过负载均衡器路由 ,URLs / servicex将被路由到serverx等等。