Experiment of using Docker to enlarge capacity under LVS

Source: Internet
Author: User
Tags docker run

Experiment of using Docker to enlarge capacity under LVS

topology

Lap Environment LVS

1. Installation components: Keepalived and LVs

Note that keepalived Apt-get installed version of the bug, in the automatic testing of RS, has been reported error, not automatically detect, download 1.2.19 version of the source code compiled after installation PIDM minimises.

Apt-getupdate

Apt-getinstall Ipvsadm

Apt-getinstall keepalived

2. Configuration

is mainly/etc/keepalived/keepalived.conf file.

Root@ubuntu:~/dev/keepalived-1.2.19#cat/etc/keepalived/keepalived.conf

#GlobalConfiguration

global_defs{

lvs_id Lvs_m

}

#VRRPConfiguration

Vrrp_instancezgye_lvs {

State MASTER has been repaired to backup on #LVS_S

Interface eth0

VIRTUAL_ROUTER_ID 60

Priority #LVS_S on the repair hair 50, less than lvs_m, to determine which is the main

Advert_int 5

Authentication {

Auth_type PASS

Auth_pass Zgye_test

}

virtual_ipaddress {

172.18.2.100

}

#Virtual Server configu-for WWW Service

Virtual_server 172.18.2.100 80 {

Delay_loop 1

Lb_algo RR

Lb_kind DR

Persistence_timerout 60

Protocol TCP

#Real Server 1 Config-web1

Real_server 172.18.2.83 80 {

Weight 1

Tcp_check {

Connection_timeout10

Nb_get_retry 3

Delay_before_retry3

Connect_port 80

}

}

Real_server 172.18.2.85 80 {

Weight 1

Tcp_check {

Connection_timeout10

Nb_get_retry 3

Delay_before_retry3

Connect_port 80

}

}

Real_server 172.18.2.125 80 {

Weight 1

Tcp_check {

Connection_timeout10

Nb_get_retry 3

Delay_before_retry3

Connect_port 80

}

}

}

}

RS

VMS

1. Installation components: Nginx

Apt-get Install Nginx

2. Configure Nginx

The main thing is to modify the/usr/share/nginx/html/index.html to distinguish which RS did the answer.

3. Add VIP

Ifconfig eth0:0 172.18.2.100 broadcast172.18.2.100 netmask 255.255.255.255 up

Route Add-host 172.18.2.100 deveth0:0

4. Modify ARP Filtering

Echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore

Echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce

Echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore

Echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce

DOCKER

1. Installing Docker

Apt-key adv--keyserverhkp://keyserver.ubuntu.com:80--recv-keys36a1d7869245c8950f966e92d8576a8ba88d21e9

Sh-c "Echo Debhttps://get.docker.com/ubuntu Docker main >/etc/apt/sources.list.d/docker.list"

Apt-get Update

Apt-get install-y Lxc-docker Gitmake

Source/etc/bash_completion.d/docker

2. Download the nginx image

Docker Pull Nginx

3. Run the Nginx container

Docker run-it--net=none--name=nginx2 Nginx/bin/bash

4. Configure fixed IP

Using Script configuration:

./docker_static_ip.sh a2ad572f9ca2172.18.2.125 255.255.255.128 172.18.2.1 nginx_2

Where the script is:

root@oa-72:~# catdocker_static_ip.sh

#/bin/bash

Br_dev=br0

If [-Z] | | [-Z] | | [-z$3] | | [-Z $4] | | [-z];

Then

echo "*****input the Necessaryparameters:containerid IP MASK GATEWAY ethname"

echo "*****call the script like:sh manual_con_static_ip.sh b0e18b6a4432192.168.5.123 192.168.5.1 deth0"

Exit

Fi

Containerid=$1

Setip=$2

Setmask=$3

Gateway=$4

Ethname=$5

Ifconfig $ETHNAME >/dev/null2>&1

If [$?-eq 0]; Then

Read-p "$ETHNAME exist,do you want delelte it? y/n "Del

if [[$del = = ' Y ']]; Then

IP link del $ETHNAME

Else

Exit

Fi

Fi

#

Pid= ' Docker inspect-f ' {{. State.pid}} ' $CONTAINERID '

Mkdir-p/var/run/netns

Find-l/var/run/netns-type L-delete

If [-f/var/run/netns/$pid]; Then

Rm-f/var/run/netns/$pid

Fi

Ln-s/proc/$pid/ns/net/var/run/netns/$pid

#

IP link Add $ETHNAME type veth peername B

Brctl addif $BR _dev $ETHNAME

IP link Set $ETHNAME up

IP link set B netns $pid

#delete Eth0 in Docker

IP netns exec $pid IP link del eth0>/dev/null 2>&1

#set Eth0 in Docker

IP netns exec $pid IP link set devb name eth0

IP netns exec $pid IP link set eth0up

IP netns exec $pid ip addr add$setip/$SETMASK dev eth0

IP netns exec $pid IP route adddefault via $GATEWAY

5. Configure VIP

Configure IP commands in the reference script:

IP netns exec 7397 IP addr Add 172.18.2.100/25dev eth0

6. Start the Nginx service

Docker exec-d nginx2 Service nginxstart data message

Client: Send the request to the VIP.

LVS: Only requests are received and modification requests are sent to RS, which is answered by Rs.

RS: Received the first SYN of the SMAC for LVs, but back to the syn\ack of the Dmac into the client's Mac.

Test

Through the cilent.

root@ubuntu:~# for ((i=0; i<100; i++)); Do curlhttp://172.18.2.100:80; Done

Access to test the equalization situation

On the 113 you can see:

root@ubuntu:~# Ipvsadm-ln

IP Virtual Server version 1.2.1 (size=4096)

Prot Localaddress:port Scheduler Flags

->remoteaddress:port forwardweight Activeconn Inactconn

TCP 172.18.2.100:80 RR

->172.18.2.83:80 Route 1 0 33

->172.18.2.85:80 Route 1 0 33

->172.18.2.125:80 Route 1 0 34

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.