使用 curl 强制 HAProxy 服务器亲和力?
Force HAProxy server affinity with curl?
如何使用 curl 强制 HAProxy 服务器关联?
我试过 curl 7.58 版:
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
我仍在获取循环法、首次连接负载平衡:
HTTP/1.1 200 Connection established
set-cookie: SRV_ID="172.21.0.3"; path=/
HTTP/1.1 200 OK
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Sat, 16 Nov 2019 22:05:22 GMT
ETag: W/"86-77S8g6gXGJd5i+Emjsb0b9sIcac"
Server: nginx
set-cookie: sails.sid=s%3AC1VtUY_GI...HsNx7LDg; Path=/; HttpOnly
Vary: Accept-Encoding
Connection: keep-alive
HAProxy 2.0.8相关后端配置:
backend http-backend
mode http
balance roundrobin
default-server inter 2s fastinter 2s downinter 2s fall 3 rise 2
cookie SRV_ID insert
server container-172-21-0-2 172.21.0.2:3000 cookie \"172.21.0.2\" check
server container-172-21-0-3 172.21.0.3:3000 cookie \"172.21.0.3\" check
我可以保存和发送保存的 cookie,我可以编辑 cookie-jar 文件以获得我正在寻找的效果,但是如何在一行中制作 curl 命令?
curl -b cookies.txt -c cookies.txt -x localhost:3001 http://scooterlabs.com/echo
Cookites.txt内容:
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
scooterlabs.com FALSE / FALSE 0 SRV_ID "172.21.0.2"
替换
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
与
curl -I \
--proxy-header "Cookie: SRV_ID=\"172.0.0.2\"" \
-x localhost:3001 \
https://postman-echo.com/headers
请注意 SRV_ID 值周围的额外引号。这必须匹配 cookie \"172.21.0.2\" check
.
中 'cookie' 和 'check' 之间的字符串
如何使用 curl 强制 HAProxy 服务器关联?
我试过 curl 7.58 版:
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
我仍在获取循环法、首次连接负载平衡:
HTTP/1.1 200 Connection established
set-cookie: SRV_ID="172.21.0.3"; path=/
HTTP/1.1 200 OK
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Sat, 16 Nov 2019 22:05:22 GMT
ETag: W/"86-77S8g6gXGJd5i+Emjsb0b9sIcac"
Server: nginx
set-cookie: sails.sid=s%3AC1VtUY_GI...HsNx7LDg; Path=/; HttpOnly
Vary: Accept-Encoding
Connection: keep-alive
HAProxy 2.0.8相关后端配置:
backend http-backend
mode http
balance roundrobin
default-server inter 2s fastinter 2s downinter 2s fall 3 rise 2
cookie SRV_ID insert
server container-172-21-0-2 172.21.0.2:3000 cookie \"172.21.0.2\" check
server container-172-21-0-3 172.21.0.3:3000 cookie \"172.21.0.3\" check
我可以保存和发送保存的 cookie,我可以编辑 cookie-jar 文件以获得我正在寻找的效果,但是如何在一行中制作 curl 命令?
curl -b cookies.txt -c cookies.txt -x localhost:3001 http://scooterlabs.com/echo
Cookites.txt内容:
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
scooterlabs.com FALSE / FALSE 0 SRV_ID "172.21.0.2"
替换
curl -I \
--proxy-header "Cookie: SRV_ID=172.0.0.2" \
-x localhost:3001 \
https://postman-echo.com/headers
与
curl -I \
--proxy-header "Cookie: SRV_ID=\"172.0.0.2\"" \
-x localhost:3001 \
https://postman-echo.com/headers
请注意 SRV_ID 值周围的额外引号。这必须匹配 cookie \"172.21.0.2\" check
.