CentOS5.5 build an LVS Environment

Source: Internet
Author: User

CentOS5.5 build an LVS Environment

CentOS5.5 + LVS (Master + Slave) + 2 WEB,

The Web page is configured in advance to distinguish which real machine is assigned,

Firewall and selinux are disabled before the experiment.

1. Download related software packages
# Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
# Wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz

2. Install LVS and Keepalived

# Lsmod | grep ip_vs
# Uname-r

2.6.18-274.17.1.el5xen

# Tar zxvf ipvsadm-1.24.tar.gz

# Cd ipvsadm-1.24
# Make & make install

# Tar zxvf keepalived-1.1.15.tar.gz

# Cd keepalived-1.1.15

#./Configure-prefix =/usr/local/keepalived-with-kernel-dir =/usr/src/linux/

# Make & make install

# Cp/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/rc. d/init. d/

# Cp/usr/local/keepalived/etc/sysconfig/

# Mkdir/etc/keepalived

# Cp/usr/local/keepalived/etc/keepalived. conf/etc/keepalived/

# Cp/usr/local/keepalived/sbin/keepalived/usr/sbin/

#/Etc/init. d/keepalived start

Startingkeepalived: [OK]

3. Configure keepalived. conf as follows:

Master machine Configuration:

# VIP1

Vrrp_instance VI_1 {

StateBACKUP

# Lvs_sync_daemon_interface eth1

Nopreempt

Interfaceeth0

Virtual_router_id 62

Priority100 # change 100 to 99 on the backup service

Advert_int3

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.168.2.228/16 brd 192.168.255.255 deveth0 label eth0: 0 ### bt web vip

}

}

Virtual_server 192.168.2.228 80 {

Delay_loop6 # (query realserver status every 10 seconds)

Lb_algowrr # (lvs algorithm)

Lb_kindDR # (Direct Route)

Persistence_timeout 60 # (connections from the same IP address are allocated to the same realserver within 60 seconds)

Inhibit_on_failure

ProtocolTCP # (use the TCP protocol to check the realserver status)

Real_server192.168.2.184 80 {

Weight10

Notify_down "/root/bin/notify_mail.sh btweb01194252.184 ″

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

Real_server192.168.2.199 80 {

Weight 10

Notify_down "/root/bin/notify_mail.sh btweb02 192.168.2.199 ″

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}

Slave machine Configuration:

# VIP1

Vrrp_instance VI_1 {

StateBACKUP # change MASTER to BACKUP on the BACKUP server

# Lvs_sync_daemon_interface eth1

Nopreempt

Interfaceeth0

Virtual_router_id62

Priority100 # change 100 to 99 on the backup service

Advert_int3

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.168.2.228/16 brd 192.168.255.255 dev eth0 label eth0: 0 ### btweb vip

}

}

Virtual_server 192.168.2.228 80 {

Delay_loop6 # (query realserver status every 10 seconds)

Lb_algowrr # (lvs algorithm)

Lb_kindDR # (Direct Route)

Persistence_timeout 60 # (connections from the same IP address are allocated to the same realserver within 60 seconds)

Inhibit_on_failure

ProtocolTCP # (use the TCP protocol to check the realserver status)

Real_server192.168.2.184 80 {

Weight10

Notify_down "/root/bin/notify_mail.sh btweb01 192.168.2.184 ″

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

Real_server192.168.2.199 80 {

Weight10

Notify_down "/root/bin/notify_mail.sh btweb02 192.168.2.199 ″

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 80

}

}

}

5. real machine configuration

[Root @ vm02 ~] # More lvs_real.sh

#! /Bin/bash

SNS_VIP = 192.168.2.228

./Etc/rc. d/init. d/functions

Case "$1" in

Start)

Ifconfig lo: 0 $ SNS_VIP netmask 255.255.255.255 broadcast $ SNS_VIP

/Sbin/route add-host $ SNS_VIP dev lo: 0

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

Sysctl-p>/dev/null 2> & 1

Echo "RealServer Start OK"

;;

Stop)

Ifconfig lo: 0 down

Route del $ SNS_VIP>/dev/null 2> & 1

Echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore

Echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce

Echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore

Echo "0">/proc/sys/net/ipv4/conf/all/arp_announce

Echo "RealServer Stoped"

;;

*)

Echo "Usage: $0 {start | stop }"

Exit 1

Esac

Exit0

6. Test

[Root @ test1 ~] # Ipvsadm-Ln

IP Virtual Server version 1.2.1 (size = 4096)

Prot LocalAddress: Port sched1_flags

-> RemoteAddress: Port Forward Weight ActiveConn InActConn

TCP 192.168.2.228: 80 wrr persistent 60

-> 192.168.2.184: 80 Route 10 0 0

-> 192.168.2.199: 80 Route 10 0 5

Disable the realserver machine:

Ipvsadm-d-t 192.168.2.228: 80-r192.168.2.199: 80

Enable the realserver machine:

Ipvsadm-a-t 192.168.2.228: 80-r192.168.2.199: 80

1. Turn off any web or nginx and the webpage can be accessed normally.

2. Disable any lvs and the webpage can be accessed normally.

Verify that the experiment is successful.

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.