Overview
This article describes how to use the curl
command to test the effectiveness of session persistence of SLB.
Description
This topic provides an example.
Sample Information
- SLB instance: assume that the public IP address of the SLB instance is 1.1.1.1, and the backend servers are two ECS instances.
- Two backend ECS instances: both run Web services, and the internal network IP addresses are 192.168.32.175 and 192.168.32.177 respectively. Create a test page in the check.php file on both ECS instances. This page displays the Cookie and internal IP address information of the ECS instances. The check.php code is as follows:
<? php
Access check.php. A similar output is displayed:
setcookie('mycookie','cookietest');
echo 'Cookie is: ';
echo ($_COOKIE['mycookie']);
echo '</br>';
echo 'Current ECS is : ';
echo '</br>';
var_dump($_SERVER['SERVER_ADDR']);
? > - Test address:
http://1.1.1.1/check.php
- Client Test Machine: Linux, you can access the test address.
Test procedure
The functional test of session persistence for layer -4 (TCP/UDP) and layer -7 (HTTP/HTTPS) listening is different and described separately.
Layer 4 listener
To test the validity of session persistence, perform the following steps:
- Log on to the client test machine.
- Create a new test script check_4.sh, the content is as follows.
for ((a=1;a<=30;a++))
do
curl http://1.1.1.1/check.php 2>/dev/null | grep 'ECS'
sleep 1
doneNote: by default, the script is tested 30 times. You can modify
aonce=30
to modify the test times. - Run the following command to perform a session persistence test:
sh check_4.sh
The following system output is displayed:- If the returned internal IP addresses of all backend ECS instances are the same, session persistence applies.
- If the returned intranet IP address of the backend ECS instance is not fixed, session persistence fails.
- If the returned internal IP addresses of all backend ECS instances are the same, session persistence applies.
layer -7 listener
To test the validity of session persistence, perform the following steps:
- Log on to the client test machine.
- Run the following command to save the Cookie value of the SLB instance:
Note: Alibaba Cloud session persistence for layer -7 SLB is to insert cookies by default. The
curl
command does not save or send cookies. You need to save the corresponding Cookie before testing. Otherwise, thecurl
test results will be random, affecting the accuracy of the test results.curl -D test.cookie http://1.1.1.1/check.php
- Create a new test script check_7.sh, the content is as follows.
for ((a=1;a<=30;a++))
do
curl -b test.cookie http://1.1.1.1/check.php 2>/dev/null | grep 'ECS'
sleep 1
doneNote: by default, the script is tested 30 times. You can modify
aonce=30
to modify the test times. - Run the following command to perform a session persistence test:
sh check_7.sh
The following system output is displayed:- If the returned internal IP addresses of all backend ECS instances are the same, session persistence applies.
- If the returned intranet IP address of the backend ECS instance is not fixed, session persistence fails.
- If the returned internal IP addresses of all backend ECS instances are the same, session persistence applies.
Related topics
The session persistence in SLB is invalid.
Application scope
- SLB