我使用HaProxy作为负载平衡,版本为1.5.14
这是haproxy.cfg文件配置:
global
log 127.0.0.1 local2 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
debug
default
mode tcp
retries 2
option redispatch
option abortonclose
maxconn 4096
timeout connect 5000ms
timeout client 30000ms
timeout server 30000ms
#timeout check 2000
log 127.0.0.1 local0 debug
listen app1
log 127.0.0.1 local2 debug
bind 0.0.0.0:5000
mode tcp
server s1 127.0.0.1:5001 check
server s2 127.0.0.1:5002 check
后面的服务器我用node.js写的:
var net = require('net');
var server = net.createServer(function(sv_c){
sv_c.on('error',function(err){
console.log(err);
});
sv_c.on('data',function(data){
console.log(data);
sv_c.write("ok");
})
sv_c.on('end',function(){
console.log('close socket');
})
console.log(sv_c.remoteAddress);
console.log(sv_c.remotePort);
console.log(sv_c.localAddress);
console.log(sv_c.localPort);
}).listen(5001);
请求程序我也是node.js写的:
var net = require('net');
var client = new net.Socket();
client.on('error',function(err){
console.log(err);
});
client.connect(5000,'127.0.0.1',function(){
console.log('connection');
client.write("request");
client.on('data',function(data){
console.log(data+"end");
client.end();
})
})
我的服务器端没有收到连接,请求端返回了一段网页:
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html
400 Bad request
Your browser sent an invalid request.
我已经设置为tcp mode了呀,还有那些地方做错了吗?