Article Title: State synchronization between active and standby ld. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
A company's business uses a persistent connection tcp protocol (even if there is no business data packet interaction, there will be keepalive packet transmission every n seconds between c/s ), lvs is used for load balancing at the access layer. The ld performs Hot Standby through heartbeat. Because the active and standby ld only involves the drift of Public ip addresses, ldirectd is not used to reconstruct the ipvs table, instead, you can use your own scripts to reconstruct the ipvs table on the slave machine. Therefore, the configuration of haresoucret is simple: master_node_name public_ip ipvs_shell.
In the actual operation process, because it is a persistent connection service, and in order to ensure a better user experience, we decided to add the State synchronization between the active and standby ld, the so-called State synchronization, that is, ld maintains a connection tracking table and stores the real-time status of each connection in this table. To synchronize the connection trace table between the master and slave ld, you must start a kernel daemon thread on the master and slave ld to synchronize data through broadcast.
Master ld:
Ipvsadm -- start-daemon = master -- mcast-interface = eth1
Backup ld:
Ipvsadm -- start-daemon = backup -- mcast-interface = eth1
After the two commands are executed on the master and slave ld, a kernel daemon thread 224.0.0.81: 8848 listen can be found on the slave ld to receive broadcast packets sent from the master ld. Therefore, remember to open port 8848 Of The udp protocol of the firewall. Otherwise, it cannot be synchronized. You can use ipvsadm-Lnc on the slave ld to check whether a connection is synchronized.
In addition, in the actual operation process, we also found that how does one trigger this synchronization between the master and slave ld?
First, a new connection will be synchronized in any case,
Second, for existing connections, if there is enough data to be transmitted over this connection, The expire time on the standby ld will be about to expire/or has expired, the primary ld will synchronize the existing connection to the standby ld again.
In addition, an old connection always exists, but the expire time on the backup machine has expired (the expire time on the master and backup machines is maintained on the master and backup machines respectively) it is also found that it is related to the transmitted data volume on this connection (that is, the data volume must reach a certain threshold value before it is triggered). If there is no business data between c/s, only the heartbeat data transmitted every n seconds (that is, the trigger threshold is not reached) will be found that the connection tracking table on the standby ld has no such data.
In the case of normal business data:
500) this. width = 500; "border = 0>
Idle (only keepalive packets)
500) this. width = 500; "border = 0>