First, environmental description:
Operating system: centos-6.5_x86_64
The Keepalived software is installed on the Node2 and Node3 machines.
close the firewall on the keepalived node (NODE2,NODE3) before you actually install it.
[[Email protected] ~]# service iptables stop
Second, Software Installation:
The software that needs to be installed here is keepalived. Both Node2 and node3 need to be installed.
Yum Install keepalived
After the installation is complete, the configuration file is under/etc/keepalived/keepalived.conf.
Third, the configuration file:
1. master configuration file (Node2):
! Configuration File forKeepalivedbal_defs {notification_email {[email protected]} Notification_email_from [email protected] s Mtp_server127.0.0.1Smtp_connect_timeout -router_id lvs_devel}vrrp_instance vi_1 {State MASTER interface eth0 virtual_router_idWuyi Priority -Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.103.100/ -Dev eth0 label eth0:1}}virtual_server192.168.103.100 the{Delay_loop6Lb_algo wrr lb_kind DR nat_mask255.255.255.0Persistence_timeout -protocol TCP Real_server192.168.103.101 the{weight1http_get {url {path/Status_code $} connect_timeout3Nb_get_retry3Delay_before_retry3}} real_server192.168.103.105 the{weight1http_get {url {path/Status_code $} connect_timeout3Nb_get_retry3Delay_before_retry3 } }}
2. Backup configuration file (NODE3):
! Configuration File forKeepalivedbal_defs {notification_email {[email protected]} Notification_email_from [email protected] s Mtp_server127.0.0.1Smtp_connect_timeout -router_id lvs_devel}vrrp_instance vi_1 {State BACKUP interface eth0 virtual_router_idWuyi Priority -Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.103.100/ -Dev eth0 label eth0:1}}virtual_server192.168.103.100 the{Delay_loop6Lb_algo wrr lb_kind DR nat_mask255.255.255.0Persistence_timeout -protocol TCP Real_server192.168.103.101 the{weight1http_get {url {path/Status_code $} connect_timeout3Nb_get_retry3Delay_before_retry3}} real_server192.168.103.105 the{weight1http_get {url {path/Status_code $} connect_timeout3Nb_get_retry3Delay_before_retry3 } }}
Iv. test: 1. First, start the keepalived service on Node2 and NODE3 respectively:
[[Email protected] ~~]# Service keepalived start
Log generated at startup in the/var/log/messages file, you can observe the logs in it. The master effect is as follows: Backup will be slightly different.
2. View the status in Node2 (MASTER):
[Email protected] ~]#ifconfigeth0 Link encap:ethernet HWaddrxx: 0C: in: CE: .:D 7 inet addr:192.168.103.102Bcast:192.168.103.255Mask:255.255.255.0Inet6 Addr:fe80::20c:29ff:fece:6d7/ -scope:link up broadcast RUNNING multicast MTU: theMetric:1RX Packets:11485Errors0Dropped0Overruns:0Frame0TX Packets:33202Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen: +RX Bytes:2217383(2.1MiB) TX Bytes:2537512(2.4MiB) eth0:1Link encap:ethernet HWaddrxx: 0C: in: CE: .:D 7 inet addr:192.168.103.100Bcast:0.0.0.0Mask:255.255.255.0Up broadcast RUNNING multicast MTU: theMetric:1lo Link encap:local Loopback inet addr:127.0.0.1Mask:255.0.0.0Inet6 Addr: ::1/ -scope:host up LOOPBACK RUNNING MTU:16436Metric:1RX Packets:0Errors0Dropped0Overruns:0Frame0TX Packets:0Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen:0RX Bytes:0(0.0b) TX Bytes:0(0.0b
[Email protected] ~]# Ipvsadm-lnip Virtual Server version1.2.1(size=4096) Prot localaddress:port Scheduler Flags-remoteaddress:port Forward Weight activeconn inactconntcp192.168.103.100: theWRR Persistent --192.168.103.101: theRoute1 0 0-192.168.103.105: theRoute1 0 0
You can see that the NIC in master is enabled.
3. Check the status on Backup (NODE3):
[Email protected] keepalived]#ifconfigeth0 Link encap:ethernet HWaddrxx: 0C: in: BE:D3:CA inet Addr:192.168.103.103Bcast:192.168.103.255Mask:255.255.255.0Inet6 Addr:fe80::20c:29ff:febe:d3ca/ -scope:link up broadcast RUNNING multicast MTU: theMetric:1RX Packets:249981Errors0Dropped0Overruns:0Frame0TX Packets:72173Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen: +RX Bytes:284573915(271.3MiB) TX Bytes:5287459(5.0MiB) Lo Link encap:local Loopback inet addr:127.0.0.1Mask:255.0.0.0Inet6 Addr: ::1/ -scope:host up LOOPBACK RUNNING MTU:16436Metric:1RX Packets:1898Errors0Dropped0Overruns:0Frame0TX Packets:1898Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen:0RX Bytes:229406(224.0KiB) TX Bytes:229406(224.0KiB)
[Email protected] keepalived]# Ipvsadm-lnip Virtual Server version1.2.1(size=4096) Prot localaddress:port Scheduler Flags-remoteaddress:port Forward Weight activeconn inactconntcp192.168.103.100: theWRR Persistent --192.168.103.101: theRoute1 0 0-192.168.103.105: theRoute1 0 0
If the NODE3 does not turn off the firewall, the ETH0:1 network card is also enabled, so be careful to shut down the firewall.
Linux under KEEPALIVED+LVS-DR mode configuration high availability load Balancer cluster