VMware-based virtual Linux cluster setup-lvs + keepalived,-lvskeepalived

Source: Internet
Author: User
Tags virtual environment

VMware-based virtual Linux cluster setup-lvs + keepalived,-lvskeepalived
Build a virtual Linux cluster based on VMware-lvs + keepalived this article uses keepalived to achieve load balancing between the dual-machine hot backup of the lvs server and the Real Server. There are many blogs in this regard, but the environments for each person to build a cluster are different and the problems they encounter are also different. This article describes some of the configuration processes and the solutions for problems encountered during the configuration process. Quasi-work 1. create a Linux virtual machine this article is based on the Vmare virtual environment to build a cluster, so first create some virtual machines in Vmare (install a Linux system, other copies can be installed for the first time ), this document creates four virtual machines. The NIC mode is set to the bridging mode, which ensures that the network and Host IP address in the virtual machine are in the same network segment. The advantage is that after the IP address is set for each virtual machine, you can log on to Linux using another host in the same CIDR block without switching back and forth between virtual machines. (CentOS 5.5 for Linux) 2. Configure the yum Library

If the local machine does not have the yum library, it is best to configure and install the yum library to facilitate software installation.

Basic Steps for creating a yum Library

① Install createrepo

② Yum-y installl createrepo

③ Create with createrepo

The createrepo command is used to generate some basic configuration information required by the yum repository.

For more information, see "install and configure the yum library"


Cluster configuration 1. Set the Virtual Machine IP Address

Virtualize four Linux Hosts in the Vmare Virtual Machine

LvsMaster: 192.168.10.101

Lvsbsk: 192.168.10.102

RealServer1: 192.168.10.121

RealServer2: 192.168.10.122



Topological Relationship Diagram Between Hosts


2. Install ipvsadm and keepalived ① install ipvsadm on LvsMaster and lvsbach respectively.

Yum-y install * ipvsadm *

: Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar

② Keepalived is installed on LvsMaster and lvsbach respectively.

Install the dependency Library: yum install-y openssl-devel

Download keepalived: wget http://www.keepalived.org/software/keepalived-1.2.6.tar.gz

Tar zxvf keepalived-1.2.6.tar.gz
./Configure -- prefix =/usr/local/keepalived
Make
Make install
Cp/usr/local/keepalived/sbin/keepalived/usr/sbin/
Cp/usr/local/keepalived/etc/sysconfig/
Cp/usr/local/keepalived/etc/rc. d/init. d/keepalived/etc/init. d/
Mkdir/etc/keepalived

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

③ Configure keepalived

LvsMaster Configuration

Global_defs {
Notification_email {
540621626@qq.com # emial notification
}
Notification_email_from 540621626@qq.com
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_sync_group test {# Set vrrp Group
Group {
Loadbalance
}
}
Vrrp_instance loadbalance {
State MASTER # Set the host type, MASTER and BACKUP, which must be capitalized, that is, a BACKUP host is too large.
Interface eth0 # Set the external service Nic
Virtual_router_id 51
Priority 100 # set priority. The priority of the standby host is lower than that of the host.
Advert_int 1 # Set the synchronization interval
Authentication {# Set the authentication type and password
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {# Set a virtual ip address, that is, a floating ip address.
192.168.10.115
}

Virtual_server 192.168.10.115 80 {
Delay_loop 6 # Health Check Interval
Lb_algo rr # load scheduling algorithm, which is a rotation algorithm by default
Lb_kind DR # Server Load balancer forwarding rules, that is, IP Forwarding rules. The DR forwarding method is the fastest, but all machines must be in the same network segment, and there are two forwarding Methods: NAT and KNN.
Protocol TCP

Real_server 192.168.10.121 80 {
Weight 1
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Real_server 192.168.10.122 80 {
Weight 1
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

}


Lvsbkr Configuration

Global_defs {
Notification_email {
540621626@qqq.com
}
Notification_email_from 540621626@qq.com
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}

Vrrp_sync_group test {
Group {
Loadbalance
}
}


Vrrp_instance loadbalance {
State BACKUP
Interface eth0
Virtual_router_id 51
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.168.10.115
}
}

Virtual_server 192.168.10.115 80 {
Delay_loop 6
Lb_algo rr
Lb_kind DR
Protocol TCP

Real_server 192.168.10.121 80 {
Weight 1
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}

Real_server 192.168.10.122 80 {
Weight 1
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}

④ Start keepalived

LvsMastrer:/etc/init. d/keepalived start

Lvsback:/etc/init. d/keepalived start

View startup status

LvsMaster: tail-f/var/log/messages


Lvsbsk: tail-f/var/log/messages


Use ip addr and ipvsadm to view route information

LvsMaster: ip addr

LvsMaster: ipvsadm

Lvsbsk: ip addr

Lvsback: ipvsadm

3. Set RealServer1 and RealServer2 ① to edit the RealServe scripts RealServer1 and ResalServer2, both of which are realserver. sh. The setting script is as follows: SNS_VIP = 192.168.10.115
Source/etc/rc. d/init. d/functions
Case "$1" in
Start)
Ifconfig lo: 0 $ SNS_VIP netmask 255.255.255.255 broadcast $ SNS_VIP up
/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
Exit 0 After the script is edited, start realserver. sh.
RealServer1:./realserver. sh startRealServer2:./realserver. sh start View IP② Install apache on RealServer1 and RealServer2 InstallYum-y install httpd ConfigurationServerName www. example. comNameVirtualHost 192.168.10.121: 80 <VirtualHost 192.168.10.121: 80>
DocumentRoot/var/www/html
ServerName www.example.com
</VirtualHost>
On the homepage of index.html testing under/var/www/hmtl /, Start apache:/etc/init. d/httpd start 4. Test Server Load balancer and dual-host hot standby Use ipvsadm to view the routes of LvsMaster and lvsback
LvsMaster: ipvsadm L VsBak: ipvsadm

5. precautions during configuration Zookeeper ① precautions for keepalvied ConfigurationLvsMaster and lvsback have only two different state masters | BACKUP (MASTER Lvs and slave Lv are BACKUP)
Priority 100 | 90 (the main Lvs is 100, and the standby LVS is smaller than 100)

② Disable iptables or enable the corresponding service port. Otherwise, the service cannot be accessed through a browser.

For linux Clusters, nginx, lvs, and keepalived, how can we choose to achieve load balancing?

Khan, let's take a look at what nginx, lvs, and keepalived are doing.
The cluster does not connect machines to a cluster ..

How to configure Master/Slave for LVS + keepalived?

This server Load balancer and high availability solution have many principles and many application scenarios. You must consider the actual situation.
Take ubuntu as an example (RHEL and centos are similar)
If you are worried about being filtered by Baidu, you have to make an image. Pay attention to the number of rows. Delete duplicate entries. text content will not be duplicated and sent offline to you.


Reference: man 5 keepalived. conf


Related Article

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.