Recently the amateur tried to configure the next Keepalived+lvs, followed by the online configuration, found that the final can run, but not access to the service behind, view a lot of information, now put the specific configuration to paste out for everyone's reference.
Lvs-drConfiguration
Environment:
4 Linux virtual machines (kernel supports LVS)
vip:192.168.1.100 ( master ) corresponding machine IP : 192.168.1.16
Vip:192.168.1.100 ( from ) corresponding machine IP : 192.168.1.11
rip:192.168.1.8 (Tomcat service )
rip:192.168.1.9 (Tomcat service )
Install the relevant software:
Ipvsadm (192.168.1.16,192.168.1.11)
Keepalived (192.168.1.16,192.168.1.11)
Tomcat (192.168.1.8)
Tomcat (192.168.1.9)
Specific configuration script:
Master VIP Configuration:
! Configuration File for Keepalived Global_defs { Notification_email { [Email protected] } Notification_email_from [email protected] Smtp_server smtp.exmail.qq.com Smtp_connect_timeout 30 router_id Lvs_devel } Vrrp_instance Vi_1 { State MASTER Interface eth0 VIRTUAL_ROUTER_ID 51 Priority 100 Advert_int 1 Authentication { Auth_type PASS Auth_pass 123456 } virtual_ipaddress { 192.168.1.100 } } Virtual_server 192.168.1.100 8080 { Delay_loop 6 Lb_algo RR Lb_kind DR Nat_mask 255.255.255.255 Persistence_timeout 1 Protocol TCP Real_server 192.168.1.8 8080 { Weight 1 Http_get { URL { path/test/jsp/2.jsp Digest c2b63159e701960a9eef44a302b56074 } Connect_timeout 3 Nb_get_retry 3 Delay_before_retry 3 } } Real_server 192.168.1.9 8080 { Weight 1 Http_get { URL { path/test/jsp/2.jsp Digest c2b63159e701960a9eef44a302b56074 } Connect_timeout 3 Nb_get_retry 3 Delay_before_retry 3 } } } |
Note: Here the Digest algorithm, it is best to use the Genhash tool to do the calculation, specific use can go online check.
from VIP Configuration
! Configuration File for Keepalived Global_defs { Notification_email { [Email protected] } Notification_email_from [email protected] Smtp_server smtp.exmail.qq.com Smtp_connect_timeout 30 router_id Lvs_devel } Vrrp_instance Vi_1 { State BACKUP Interface eth0 VIRTUAL_ROUTER_ID 51 Priority 40 Advert_int 1 Authentication { Auth_type PASS Auth_pass 123456 } virtual_ipaddress { 192.168.1.100 } } Virtual_server 192.168.1.100 8080 { Delay_loop 6 Lb_algo RR Lb_kind DR Nat_mask 255.255.255.255 Persistence_timeout 1 Protocol TCP Real_server 192.168.1.8 8080 { Weight 1 Http_get { URL { path/test/jsp/2.jsp Digest c2b63159e701960a9eef44a302b56074 } Connect_timeout 3 Nb_get_retry 3 Delay_before_retry 3 } } Real_server 192.168.1.9 8080 { Weight 1 Http_get { URL { path/test/jsp/2.jsp Digest c2b63159e701960a9eef44a302b56074 } Connect_timeout 3 Nb_get_retry 3 Delay_before_retry 3 } } } |
when configured well After the VIP, in order to support the corresponding VIP route on the real server , we need torun some content on the real server (here refers to 192.168.1.8,192.168.1.9):
#!/bin/bash vip=192.168.1.100 Ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up Route add–host $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 |
In order to differentiate keepalived, it is best to simply write a webpage and put it under Tomcat for access.
start all the services. Now try to see if you can access the ^_^.
to understand the functionality of keepalived, you can test the following scenarios:
stop one of the real services and see if the LVs will work properly
Stop the main VIPto see if the VIP can take over to reach high availability
start the main VIP, see if the Lord will follow the VIP to seize
Operation Result:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/4B/wKiom1XKtCnhPl3IAADEKJB4SU4586.jpg "title=" 1.png " alt= "Wkiom1xktcnhpl3iaadekjb4su4586.jpg"/>
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/71/4B/wKiom1XKtTjwu39cAAHYW_sZkH0147.jpg "title=" 2.png " alt= "Wkiom1xkttjwu39caahyw_szkh0147.jpg"/>
This article is from the "Java" blog, so be sure to keep this source http://zwbjava.blog.51cto.com/2789897/1683912
KEEPALIVE+LVS-DR Configuration