Using Linux architecture load balancing (2)

xiaoxiao2021-03-06  39

achieve

1. Hardware configuration: I my own experimental environment is 5 PCs, two as LLBs, and two network cards in two LLBs. The other three Web servers. A HUB.

2, software configuration on LLB:

· OS: Redhat Linux 6.2

· Linux kernel: Linux-2.2.17

· IPVSADM: IPvs-0.9.16

· Ipchains: ipchains 1.3.9

KeePalived: Keepalived-0.2.7

· Heartbeat: HeartBeat-0.4.9

3, software installation:

· Install IPvs-0.9.16-2.2.17.tar.gz

#TAR ZXVF IPvs-0.9.16-2.2.17.tar.gz

#CD / USR / SRC / Linux

#cat

/IPVS-0.9.16-2.2.17.patch | patch -p1

After this step is complete, you must recompile Linux kernel and determine the following options to be compiled into the new kernel!

Kernel Compile Options:

Code Maturity Level Options ---

[*] Prompt for development and / or ibPlete code / drivers

NetWorking Options ---

[*] NetWork FireWalls

....

[*] Ip: firewalling

....

[*] IP: Masquerading

....

[*] IP: Masquerading Virtual Server Support

(12) IP Masquerading Table Size (The Nth Power of 2)

<*> Ipvs: round-robin scheduling

<*> Ipvs: weighted round-robin scheduling

<*> Ipvs: Least-Connection Scheduling

<*> Ipvs: weighted least-connection scheduling

....

[*] IP: AliaSing Support

After the kernel is compiled, use the new kernel to restart the system.

Then do the following command:

#CD /

/ IPVSADM /

#make

#make install

At this point, IPVSADM is installed!

· Install KeePaliveD-0.2.7.tar.gz, execute the following command:

#TAR KeepaliveD-0.2.7.tar.gz

#CD KeepaliveD-0.2.7

#make

#make install

· Install HeartBeat-0.4.9.tar.gz

#TAR ZXVF HeartBeat-0.4.9.tar.gz

#CD HeartBeat-0.4.9

#make

#make install

4, configuration:

The configuration of the IP address:

User IP address: 192.168.2.21

Two LLBs have two network cards: Eth0, Eth1,

Master Llb eth0: 192.168.2.1

Master Llb Eth1: 10.10.10.1

Slave llb eth0: 192.168.2.2

Slave Llb Eth1: 10.10.10.2

Server-1: 10.10.10.11

Server-2: 10.10.10.12

Server-3: 10.10.10.13

There are also two special IP addresses to pay more attention to, one is the IP address used throughout the cluster, we call it VIP (Virtual IP), we

He is set to: 192.168.2.11, this IP address should appear in your DNS, such as this cluster we configured to provide a web service, there should be such a record in DNS:

Www.your-domain.com -> 192.168.2.11

After the LLB startup, VIP will run on the Eth0: 0 of the LLB;

Another special IP is Eth1: 0 running in LLB, this IP is the default gateway of three servers, we call it V-Gate (Virtual Gate).

The subnet mask of all IP addresses is available in 255.255.255.0. VIP is configured later with V-GATE. So far, the network should be a such environment:

Client

192.168.2.21

________ | __________

| | |

| | |

Master LLB Slave LLB

Eth0: 192.168.2.1 Eth0: 192.168.2.2

Eth1: 10.10.10.10.1 Eth1: 10.10.10.2

| | |

| __________________ |

|

Hub

____________ | _______________

| | | | |

| | | | |

WebServer1 WebServer2 WebServer3

10.10.10.11 10.10.10.12 10.10.10.13

Profile:

In LLB, ipchains and ipvsadm are started by KeePalived, and Keepalived is started by HeartBeat. Keepalived has two profiles:

/etc/keepalived/keepalived.conf and /etc/lvs.conf

The /etc/lvs.conf is as follows:

#Configuration File for Portfw Nat

# / etc / lvs.conf

#Port forwarding

IPvsadm -a -t 192.168.2.11:80 -s rr

#nat

Ipchains -a forward -j masq -p tcp -s 10.10.10.0/24 80 -D 0.0.0.0/0

Explanation:

IPvsadm -a -t 192.168.2.11:80 -s rr

This sentence means that 192.168.2.11 is a cluster address (VIP) and is for 80 ports, that is, a web cluster. Adopting this cluster

Algorithm of Round-Robin (RR).

Ipchains -a forward -j masq -p tcp -s 10.10.10.0/24 80 -D 0.0.0.0/0

The role of this sentence is to disguise the IP address when the server responds to the user, from 10.10.10.11, 10.10.10.12, 10.10.10.13 pseudo

Furnished into 192.168.2.11.

The /etc/keepalived/keepalived.conf is as follows:

# Configuration File for Keepalived

#begin www server config .......

Virtual_server 192.168.2.11 80 {

LB_Algo RR

LB_Kind Nat

Protocol TCP

REAL_SERVER 10.10.10.11 80 {

Weight 1

ICMP_CHECK

}

REAL_SERVER 10.10.10.12 80 {

Weight 1

ICMP_CHECK

}

REAL_SERVER 10.10.10.13 80 {

Weight 1

ICMP_CHECK

}

}

#end of fweb config!

Explanation: For details of the three servers in this file, the three servers have the same weight value. Keepalived works in a Layer3 (ICMP_CHECK), which is scheduled to check whether the server exists.

HeartBeat has three profiles: /etc/ha.d/ha.cf; /etc/ha.d/hareesources; /etc/ha.D/Authkeys

/etc/ha.d/ha.cf content is as follows:

#

# Keepalive: How Many Seconds Between Heartbeats

#

Keepalive 2

Logfile / var / log / ha-log

#

# deadTime: secondtime: secondtime: secondtime: second-to-declare-host-dead

#

DeadTime 10

# Hopfudge Maximum Hop Count Minus Number of Nodes in config

Hopfudge 1

#

# What udp port to use for udp or ppp-udp communication?

#

UDPPORT 1001

# What interfacs to heartbeat over?

UDP eth0

#

# Facility to use for syslog () / logger (alternative to log / debugfile)

#

Logfacility Local0

#

# Tell What Machines Are in The Cluster

# Node Nodename ... - Must match uname -n

Node Master #Master is the machine name of Master LLB, which must be consistent with uname -n

Node Slave #slave is the machine name of Slave LLB, which must be consistent with uname -n

/etc/ha.d/hareesources is as follows:

Master ipaddr :: 10.10.10.9/24/eth1 ipaddr :: 192.168.2.11/24/eth0 KeePalived

Among them, 10.10.10.9 is the value of V-GATE, 192.168.2.11 is VIP value, which is set here. And explanation of Master is the LLB used.

Keepalived is a program that requires the HeartBeat startup. Keepalived is an executable file that automatically generated when installing KeePalived, Heartbeat

Looking for KeePalived in the /etc/ha.d/resource.d directory, you need to copy the executable KeepaliveD file to the /etc/ha.d/resource.d/ directory.

/etc/ha.d/ Authkeys is as follows:

Auth 1

1 sha1 cluster

This file is not very important, but must have. An Auth mechanism between the LLB is described herein. For detailed description, please refer to: www.linux-ha.org

At this point, all installation configurations are all completed. There are five configuration files:

· /Etc/keepalived/keepalived.conf

· /Etc/lvs.conf

· /Etc/ha.d/ha.cf

· /Etc/ha.d/hareesources

· /Etc/ha.D/Authkeys

Please check it carefully and make sure these five files are installed on Master LLB and Slave LLB. The next step can be started.

Start system:

[root @ Master Heartbeat] #heartbeat start

[root @ slave healthbeat] # Heartbeat Start

转载请注明原文地址:https://www.9cbs.com/read-77696.html

New Post(0)