I. lab environment requirements and preparation
As shown in an architecture to be completed in this experiment, we use LVS-DR-MASTER, LVS-DR-BACKUP as The LVS Load Balancing scheduler, and keepalived between the two for HA. Keepalived is developed for LVS. Therefore, it is very convenient to configure LVS through keepalived. In addition, keepalived directly operates ip_vs without using ipvsadm, so it is more convenient.
1) experiment architecture diagram & demand table:
650) This. width = 650; "style =" border-bottom: 0px solid; border-left: 0px solid; margin: 0px; width: pixel PX; Height: 306px; border-top: 0px solid; border-Right: 0px solid; "Title =" lvs?keepalived=fig. PNG "alt =" wkiom1lvc6lwkwadaagyy4ob04w803.jpg "src =" http://www.it165.net/uploadfile/files/2014/0115/201401150845551.jpg "/>
Role |
IP address |
Remarks |
Master LVS scheduler (master) |
192.168.41.181 |
Use keepalived Configuration |
Backup LVS Scheduler) |
192.168.41.20. |
|
HTTP server (RS1) |
192.168.41.31 |
Apache server (generally, the production environment requires an Internet IP address, which is replaced by an intranet IP address) |
HTTP server (rs2) |
192.168.41.33 |
|
Virtual IP address (VIP) |
192.168.41.249 |
Virtual IP Address |
2) Deploy the HTTP server to verify normal access
There is not much space to introduce here, that is, to ensure that HTTP can be accessed normally.
Ii. Configure keepalived for load balancing and high availability
Install LVS first
Command Yum-y intall ipvsadm
Ipvsadm -- help can be used to test whether the installation is successful.
[[Email protected] keepalived] # lsmod ip_vs check whether the module is successfully loaded
Usage: lsmod
Use modprobe ip_vs to mount the module
[[Email protected] keepalived] # Save service protected SADM
Ipvsadm: Saving ipvs table to/etc/sysconfig/ipvsadm: [OK]
1) install keepalived Software
Wget http://www.keepalived.org/software/keepalived-1.2.8.tar.gz
Tar-zxf keepalived-1.2.8.tar.gz
CD keepalived-1.2.8
./Configure -- prefix =/usr/local/keepalived
At this time, we will report that you can install the plug-in yum. Just install Yum install GCC.
Make
Always Prompt during compilation
Make: *** no targets specified and no makefile found. Stop.
I also want to install ncurses-5.6.tar.gz.
1. wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
2. Tar zxvf ncurses-5.6.tar.gz
3../configure-Prefix =/usr/local-with-shared-without-Debug
4. Make
5. Make install
Later, I realized that I had installed things when I was in./configure.
650) This. width = 650; "Title =" 1.png" src = "http://s3.51cto.com/wyfs02/M00/4C/68/wKiom1Q8y_Ggf_F6AAJVXZWA04M039.jpg" alt = "wkiom1q8y_ggf_f6aajvxzwa04m039.jpg"/>
Solution
Yum install-y OpenSSL-devel
Next, we will report that the shared library is not installed.
650) This. width = 650; "Title =" 1.png" src = "http://s3.51cto.com/wyfs02/M00/4C/69/wKioL1Q8zoOS1Lk1AALA8WvTgXg650.jpg" alt = "wkiol1q8zoos1lk1aala8wvtgxg650.jpg"/>
Yum install popt-devel
Next we will install
650) This. width = 650; "Title =" 1.png" src = "http://s3.51cto.com/wyfs02/M00/4C/6A/wKioL1Q8z9-w1LqOAAJz8qEaAIk222.jpg" alt = "wKioL1Q8z9-w1LqOAAJz8qEaAIk222.jpg"/>
If this is no, LVS and keeplived are not associated successfully. You can see that my association has been added, but I will teach you how to do so.
Ln-S/usr/src/kernels/kernel version/usr/src/Linx
Then we use make-J4 to compile at 4 CPUs.
Make install
# Set keepalived to a service
CD/usr/local/keepalived/
CP etc/rc. d/init. d/keepalived/etc/rc
CP etc/rc. d/init. d/keepalived/etc/rc. d/init. d/
Cp etc/sysconfig/keepalived/etc/sysconfig/
Mkdir/etc/keepalived
Cp etc/keepalived. CONF/etc/keepalived/
CP sbin/keepalived/usr/sbin/
# Enable the kernel forwarding function
VI/etc/sysctl net. ipv4.ip _ forword = 1
Sysctl-P does not take effect after restart
CD/etc/keepalived/
2) configure the keepalived. conf configuration file for the LVS-DR-MASK
! Configuration file for keepalived Global_defs { Notification_email { [Email protected] # Set the alarm email address. Generally, you do not need to set this email address. Instead, you can use other methods to generate an alarm. } Notification_email_from [email protected] # Set the email sending Address Smtp_server 127.0.0.1 # Set the email sending server Smtp_connect_timeout 30 # Set SMTP connection timeout Router_id lvs_181 # Server Load balancer ID, which is unique within the LAN } Vrrp_instance vi_1 {# define a virtual route instance. Different instance IDs are different. State master # define the role of the server in keepalived master server Interface eth0 # define the port eth0 for Detection Virtual_router_id 51 # defines the virtual route ID, which is the same as the master and slave nodes of the same instance. Priority 100 # permission defined in the vro group, the higher Advert_int 1 # define the detection Interval Authentication {# define the Authentication mode password. The master and slave must be the same Auth_type pass Auth_pass 1111 } Virtual_ipaddress {# specify the virtual IP Address 192.168.41.249 } } Virtual_server 192.168.41.249 80 {# defines virtual services. You must specify an IP address and a port separated by spaces. Delay_loop 6 # define the RS runtime monitoring interval Lb_algo RR # defines the Load Scheduling Algorithm Lb_kind Dr # define the LVS Working Mode Nat_mask limit 255.255.0 # define the virtual service's mask Persistence_timeout 50 # defines the session persistence time, in seconds Protocol TCP # specify the forwarding Protocol Real_server 192.168.41.31 80 {# define the Real Server IP address and port Weight 1 # define the RS weight Tcp_check {# Rs server Health Check Section Connect_timeout 10 # define a connection timeout of 10 s Nb_get_retry 3 # define the number of retries Delay_before_retry 3 # define the Retry Interval Connect_port 80 # define the Health Check Port } Real_server 192.168.41.33 80 { Weight 1 Tcp_check { Connect_timeout 10 Nb_get_retry 3 Delay_before_retry 3 Connect_port 80 } } |
3) configure the keepalived. conf configuration file for the LVS-DR-BACKUP
! Configuration file for keepalived Global_defs { Notification_email { [Email protected] # Set the alarm email address. Generally, you do not need to set this email address. Instead, you can use other methods to generate an alarm. } Notification_email_from [email protected] # Set the email sending Address Smtp_server 127.0.0.1 # Set the email sending server Smtp_connect_timeout 30 # Set SMTP connection timeout Router_id lvs_251 # ID of the Server Load balancer, which is unique in the LAN } Vrrp_instance vi_1 {# define a virtual route instance. Different instance IDs are different. State backup # define the role of the server in keepalived Interface eth0 # define the port eth0 for Detection Virtual_router_id 51 # defines the virtual route ID, which is the same as the master and slave nodes of the same instance. Priority 50 # permission defined in the vro group, the higher Advert_int 1 # define the detection Interval Authentication {# define the Authentication mode password. The master and slave must be the same Auth_type pass Auth_pass 1111 } Virtual_ipaddress {# specify the virtual IP Address 192.168.41.249 } } Virtual_server 192.168.41.249 80 {# defines virtual services. You must specify an IP address and a port separated by spaces. Delay_loop 6 # define the RS runtime monitoring interval Lb_algo RR # defines the Load Scheduling Algorithm Lb_kind Dr # define the LVS Working Mode Nat_mask limit 255.255.0 # define the virtual service's mask Persistence_timeout 50 # defines the session persistence time, in seconds Protocol TCP # specify the forwarding Protocol Real_server 192.168.41.31 80 {# define the Real Server IP address and port Weight 1 # define the RS weight Tcp_check {# Rs server Health Check Section Connect_timeout 10 # define a connection timeout of 10 s Nb_get_retry 3 # define the number of retries Delay_before_retry 3 # define the Retry Interval Connect_port 80 # define the Health Check Port } Real_server 192.168.41.33 80 { Weight 1 Tcp_check { Connect_timeout 10 Nb_get_retry 3 Delay_before_retry 3 Connect_port 80 } |
(Here the main LVS-DR-MASTER and LVS-DR-BACKUP Configuration between the difference is only the red part: Ha role (master, backup) and priority is different, there is router_id.
4) Configure LVS parameters on the client
What the client needs to do is to bind our VIP to the lo port and implement ARP suppression. This method has been mentioned in previous articles. Now we will write the configuration as a script for execution.
Script content:
[[Email protected] ~] # Cat lvs-client.sh #! /Bin/bask # [Email protected] QQ.com # ./Etc/rc. d/init. d/functions VIP = ( 192.168.40.17 ) Function start (){ For (I = 0; I <'echo $ {# VIP [*]} '; I ++ )) Do Echo $ {I }$ {VIP [$ I]} Ifconfig lo: $ {I }$ {VIP [$ I]} netmask 255.255.255.255 up Route add-host $ {VIP [$ I]} Dev Lo Done 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_announce Echo "2">/proc/sys/NET/IPv4/CONF/All/arp_announce } Function stop (){ For (I = 0; I <$ {# VIP [*]}; I ++ )) Do Echo $ {I }$ {VIP [$ I]} Ifconfig lo: $ {I }$ {VIP [$ I]} netmask 255.255.255.255 up Route del-host $ {VIP [$ I]} Dev lo :$ {I} Done } Case "$1" in Start) Start Exit ;; Stop) Stop Exit ;; *) Echo "you must use $0: Stop | start" ;; Esac |
5) test lab results
If the test department is successful, you can troubleshoot the problem based on the triangular troubleshooting principle to check whether the client can communicate with the RS, whether the LB can communicate with the RS, and whether the client can communicate with the lb, whether the client can communicate with the VIP. Check the running status of LVS. Make sure that the configuration file keepalived. conf is correct.
This article is from the "diaosi life" blog and will not be reproduced!
LVS + keepalived for Load Balancing & High Availability