These two days in a detailed look at the man carp document. found that the original carp can not only achieve failover (failover) cluster, through a simple configuration or can be a local LAN load balance.
Carp load Balancing uses the Arpbalance function, which is understood literally as the use of ARP load balancing, that is, the second layer of the OSI7 layer model-the data link layer. Therefore, using arpbalance can only be applied to local LAN, can not achieve a higher level of balance.
The principle is roughly as follows
Two servers A, B, the establishment of two Carp Virtual network card a1, A2, B1, B2, where A1, B1 as a carp group (that is, the same vhid), the remaining two network cards for another carp group. A1 is master,b1 as slave in the first Carp group. In the second Carp group, exactly the opposite, A2 is slave,b2 as master. These two carp groups have the same virtual IP.
So arpbalance can rotate between the two groups. When using the CARP1 group, the A1 is master. So the service is provided by a at this time, and when the CARP2 group is used, the service is provided by B because B2 is master.
At the same time, the rotary algorithm is based on the source IP address hash algorithm to ensure that the same source address by the fixed carp group to provide services, can ensure that the client session and other applications.
The following steps are implemented
Modify the configuration file on Server A
ee/etc/rc.conf #配置rc. conf file, establish CARP virtual network card respectively. Add the following content
cloned_interfaces= "Carp0 Carp1"
ifconfig_carp0= "Vhid 1 advbase 5 pass passwd 192.168.1.100/24"
Ifconfig_carp1= "Vhid 2 advbase 5 Advskew pass passwd 192.168.1.100/24"
Ee/etc/sysctl.conf #修改sysctl文件启用carp的arpbalance和carp抢占功能. Add the following content
Net.inet.carp.preempt=1
Net.inet.carp.arpbalance=1
Modified on Server B is roughly the same, just a little change in the carp NIC
ee/etc/rc.conf #配置rc. conf file, establish CARP virtual network card respectively. Add the following content
cloned_interfaces= "Carp0 Carp1"
ifconfig_carp0= "Vhid 1 advbase 5 Advskew pass passwd 192.168.1.100/24"
Ifconfig_carp1= "Vhid 2 advbase 5 pass passwd 192.168.1.100/24"
Ee/etc/sysctl.conf #修改sysctl文件启用carp的arpbalance和carp抢占功能. Add the following content
Net.inet.carp.preempt=1
Net.inet.carp.arpbalance=1
Restarting two servers will take effect.