我们使用Nginx作为websocket应用程序的负载均衡器.每个后端服务器都会保留会话信息,因此客户端的每个请求都必须在同一服务器上转发.所以我们使用ip_hash指令来实现这个目的:
upstream app {
ip_hash;
server 1;
}
Run Code Online (Sandbox Code Playgroud)
当我们想要添加另一个后端服务器时,会出现问题:
upstream app {
ip_hash;
server 1;
server 2;
}
Run Code Online (Sandbox Code Playgroud)
新的连接转到服务器1和服务器2 - 但这不是我们在这种情况下需要的,因为服务器1上的负载继续增加 - 我们仍然需要粘性会话但是也least_conn启用了算法 - 所以我们的两台服务器接收的负载大致相等.
我们也考虑过使用Nginx-sticky-module但文档说如果没有可用的粘性cookie,它将回退到循环默认的Nginx算法 - 所以它也没有解决问题.
所以问题是我们可以使用Nginx组合粘性和最少连接逻辑吗?你知道其他负载均衡器能解决这个问题吗?
我正在学习Go并遇到了这个问题.
我只是使用HTTP客户端下载网页内容:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
client := &http.Client{}
req, err := http.NewRequest("GET", "https://mail.ru/", nil)
req.Close = true
response, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
content, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(content)[:100])
}
Run Code Online (Sandbox Code Playgroud)
我得到一个unexpected EOF读响应主体时的错误.同时内容变量具有完整页面内容.
仅在下载https://mail.ru/内容时才会出现此错误.使用其他URL一切正常 - 没有任何错误.
我使用curl下载此页面内容 - 一切都按预期工作.
我有点困惑 - 这里发生了什么?
去v1.2,在Ubuntu和MacOS X上试过
我使用以下简单脚本:
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
cmdgen.CommunityData('test-agent', 'public'),
cmdgen.UdpTransportTarget(('IP.IP.IP.IP', 161)),
0,
1,
(1,3,6,1,2,1,4,24,4,1,2,169,254)
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
Run Code Online (Sandbox Code Playgroud)
从命令行使用snmpwalk到此设备返回预期结果.但脚本返回超时之前未收到SNMP响应.如果我省略这个OID,那么一切正常.所以问题在于这个OID
这里tcpdump统计:
/usr/sbin/tcpdump -nn -vv -s0 -A host HOST and udp
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
12:15:31.494920 …Run Code Online (Sandbox Code Playgroud)