我主持一个使用TCP连接的游戏客户端的网站。 我目前正在寻找一种方法来代理我的连接从一台服务器到我的原始服务器。 我已经testing了iptables的转发,我发现,虽然它的工作HaProxy似乎performance更好。 我面临的问题是HaProxy在随机连接打开后随机断开用户连接。 通常不到2分钟。 我对Linux很新,当然我也是haProxy的新手。
在这里,我的configuration,原始IP地址已被删除,原因很明显:
global daemon maxconn 1000 defaults mode tcp timeout connect 5000ms timeout client 5000ms timeout server 5000ms frontend proxy-in mode tcp bind *:1233 default_backend proxy-out backend proxy-out mode tcp server s1 127.0.0.1:1232 listen admin bind *:7772 stats enable
谢谢。 可以提供更多细节(如果需要的话)。
根据您的游戏服务器的工作方式,您可能需要使用timeout client和timeout server 。 这些在您的configuration中目前设置为5秒。
这些设置与你的tcp会话有关。 如果你想在服务器上稍微好一些,你可能还需要考虑持久化configuration文件来平衡与同一台服务器的连接。 这又取决于你的configuration。
也看看balance选项查看文档。
haproxy文档中的algorithm示例:( http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#balance )
leastconn The server with the lowest number of connections receives the connection. Round-robin is performed within groups of servers of the same load to ensure that all servers will be used. Use of this algorithm is recommended where very long sessions are expected, such as LDAP, SQL, TSE, etc... but is not very well suited for protocols using short sessions such as HTTP. This algorithm is dynamic, which means that server weights may be adjusted on the fly for slow starts for instance.
也可能需要tcp保持活动状态:( http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#option%20tcpka )
您也可以通过一个很好的工具haproxyctl主动查看会话,您可以在github上find它,或者使用gem install haproxyctl进行gem install haproxyctl 。
> haproxyctl show sess 0x1eb23c0: proto=tcpv4 src=172.12.0.149:57749 fe=https be=<NONE> srv=<none> ts=08 age=1m36s calls=40 rq[f=400000h,i=0,an=1ch,rx=1m23s,wx=,ax=] rp[f=008000h,i=0,an=00h,rx=,wx=,ax=] s0=[7,8h,fd=2,ex=] s1=[0,0h,fd=-1,ex=] exp=1m23s 0x1e3b170: proto=tcpv4 src=172.12.0.149:57750 fe=https be=<NONE> srv=<none> ts=08 age=1m36s calls=31 rq[f=400000h,i=0,an=1ch,rx=1m23s,wx=,ax=] rp[f=008000h,i=0,an=00h,rx=,wx=,ax=] s0=[7,8h,fd=3,ex=] s1=[0,0h,fd=-1,ex=] exp=1m23s 0x1e35da0: proto=tcpv4 src=172.12.0.149:57751 fe=https be=<NONE> srv=<none> ts=08 age=1m36s calls=35 rq[f=400000h,i=0,an=1ch,rx=1m23s,wx=,ax=] rp[f=008000h,i=0,an=00h,rx=,wx=,ax=] s0=[7,8h,fd=8,ex=] s1=[0,0h,fd=-1,ex=] exp=1m23s 0x1e4fa50: proto=tcpv4 src=172.12.0.149:57754 fe=https be=<NONE> srv=<none> ts=08 age=1m36s calls=15 rq[f=400000h,i=0,an=1ch,rx=1m23s,wx=,ax=] rp[f=008000h,i=0,an=00h,rx=,wx=,ax=] s0=[7,8h,fd=9,ex=] s1=[0,0h,fd=-1,ex=] exp=1m23s