﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-少年阿宾-随笔分类-keepAlive</title><link>http://www.blogjava.net/stevenjohn/category/54884.html</link><description>那些青春的岁月</description><language>zh-cn</language><lastBuildDate>Mon, 02 Nov 2015 17:13:18 GMT</lastBuildDate><pubDate>Mon, 02 Nov 2015 17:13:18 GMT</pubDate><ttl>60</ttl><item><title>Deploying Highly Available Virtual Interfaces With Keepalived</title><link>http://www.blogjava.net/stevenjohn/archive/2015/11/01/428012.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Sun, 01 Nov 2015 13:06:00 GMT</pubDate><guid>http://www.blogjava.net/stevenjohn/archive/2015/11/01/428012.html</guid><wfw:comment>http://www.blogjava.net/stevenjohn/comments/428012.html</wfw:comment><comments>http://www.blogjava.net/stevenjohn/archive/2015/11/01/428012.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/stevenjohn/comments/commentRss/428012.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/stevenjohn/services/trackbacks/428012.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">Linux is a powerhouse when it comes to networking, and provides a full featured and high performance network stack. When combined with web front-ends such as<a href="http://haproxy.1wt.eu/" style="color: black;">HAProxy</a>,&nbsp;<a href="http://www.lighttpd.net/" style="color: black;">lighttpd</a>,&nbsp;<a href="http://nginx.net/" style="color: black;">Nginx</a>,&nbsp;<a href="http://httpd.apache.org/" style="color: black;">Apache</a>&nbsp;or your favorite application server, Linux is a killer platform for hosting web applications. Keeping these applications up and operational can sometimes be a challenge, especially in this age of horizontally scaled infrastructure and commodity hardware. But don't fret, since there are a number of technologies that can assist with making your applications and network infrastructure fault tolerant.</p><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">One of these technologies, keepalived, provides interface failover and the ability to perform application-layer health checks. When these capabilities are combined with the&nbsp;<a href="http://www.linuxvirtualserver.org/" style="color: black;">Linux Virtual Server (LVS) project</a>, a fault in an application will be detected by keepalived, and the virtual interfaces that are accessed by clients can be migrated to another available node. This article will provide an introduction to keepalived, and will show how to configure interface failover between two or more nodes. Additionally, the article will show how to debug problems with keepalived and VRRP.</p><h2>What Is Keepalived?</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">The keepalived project provides a keepalive facility for Linux servers. This keepalive facility consists of a VRRP implementation to manage virtual routers (aka virtual interfaces), and a health check facility to determine if a service (web server, samba server, etc.) is up and operational. If a service fails a configurable number of health checks, keepalived will fail a virtual router over to a secondary node. While useful in its own right, keepalived really shines when combined with the Linux Virtual Server project. This article will focus on keepalived, and a future article will show how to integrate the two to create a fault tolerant load-balancer.</p><h2>Installing KeepAlived From Source Code</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">Before we dive into configuring keepalived, we need to install it. Keepalived is distributed as source code, and is available in several package repositories. To install from source code, you can execute wget or curl to retrieve the source, and then run "configure", "make" and "make install" compile and install the software:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">$ wget http://www.keepalived.org/software/keepalived-1.1.17.tar.gz  $ tar xfvz keepalived-1.1.17.tar.gz   $ cd keepalived-1.1.17  $ ./configure --prefix=/usr/local  $ make &amp;&amp; make install </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">In the example above, the keepalived daemon will be compiled and installed as /usr/local/sbin/keepalived.</p><h2>Configuring KeepAlived</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">The keepalived daemon is configured through a text configuration file, typically named keepalived.conf. This file contains one or more configuration stanzas, which control notification settings, the virtual interfaces to manage, and the health checks to use to test the services that rely on the virtual interfaces. Here is a sample annotated configuration that defines two virtual IP addresses to manage, and the individuals to contact when a state transition or fault occurs:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;"># Define global configuration directives global_defs {     # Send an e-mail to each of the following     # addresses when a failure occurs    notification_email {        matty@prefetch.net        operations@prefetch.net    }    # The address to use in the From: header    notification_email_from root@VRRP-director1.prefetch.net     # The SMTP server to route mail through    smtp_server mail.prefetch.net     # How long to wait for the mail server to respond    smtp_connect_timeout 30     # A descriptive name describing the router    router_id VRRP-director1 }  # Create a VRRP instance  VRRP_instance VRRP_ROUTER1 {      # The initial state to transition to. This option isn't     # really all that valuable, since an election will occur     # and the host with the highest priority will become     # the master. The priority is controlled with the priority     # configuration directive.     state MASTER      # The interface keepalived will manage     interface br0      # The virtual router id number to assign the routers to     virtual_router_id 100      # The priority to assign to this device. This controls     # who will become the MASTER and BACKUP for a given     # VRRP instance.     priority 100      # How many seconds to wait until a gratuitous arp is sent     garp_master_delay 2      # How often to send out VRRP advertisements     advert_int 1      # Execute a notification script when a host transitions to     # MASTER or BACKUP, or when a fault occurs. The arguments     # passed to the script are:     #  $1 - "GROUP"|"INSTANCE"     #  $2 = name of group or instance     #  $3 = target state of transition     # Sample: VRRP-notification.sh VRRP_ROUTER1 BACKUP 100     notify "/usr/local/bin/VRRP-notification.sh"      # Send an SMTP alert during a state transition     smtp_alert      # Authenticate the remote endpoints via a simple      # username/password combination     authentication {         auth_type PASS         auth_pass 192837465     }     # The virtual IP addresses to float between nodes. The     # label statement can be used to bring an interface      # online to represent the virtual IP.     virtual_ipaddress {         192.168.1.100 label br0:100         192.168.1.101 label br0:101     } } </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">The configuration file listed above is self explanatory, so I won't go over each directive in detail. I will point out a couple of items:</p><ul style="font-family: Simsun; font-size: medium; line-height: normal;"><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">Each host is referred to as a director in the documentation, and each director can be responsible for one or more VRRP instances</li><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">Each director will need its own copy of the configuration file, and the router_id, priority, etc. should be adjusted to reflect the nodes name and priority relative to other nodes</li><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">To force a specific node to master a virtual address, make sure the director's priority is higher than the other virtual routers</li><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">If you have multiple VRRP instances that need to failover together, you will need to add each instance to a VRRP_sync_group</li><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">The notification script can be used to generate custom syslog messages, or to invoke some custom logic (e.g., restart an app) when a state transition or fault occurs</li><li style="font-size: 17px; margin-top: 5px; margin-bottom: 5px; margin-left: 10px;">The keepalived package comes with numerous configuration examples, which show how to configure numerous aspects of the server</li></ul><h2>Starting Keepalived</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">Keepalived can be executed from an RC script, or started from the command line. The following example will start keepalived using the configuration file /usr/local/etc/keepalived.conf:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">$ keepalived -f /usr/local/etc/keepalived.conf </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">If you need to debug keepalived issues, you can run the daemon with the "--dont-fork", "--log-console" and "--log-detail" options:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">$ keepalived -f /usr/local/etc/keepalived.conf --dont-fork --log-console --log-detail </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">These options will stop keepalived from fork'ing, and will provide additional logging data. Using these options is especially useful when you are testing out new configuration directives, or debugging an issue with an existing configuration file.</p><h2>Locating The Router That is Managing A Virtual IP</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">To see which director is currently the master for a given virtual interface, you can check the output from the ip utility:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">VRRP-director1$ ip addr list br0 5: br0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UNKNOWN      link/ether 00:24:8c:4e:07:f6 brd ff:ff:ff:ff:ff:ff     inet 192.168.1.6/24 brd 192.168.1.255 scope global br0     inet 192.168.1.100/32 scope global br0:100     inet 192.168.1.101/32 scope global br0:101     inet6 fe80::224:8cff:fe4e:7f6/64 scope link         valid_lft forever preferred_lft forever  VRRP-director2$ ip addr list br0 5: br0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UNKNOWN      link/ether 00:24:8c:4e:07:f6 brd ff:ff:ff:ff:ff:ff     inet 192.168.1.7/24 brd 192.168.1.255 scope global br0     inet6 fe80::224:8cff:fe4e:7f6/64 scope link         valid_lft forever preferred_lft forever </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">In the output above, we can see that the virtual interfaces 192.168.1.100 and 192.168.1.101 are currently active on VRRP-director1.</p><h2>Troubleshooting Keepalived And VRRP</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">The keepalived daemon will log to syslog by default. Log entries will range from entries that show when the keepalive daemon started, to entries that show state transitions. Here are a few sample entries that show keepalived starting up, and the node transitioning a VRRP instance to the MASTER state:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">Jul  3 16:29:56 disarm Keepalived: Starting Keepalived v1.1.17 (07/03,2009) Jul  3 16:29:56 disarm Keepalived: Starting VRRP child process, pid=1889 Jul  3 16:29:56 disarm Keepalived_VRRP: Using MII-BMSR NIC polling thread... Jul  3 16:29:56 disarm Keepalived_VRRP: Registering Kernel netlink reflector Jul  3 16:29:56 disarm Keepalived_VRRP: Registering Kernel netlink command channel Jul  3 16:29:56 disarm Keepalived_VRRP: Registering gratutious ARP shared channel Jul  3 16:29:56 disarm Keepalived_VRRP: Opening file '/usr/local/etc/keepalived.conf'. Jul  3 16:29:56 disarm Keepalived_VRRP: Configuration is using : 62990 Bytes Jul  3 16:29:57 disarm Keepalived_VRRP: VRRP_Instance(VRRP_ROUTER1) Transition to MASTER STATE Jul  3 16:29:58 disarm Keepalived_VRRP: VRRP_Instance(VRRP_ROUTER1) Entering MASTER STATE Jul  3 16:29:58 disarm Keepalived_VRRP: Netlink: skipping nl_cmd msg... </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">If you are unable to determine the source of a problem with the system logs, you can use tcpdump to display the VRRP advertisements that are sent on the local network. Advertisements are sent to a reserved VRRP multicast address (224.0.0.18), so the following filter can be used to display all VRRP traffic that is visible on the interface passed to the "-i" option:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">$ tcpdump -vvv -n -i br0 host 224.0.0.18 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on br0, link-type EN10MB (Ethernet), capture size 96 bytes  10:18:23.621512 IP (tos 0x0, ttl 255, id 102, offset 0, flags [none], proto VRRP (112), length 40) \                 192.168.1.6 &gt; 224.0.0.18: VRRPv2, Advertisement, vrid 100, prio 100, authtype simple,                  intvl 1s, length 20, addrs: 192.168.1.100 auth "19283746"  10:18:25.621977 IP (tos 0x0, ttl 255, id 103, offset 0, flags [none], proto VRRP (112), length 40) \                 192.168.1.6 &gt; 224.0.0.18: VRRPv2, Advertisement, vrid 100, prio 100, authtype simple,                  intvl 1s, length 20, addrs: 192.168.1.100 auth "19283746"                          ......... </pre><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">The output contains several pieces of data that be useful for debugging problems:</p><pre style="margin: 15px 10px 15px 15px; font-size: 13pt; font-family: Courier; white-space: pre-wrap; word-wrap: break-word; line-height: normal;">authtype - the type of authentication in use (authentication configuration directive) vrid - the virtual router id (virtual_router_id configuration directive) prio - the priority of the device (priority configuration directive) intvl - how often to send out advertisements (advert_int configuration directive) auth - the authentication token sent (auth_pass configuration directive) </pre><h2>Conclusion</h2><hr style="width: 600px; font-family: Simsun; font-size: medium; line-height: normal;" /><p style="margin-top: 10px; margin-left: 15px; margin-right: 10px; font-size: 13pt; font-family: Simsun; line-height: normal;">In this article I described how to set up a host to use the keepalived daemon, and provided a sample configuration file that can be used to failover virtual interfaces between servers. Keepalived has a slew of options not covered here, and I will refer you to the&nbsp;<a href="http://www.keepalived.org/" style="color: black;">keepalived</a>&nbsp;source code and documentation for additional details</p><img src ="http://www.blogjava.net/stevenjohn/aggbug/428012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/stevenjohn/" target="_blank">abin</a> 2015-11-01 21:06 <a href="http://www.blogjava.net/stevenjohn/archive/2015/11/01/428012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Keepalived中Master和Backup角色选举策略</title><link>http://www.blogjava.net/stevenjohn/archive/2015/10/12/427693.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Sun, 11 Oct 2015 16:50:00 GMT</pubDate><guid>http://www.blogjava.net/stevenjohn/archive/2015/10/12/427693.html</guid><wfw:comment>http://www.blogjava.net/stevenjohn/comments/427693.html</wfw:comment><comments>http://www.blogjava.net/stevenjohn/archive/2015/10/12/427693.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/stevenjohn/comments/commentRss/427693.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/stevenjohn/services/trackbacks/427693.html</trackback:ping><description><![CDATA[<p>在Keepalived集群中，其实并没有严格意义上的主、备节点，虽然可以在Keepalived配置文件中设置&#8220;state&#8221;选项为&#8220;MASTER&#8221;状态，但是这并不意味着此节点一直就是Master角色。控制节点角色的是Keepalived配置文件中的&#8220;priority&#8221;值，但并它并不控制所有节点的角色，另一个能改变节点角色的是在vrrp_script模块中设置的&#8220;weight&#8221;值，这两个选项对应的都是一个整数值，其中&#8220;weight&#8221;值可以是个负整数，一个节点在集群中的角色就是通过这两个值的大小决定的。</p> <p>在一个一主多备的Keepalived集群中，&#8220;priority&#8221;值最大的将成为集群中的Master节点，而其他都是Backup节点。在Master节点发生故障后，Backup节点之间将进行&#8220;民主选举&#8221;，通过对节点优先级值&#8220;priority&#8221;和&#8220;&#8220;weight&#8221;的计算，选出新的Master节点接管集群服务。</p> <p><br /></p> <p>在vrrp_script模块中，如果不设置&#8220;weight&#8221;选项值，那么集群优先级的选择将由Keepalived配置文件中的&#8220;priority&#8221;值决定，而在需要对集群中优先级进行灵活控制时，可以通过在vrrp_script模块中设置&#8220;weight&#8221;值来实现。下面列举一个实例来具体说明。</p> <p><br /></p> <p>假定有A和B两节点组成的Keepalived集群，在A节点keepalived.conf文件中，设置&#8220;priority&#8221;值为100，而在B节点keepalived.conf文件中，设置&#8220;priority&#8221;值为80，并且A、B两个节点都使用了&#8220;vrrp_script&#8221;模块来监控mysql服务，同时都设置&#8220;weight&#8221;值为10，那么将会发生如下情况。</p> <p><br /></p> <p>在两节点都启动Keepalived服务后，正常情况是A节点将成为集群中的Master节点，而B自动成为Backup节点，此时将A节点的mysql服务关闭，通过查看日志发现，并没有出现B节点接管A节点的日志，B节点仍然处于Backup状态，而A节点依旧是Master状态，在这种情况下整个HA集群将失去意义。</p> <p><br /></p> <p>下面就分析一下产生这种情况的原因，这也就是Keepalived集群中主、备角色选举策略的问题。下面总结了在Keepalived中使用vrrp_script模块时整个集群角色的选举算法，由于&#8220;weight&#8221;值可以是正数也可以是负数，因此，要分两种情况进行说明。</p> <p><br /></p> <p>1.<span style="white-space: pre">	</span>&#8220;weight&#8221;值为正数时</p> <p>在vrrp_script中指定的脚本如果检测成功，那么Master节点的权值将是&#8220;weight值与&#8221;priority&#8220;值之和，如果脚本检测失败，那么Master节点的权值保持为&#8220;priority&#8221;值，因此切换策略为：</p> <p><span style="white-space: pre">	</span>Master节点&#8220;vrrp_script&#8221;脚本检测失败时，如果Master节点&#8220;priority&#8221;值小于Backup节点&#8220;weight值与&#8221;priority&#8220;值之和，将发生主、备切换。</p> <p><span style="white-space: pre">	</span>Master节点&#8220;vrrp_script&#8221;脚本检测成功时，如果Master节点&#8220;weight&#8221;值与&#8220;priority&#8221;值之和大于Backup节点&#8220;weight&#8221;值与&#8220;priority&#8221;值之和，主节点依然为主节点，不发生切换。</p> <p><br /></p> <p>2.<span style="white-space: pre">	</span>&#8220;weight&#8221;值为负数时</p> <p>在&#8220;vrrp_script&#8221;中指定的脚本如果检测成功，那么Master节点的权值仍为&#8220;priority&#8221;值，当脚本检测失败时，Master节点的权值将是&#8220;priority&#8220;值与&#8220;weight&#8221;值之差，因此切换策略为：</p> <p><span style="white-space: pre">	</span>Master节点&#8220;vrrp_script&#8221;脚本检测失败时，如果Master节点&#8220;priority&#8221;值与&#8220;weight&#8221;值之差小于Backup节点&#8220;priority&#8221;值，将发生主、备切换。</p> <p><span style="white-space: pre">	</span>Master节点&#8220;vrrp_script&#8221;脚本检测成功时，如果Master节点&#8220;priority&#8221;值大于Backup节点&#8220;priority&#8221;值时，主节点依然为主节点，不发生切换。</p> <p><br /></p> <p>在熟悉了Keepalived主、备角色的选举策略后，再来分析一下刚才实例，由于A、B两个节点设置的&#8220;weight&#8221;值都为10，因此符合选举策略的第一种，在A节点停止Mysql服务后，A节点的脚本检测将失败，此时A节点的权值将保持为A节点上设置的&#8220;priority&#8221;值，即为100，而B节点的权值将变为&#8220;weight&#8221;值与&#8220;priority&#8221;值之和，也就是90（10+80），这样就出现了A节点权值仍然大于B节点权值的情况，因此不会发生主、备切换。</p> <p><br /></p> <p>对于&#8220;weight&#8221;值的设置，有一个简单的标准，即&#8220;weight&#8221;值的绝对值要大于Master和Backup节点&#8220;priority&#8221;值之差。对于上面A、B两个节点的例子，只要设置&#8220;weight&#8221;值大于20即可保证集群正常运行和切换。由此可见，对于&#8220;weight值的设置，要非常谨慎，如果设置不好，将导致集群角色选举失败，使集群陷于瘫痪状态。</p><img src ="http://www.blogjava.net/stevenjohn/aggbug/427693.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/stevenjohn/" target="_blank">abin</a> 2015-10-12 00:50 <a href="http://www.blogjava.net/stevenjohn/archive/2015/10/12/427693.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Keepalived VS Heartbeat对比</title><link>http://www.blogjava.net/stevenjohn/archive/2015/07/26/426432.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Sun, 26 Jul 2015 12:42:00 GMT</pubDate><guid>http://www.blogjava.net/stevenjohn/archive/2015/07/26/426432.html</guid><wfw:comment>http://www.blogjava.net/stevenjohn/comments/426432.html</wfw:comment><comments>http://www.blogjava.net/stevenjohn/archive/2015/07/26/426432.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/stevenjohn/comments/commentRss/426432.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/stevenjohn/services/trackbacks/426432.html</trackback:ping><description><![CDATA[<div>最近因为项目需要，简单的试用了两款高可用开源方案：Keepalived和Heartbeat。两者都很流行，但差异还是很大的，现将试用过程中的感受以及相关知识点简单总结一下，供大家选择方案的时候参考。</div><div></div><div>1）Keepalived使用更简单：从安装、配置、使用、维护等角度上对比，Keepalived都比Heartbeat要简单得多，尤其是Heartbeat2.1.4后拆分成3个子项目，安装、配置、使用都比较复杂，尤其是出问题的时候，都不知道具体是哪个子系统出问题了；而Keepalived只有1个安装文件、1个配置文件，配置文件也简单很多；</div><div></div><div>2）Heartbeat功能更强大：Heartbeat虽然复杂，但功能更强大，配套工具更全，适合做大型集群管理，而Keepalived主要用于集群倒换，基本没有管理功能；</div><div></div><div>3）协议不同：Keepalived使用VRRP协议进行通信和选举，Heartbeat使用心跳进行通信和选举；Heartbeat除了走网络外，还可以通过串口通信，貌似更可靠；</div><div></div><div>4）使用方式基本类似：如果要基于两者设计高可用方案，最终都要根据业务需要写自定义的脚本，Keepalived的脚本没有任何约束，随便怎么写都可以；Heartbeat的脚本有约束，即要支持service start/stop/restart这种方式，而且Heartbeart提供了很多默认脚本，简单的绑定ip，启动apache等操作都已经有了；</div><div></div><div>使用建议：优先使用Keepalived，当Keepalived不够用的时候才选择Heartbeat</div><img src ="http://www.blogjava.net/stevenjohn/aggbug/426432.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/stevenjohn/" target="_blank">abin</a> 2015-07-26 20:42 <a href="http://www.blogjava.net/stevenjohn/archive/2015/07/26/426432.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>