1. System Environment
Centos6.5
LVS + keepalived (master)
LVS + keepalived (slave)
Nginx (Real-server)
Nginx (Real-server)
Ii. LVS Introduction
LVS is short for Linux virtual server, which is a virtual server cluster system. The main function of a virtual server is to provide packet forwarding and load balancing. This function can be implemented through ipvsadm. IP Server Load balancer technologies include VS/NAT, VS/DR, and VS/tun. This document introduces the Dr mode.
Iii. keepalive Introduction
Keepalived is an open-source software that enables high availability. High Availability means that it is always online and can prevent single point of failure (spof) of services. It is based on vrrp (Virtual routing redundancy protocol) to achieve high availability.
Vrrp is a master-slave protocol designed to eliminate network failures caused by a single point of failure on the default router in a static default routing environment, in this way, device function switching in case of a fault does not affect internal and external data communication, and you do not need to modify the network parameters of the internal network. The vrrp protocol must have IP address backup, and the routes are prioritized. Select to reduce unnecessary functions such as inter-router communication.
Vrrp virtualizes two or more router devices into one device and provides one or more vroip IP addresses, if the router that actually owns the external IP address works normally, it is the master node, or it is generated through algorithm election. The master node implements various network functions for the virtual router IP address, such as ARP requests, ICMP, and data forwarding. Other devices do not have this IP address and the status is backup. In addition to receiving vrrp status notifications from the master, they do not perform external network functions. When the host fails, backup takes over the network function of the original master.
Iv. Installation
1. Install LVS
Since Linux kernel version 2.6, ip_vs code has been integrated into the kernel. Therefore, as long as you select ipvs during kernel compilation, Linux supports LVS. Kernel Versions later than Linux 2.4.23 also integrate ip_vs Code. However, if you use an older kernel version, you must manually integrate ip_vs code into the original kernel code, and re-compile the kernel to use LVS.
# Yum install-y ipvsadm
2 install keepalived
# Tar zxf keepalived-1.1.17.tar.gz
# Cd keepalived-1.1.17
#./Configure
# Make & make install
# Cp/usr/local/etc/rc. d/init. d/keepalived/etc/rc. d/init. d/
# Cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
# Mkdir-P/etc/keepalived
# Cp/usr/local/etc/keepalived. CONF/etc/keepalived/
# Cp/usr/local/sbin/keepalived/usr/sbin/
#/Etc/init. d/keepalived start
Keepalived starts three processes.
V. Configuration File
! Configuration file for example {icationication_email {[email protected]} configure [email protected] smtp_server localhost route 30 router_id lvs_devel} configure vg1 {Group {vi_1 vi_2 vi_3 vi_4} vrrp_instance vi_1 {state master # status, slave is backup interface eth0 virtual_router_id 71 priority 102 #102 on Master, 100 on backup advert_int 3 smtp_alert authentication {auth_type pass auth_pass password} virtual_ipaddress {192.168.1.30 }## nginx vipvirtual_server 192.168.1.30 80 {delay_loop 6 # Health Check Interval lb_algo wlc # load balancing algorithm, weighted Least connection lb_kind Dr # Server Load balancer technology Dr persistence_timeout 7 # session persistence 7 s protocol TCP # forwarding protocol real_server 192.168.1.40 80 {weight 1 # weight tcp_check {connect_timeout 7 # connection timeout}} real_server 192.168.1.41 80 {weight 4 tcp_check {connect_timeout 7 }}}
Vi. RealServer VIP settings
# Vim/etc/sysctl. conf
Net. ipv4.conf. Lo. arp_ignore = 1
Net. ipv4.conf. Lo. arp_announce = 2
Net. ipv4.conf. All. arp_ignore = 1
Net. ipv4.conf. All. arp_announce = 2
# Vim/etc/sysconfig/network-scripts/ifcfg-Lo: 1
Device = lo: 1
Name = loopback1
Ipaddr = 192.168.1.30 # VIP
Netmask = 255.255.255.255.255
Onboot = Yes
~ # Service network restart
# View ifconfig Verification
This article is from the blog of the "Bremen band" and will not be reposted!