We have three servers. For sake of simplicity let’s name them lx11, lx12 and lx13. Our goal is to have standard loadbalancing VIP (round-robin), but we need ability to force the connection to go to a specific server by setting appropriate header value in a HTTP request.
- Real servers are configured and alive.
- All of them have their server-id assigned. In our example its 1218, 1211 and 1213.
- Verify if the servers have their IDs assigned
server real linux-117.11 192.168.117.11 port http port http keepalive port http url "HEAD /" port http server-id 1218 port http group-id 1 1 ! server real linux-117.12 192.168.117.12 port http port http keepalive port http url "HEAD /" port http server-id 1211 port http group-id 1 1 ! server real linux-117.13 192.168.117.13 port http port http keepalive port http url "HEAD /" port http server-id 1213 port http group-id 1 1
In order to extract the value from the headers, we need to use CSW policies. Technically, we could use CSW policy to configure the persistence but we have explicit requirement that it needs to be just for part of the servers. Also, this method does not disclose what our server-ids are.
- Create CSW rules
csw-rule "j11" header "MyServerID" equals "Server117.11" csw-rule "j12" header "MyServerID" equals "Server117.12" csw-rule "j13" header "MyServerID" equals "Server117.13"
- Create CSW policy
csw-policy "hdr_balance" match "j11" forward 1218 match "j12" forward 1211 match "j13" forward 1213
- Apply CSW policy to the VIP
! server virtual VIP1 192.168.112.250 port http sticky port http csw-policy "hdr_balance" port http csw bind http linux-117.11 http linux-117.12 http linux-117.13 http !
- If you want to test if this works and you have ability to find out which server are you using based on the response, you can fire a HTTP request with specified header towards the server:
skrobul > curl http://192.168.80.250/jsessionid.php -H "MyServerID: Server117.13" -v * About to connect() to 192.168.80.250 port 80 (#0) * Trying 192.168.80.250... * connected * Connected to 192.168.80.250 (192.168.80.250) port 80 (#0) > GET /jsessionid.php HTTP/1.1 > User-Agent: curl/7.26.0 > Host: 192.168.80.250 > Accept: */* > MyServerID: Server117.13 > * HTTP 1.0, assume close after body Server 117.13
- Closing connection #0