Created
February 12, 2019 07:41
-
-
Save bjethwan/f71c7b0a53f963727d132ef09d2e6eec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IPVS on AWS EC2 | |
ip_vs & ipvsadm | |
Note: ipvsadm is just the cli tools for interacting with the IP virtual server table in the kernel. | |
"ip_vs" is the kernel module that does the actual connection manipulating. | |
ipvsadm command options: | |
Either long or short options are allowed. | |
--add-service -A add virtual service with options | |
--edit-service -E edit virtual service with options | |
--add-server -a add real server with options | |
--edit-server -e edit real server with options | |
--tcp-service -t service-address service-address is host[:port] | |
--udp-service -u service-address service-address is host[:port] | |
sudo yum install -y ipvsadm | |
sudo ipvsadm -l | |
mkdir /home/ec2-user/srv | |
mkdir /home/ec2-user/srv/A | |
mkdir /home/ec2-user/srv/B | |
echo "This is A" > /home/ec2-user/srv/A/index.html | |
echo "This is B" > /home/ec2-user/srv/B/index.html | |
sudo docker run --rm -d -v "/home/ec2-user/srv/A:/usr/share/nginx/html" --name nginx-a nginx | |
sudo docker run --rm -d -v "/home/ec2-user/srv/B:/usr/share/nginx/html" --name nginx-b nginx | |
sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx-a | |
172.17.0.2 | |
sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx-b | |
172.17.0.3 | |
curl 172.17.0.2 | |
This is A | |
curl 172.17.0.3 | |
This is B | |
sudo ipvsadm -A -t 172.31.20.35:80 -s rr | |
sudo ipvsadm -a -t 172.31.20.35:80 -r 172.17.0.2 -m | |
sudo ipvsadm -a -t 172.31.20.35:80 -r 172.17.0.3 -m | |
sudo ipvsadm -l -n | |
for i in {1..10}; do curl private-ip; done | |
This is B | |
This is A | |
This is B | |
This is A | |
This is B | |
This is A | |
This is B | |
This is A | |
This is B | |
This is A | |
http://public-ip/ this worked well in mozilla browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment