Tag: IP Address server server virtual machine equalizer
Function:
Lvs+keepalived in a high-availability load-balancing cluster:
· Keepalived is responsible for back-end real server Health Check
If a real server service fails, it is removed from the Cluster service, and then automatically joined to the cluster after recovery.
· Keepalived is responsible for high availability of the load Balancer (directory server)
A and B virtual machines installed lvs+keepalived (master) and lvs+keepalived (prepared), but the external performance as a virtual IP, the primary server will send a message to the standby server, when the standby server received the message, the host is considered to be faulty, and then take over the virtual IP continue to provide services If the primary node resumes, the virtual IP is taken over again to provide the service.
Principle:
· When working with Layer3, Keepalived sends ICMP packets to the server group periodically, and if a server IP address is not activated, it is considered invalid and rejected (a typical example is that the server was illegally shut down)
· When working with LAYER4, such as Web 80 port load Balancing, keepalived detects that 80 ports in the back-end server group are not started, and if not, it is considered invalid and rejected
· When working with Layer7, according to user's settings, if the user does not match the set, it is considered invalid and rejected
Three modules:
· Core: Responsible for initiating and maintaining the main process, loading and parsing of global configuration files
· Health_check: Load health status check
· VRRP: Implementing the VRRP protocol
Experiment:
• The master node and the standby node start the keepalived, Web1 and web2 start httpd,
Architecture Design:
use keepalived to achieve high availability of the LVS directory server, and then utilize the high availability of LVS and keepalived to achieve load balancing of Web Services! The architecture diagram is as follows
650) this.width=650; "src=" Http://img1.51cto.com/attachment/201305/16/6466723_1368679018UowU.png "width=" 640 " height= "454" alt= "6466723_1368679018uowu.png"/>
The keepalived in this article is to detect the health state of real server and the failover between the primary and standby of the load balancer.
Detect Real Server Health: If a Web server goes down or fails, keepalived is detected and removed from the cluster group, and then automatically added after recovery.
Load balancer Failover: A Web server requires at least two keepalived, a primary node (master), a standby node (backup), but externally represented as a virtual IP, the primary server sends multicast, If the standby server fails to receive the VRRP packet, it will take over the virtual IP and continue to provide services to ensure high availability.
Build:
Focus Time Synchronization
Each node can parse each other
(1) Preparation environment
1. The main and standby nodes are loaded with LVS and keepalived
2.web1 and WEB2 are all loaded httpd
3. Turn off the firewall
4. Turn off SELinux
5.web1 and Web2 both have to suppress ARP.
(2) Master node
Install Ipvsadm and keepalived yum-y install keepalived ipvsadm shut down Firewall service iptables stop shutdown SELinux Setenforce 0
Modify the keepalived configuration file vim/etc/keepalived/keepalived.conf
vrrp_instance vi_1 { state master #备用服务器上为 BACKUP interface eth0 virtual_router_id 51 priority 100 #备用服务器上为90 advert_int 1 authentication { auth_type pass auth_pass 1111 } virtual_ipaddress { 172.16.7.5 }}virtual_server 172.16.7.5 80 { delay_loop 6 #每隔6秒查询realserver状态  &Nbsp; lb_algo wrr #lvs Algorithms lb_kind DR #lvs Mode persistence_timeout 60 # Connection of the same IP is assigned to the same realserver protocol tcp within 60 seconds #指定转发协议类型 with two real_ of TCP and UDP server 172.16.7.3 80 { weight 3 #权重 TCP_CHECK { Connect_timeout 3 #表示3秒无响应, the timeout nb_get_ retry 3 #表示重试次数 delay_before_retry 3 #表示重试间隔 connect_port 80 #端口为80 } }real_ server 172.16.7.4 80 { weight 1 tcp_check { connect_ timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } }}
(3) Standby node
Install Ipvsadm and keepalived yum-y install keepalived ipvsadm shut down Firewall service iptables stop shutdown SELinux Setenforce 0
Modify the keepalived configuration file vim/etc/keepalived/keepalived.conf
You only need to change two places:
The "state MASTER" is modified to "state BACKUP"
No.2 "Priority 100" changed to "Priority 99"
(4) Web1 and WEB2
Install Ipvsadm and Keepalived yum -y install keepalived ipvsadm shut down the firewall service iptables stop Close selinux setenforce 0 installation httpd       YUM -Y INSTALL HTTPD Inhibition of arp echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore echo 1 >/proc/sys/net/ipv4/conf/eth0/arp_ignore Add vip ifconfig lo:0 192.168.1.10 broadcast 192.168.1.10 netmask 255.255.255.255 adding Routes route add -host 192.168.1.10 dev lo:0
Test
Test Health Check: Master node and standby node start Keepalived,web1 and web2 start httpd, view Ipvs rule on master node, can see WEB1 and web2,ip Addr View Master node VIP, stop web1 httpd service, See Ipvs rule again on master node, Web1 rule disappears, test successful
Test failover: Master node and standby node start Keepalived,web1 and WEB2 start httpd. Stop keepalived on the master node, see if the standby node takes over the VIP, continue to provide Web services, and if so, test successfully
Test failure recovery: The primary node fails, the keepalived fails to stop, the standby node takes over the VIP and continues to provide Web services. If the primary node resumes, restart the keepalived, and see if the VIP is drifting back, the master node takes over the standby node service and continues to serve.
LVS Dr Mode +keepalived enables directory high availability, HTTPD service load Balancing clusters