Lvs:linux virtual Server, Lvs-nat mode +lvs-dr mode

Source: Internet
Author: User

Lvs:linux Virtual Server
What is a cluster:
A group of computing groups connected by a high-speed network, with a single system of modular
-Style management
? Centralize many servers together to provide the same service
The client looks like there's only one server
? Can be achieved at a lower cost in the performance, reliability,
Relatively high profitability in terms of flexibility
? Task scheduling is the core technology in cluster system
First, the mode of work
1. NAT
2. TUN: Tunnel mode (rarely used)
3. DR: Widely used
4. Full NAT: Large-scale deployment
Two, the LVS scheduling algorithm
1. Polling RR
2. Weighted polling WRR
3. Minimum connection LC
4. Least-weighted connection WLC
5, based on the local minimum connection LBLC
6. Local-based minimum connection LBLCR with replication
7. Source Address Hash sh
8. Destination Address hash DH
9. Minimum expected delay SED
10. Minimum queue scheduling NQ

Lvs-nat mode:
1. New Virtual machine vh04.tedu.cn 192.168.4.4
2. Host role:
(1) MySQL vh01
(2) vh02/vh03 web
(3) Vh04-Lvs-nat
(4) Physical host-Client
3, based on the morning environment, do some improvement
(1) Web server configuration Gateway
# nmtui # ifdown eth0; ifup eth0
(2) vh04 add another IP address. Eth2-201.1.1.4/24
[Email protected] ~]# Nmtui
(3) Turn on route forwarding on VH04 (7 version is already open, can not do)
[Email protected] ~]# Sysctl-a | grep Ip_forward
[Email protected] ~]# echo "Net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
[Email protected] ~]# sysctl-p
4. Configuring LVS
(1) Installation
[email protected] ~]# Yum install-y ipvsadm
(2) Create a virtual server, the scheduling algorithm is RR
[[email protected] ~]# ipvsadm-a-t 201.1.1.4:80-s RR
(3) Adding a real server to a virtual server
[Email protected] ~]# ipvsadm-a-t 201.1.1.4:80-r 192.168.4.2-m-w2
[Email protected] ~]# ipvsadm-a-t 201.1.1.4:80-r 192.168.4.3-m
(4) View rules
[Email protected] ~]# IPVSADM-LN
(5) Verification. Can configure different pages for two Web servers
[Email protected] html]# vim/var/www/html/index.html
(6) Modify the scheduling algorithm to WRR
[Email protected] ~]# ipvsadm-e-t 201.1.1.4:80-s WRR
(7) Delete
[Email protected] ~]# ipvsadm-d-t 201.1.1.4:80-r 192.168.4.3
[Email protected] ~]# ipvsadm-d-t 201.1.1.4:80

LVS-DR mode
First, topology: The LVS Scheduler has only one IP address, and it is on the same network as real server.
Second, the client to send the data to the VIP. VIP needs to appear on each server (scheduler, Web server)
Third, in order to address the conflict, the VIP needs to be configured on the eth0 of the Scheduler, the VIP configuration on the Web server lo
Four, each host has VIP, the client sent the request, only LVS response. To achieve this, you need to change the kernel parameters of the Web server
V. Implementation
1, still use vh04 as the scheduler, to clean it
[Email protected] ~]# Ifdown eth2
[Email protected] ~]# ipvsadm-d-t 201.1.1.4:80
2. Configure VIP on VH04
[[email protected] ~]# cp/etc/sysconfig/network-scripts/ifcfg-eth0{,:0}
[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0:0
Type=ethernet
Bootproto=none
name=eth0:0
device=eth0:0
Onboot=yes
ipaddr=192.168.4.100
Prefix=24
[Email protected] ~]# ifup eth0:0
3. Configure the VIP on the lo of the Web server
[[email protected] ~]# cp/etc/sysconfig/network-scripts/ifcfg-lo{,:0}
[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-lo:0
device=lo:0
ipaddr=192.168.4.100
netmask=255.255.255.255
network=192.168.4.100
broadcast=192.168.4.100
Onboot=yes
name=lo:0
[Email protected] ~]# ifup lo:0
4. Modify kernel parameters on the Web server
[Email protected] ~]# Sysctl-a | grep Arp_ig
[Email protected] ~]# echo "Net.ipv4.conf.all.arp_ignore = 1" >>/etc/sysctl.conf
[Email protected] ~]# echo "Net.ipv4.conf.lo.arp_ignore = 1" >>/etc/sysctl.conf
[Email protected] ~]# Sysctl-a | grep Arp_ann
[Email protected] ~]# echo "net.ipv4.conf.all.arp_announce = 2" >>/etc/sysctl.conf
[Email protected] ~]# echo "net.ipv4.conf.lo.arp_announce = 2" >>/etc/sysctl.conf
5. Configuration Rules
[[email protected] ~]# ipvsadm-a-T 192.168.4.100:80-s LC
[Email protected] ~]# ipvsadm-a-t 192.168.4.100:80-r 192.168.4.3
[Email protected] ~]# ipvsadm-a-t 192.168.4.100:80-r 192.168.4.2-g

6. Ipvsadm Service
If an error occurs when you start the Ipvsadm service,
[Email protected] ~]# ipvsadm-save-n >/etc/sysconfig/ipvsadm
And then control the service state normally.
[Email protected] ~]# systemctl restart Ipvsadm
[Email protected] ~]# Systemctl enable Ipvsadm

Writing a service monitoring script on vh04
[Email protected] bin]# vim monitor_web.sh
Vip=192.168.4.100:80
rip1=192.168.4.2
rip2=192.168.4.3

While [:]
Do
For IP in $RIP 1 $RIP 2
Do
Curl/HTTP/$ip &>/dev/null
Web_health=$?
Ipvsadm-ln | grep $ip &>/dev/null
Web_in_lvs=$?
If [$web _health-ne 0-a $web _in_lvs-eq 0]; Then
Ipvsadm-d-T $VIP-R $IP
elif [$web _health-eq 0-a $web _in_lvs-ne 0]; Then
Ipvsadm-a-T $VIP-R $IP
Fi
Done
Sleep 3
Done

When validating, you can view the rules every second
[Email protected] bin]# watch-n1 IPVSADM-LN

Lvs:linux virtual Server, Lvs-nat mode +lvs-dr mode

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.