Prepare two virtual machines: Client / Server
- 环境:
Distributor ID: CentOS
Description: CentOS Linux release 7.7.1908 (Core)
Release: 7.7.1908
Codename: Core
LVS achieve load balancing
- Client as a client, Server as a server
- Server running at the end of the installation for scheduling LVS
- It provides a web service in Server-side run two mirrored nginx
Implementation
Server installation docker
visible official documents
also see my other essay- Start docker, mirrored pull nginx
systemctl start docker
docker pull nginx:1.17-alpine
- Deploy two vessels nginx as a web service: web1, web2
docker run --name web1 -d nginx:1.17-alpine
docker exec -it web1 /bin/sh
echo '<h1>web1<h1>' > /usr/share/nginx/html/index.html
docker run --name web2 -d nginx:1.17-alpine
docker exec -it web2 /bin/sh
echo '<h1>web2<h1>' > /usr/share/nginx/html/index.html
Server-side view of the container and ip address of the
Server side: run directlyifconfig
container: Thedocker exec
operation of the case into the containerifconfig
- Installation ipvsadm
yum -y install ipvsadm
- Add scheduling rules
ipvsadm -A -t Server端ip地址:80 -s rr
ipvsadm -a -t Server端ip地址:80 -r 容器ip地址:80 -m
- Client Client Access Server
curl Server端ip地址
Experimental results
Encounter problems
- Client-Server can not access the service side of the web, but can ping
- Server-side port 80 open Solution:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT