ヒアビート



Hearbeat




ハートビートの説明:

効果:



ハートビートによって、一般に高可用性サービスとして知られている、マシンの別の通常の操作でサービスを継続できなかったコンピューターからリソース(IPプログラムとサービスおよびその他のリソース)をすばやく転送できます。本番アプリケーションのアップグレードシナリオ、ハートビート、その他の高可用性機能の維持には多くの共通点があります

ハートビートの公式アドレス:http://linux-ha.org/wiki/Main_Page



動作原理:

ソフトウェア構成ファイルを変更することにより、heartbeat canプライマリサーバーとしてどのハートビートサーバーを指定し、もう一方は自動的にホットスタンバイサーバーになります。次に、ハートビートはホットスタンバイサーバーデーモンに配置され、マスターサーバーからのハートビートメッセージをリッスンします。開発時のホットスタンバイサーバーがハートビートモニターの独立したサーバーになっていない場合、フェイルオーバープロセスを開始し、プライマリサーバーの所有権で関連するリソースとサービスを取得します。ステップマスターサーバーは、リソースとサービスの高可用性を実現するために、中断のないサービスを提供し続けます。目的

上記の説明は、スタンバイモードとプライマリマスターモード、つまり2つの相互バックアップサーバーであり、指定された範囲内で相手が受信されない場合、メッセージを相互に送信して、現在の状態を相互に通知します。ハートビートパケットが送信されると、パーティが失敗するか、反対側がダウンします。その後、各ホストの通常の操作が自身のリソースを引き継ぎ始め、他のホスト上のモジュールリソースまたはサービスの操作を引き継ぎます。ユーザーにサービスを提供するサービスを提供する



切り替え条件:

1)サーバーのダウンタイム

2)ハートビートサービス自体の障害

3)ハートビート接続障害

ハートビート接続はじめに:

ハートビートサービスを展開するには、完了するために少なくとも2つのホストが必要です。では、2つのホスト間で高可用性サービスを実現するには、どのように相互に通信し、相互に通信してそれを検出するのでしょうか。

1)シリアルケーブル(推奨、デメリットはそれほど遠くない)

2)2つのNICに直接接続されたイーサネットケーブル(推奨)

3)イーサネットケーブル、選択したスイッチ(Ci)に接続されたネットワークデバイス、2番目の選択肢、スイッチの障害点が増加しますが、回線は他のデータ送信の影響を受けやすい専用のハートビートではないため、ハートビートパケットに問題が発生します

スプリットブレイン:

指定された時間内に高可用性を実現する2つのサーバー間では、両方の高可用性サーバーがまだ稼働していて正常に動作しているときに、お互いを検出してハートビートフェイルオーバー機能を開始し、リソースとサービスの所有権を取得することができないため、これにより、両端で同じIPまたはサーバーが同時に起動するという深刻な問題が発生し、競合が解消されます。最も深刻なのは、ユーザーがデータを書き込むときに、2つのホストが同じVIPアドレスを占有することです。これにより、サーバー間でデータが失われたり、データの一貫性が失われたりする可能性があります。これはスプリットブレインと呼ばれ、クラスターパーティションまたは垂直スプリットブレインとも呼ばれます。

ハートビートメッセージタイプ:

1)ハートビートメッセージ:約150バイトのデータパケットは、ユニキャスト、マルチキャスト、またはブロードキャストモード、制御心拍数、および障害フェイルオーバーの待機時間のいずれかです。

2)クラスター変換メッセージ:ip-requestおよびip-reques-resp。プライマリサーバーがip-requestメッセージによってオンラインに戻り、プライマリサーバーが取得に失敗した場合にバックアップマシンのバックアップサーバーに必要なリソースを解放し、プライマリサーバーのリリースで作成されたバックアップサーバーのリソースとサービスをシャットダウンすると失敗します。プライマリサーバーに障害が発生したときに取得したリソースとサービスを解放した後、プライマリサーバーはip-request-respを介してメインサーバーに通知します。これはニュースではありません。

ハートビート高可用性クラスター戦闘

環境の準備:

Master: OS:Centos6.5 IP: eth0: 192.168.1.1 # IP Server Management eth1:192.168.220.10 Hostname:heart-master VIP:192.168.1.249 Backup: OS:Centos6.5 IP: eth0: 192.168.1.2 # IP Server Management eth1:192.168.220.20 Hostname:heart-backup VIP:192.168.1.250 hosts: echo '192.168.220.10 heart-master' >> /etc/hosts echo '192.168.220.20 heart-backup' >> /etc/hosts # The two must be configured # Heartbeat connection [root@xxxxx /]# route add -host 192.168.220.20 dev eth1 [root@xxxxx /]# route add -host 192.168.220.10 dev eth1 # Simulated heartbeat connection, from eth1 out are equal to the two card directly connected, can be placed in rc.local for boot

ソフトウェアのインストール:

# Download and install the package epel [root@xxxxx ~]# wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@xxxxx ~]# rpm -ivh epel-release-6-8.noarch.rpm [root@xxxxx ~]# yum -y install heartbeat* # Explain profile ha.cf heartbeat parameter configuration files here to configure some basic parameters of the heartbeat Heartbeat authkey authentication file server according authkey availability between peer of the peer authenticate haresource heartbeat resource configuration files, such as IP configuration and script and other resources # The default configuration file path [root@xxxxx ~]# ls /etc/ha.d/ harc rc.d README.config resource.d shellfuncs # But now there is nothing profile, so we want to install a copy of the template over point [root@xxxxx ~]# cd /etc/ha.d/ [root@xxxxx ha.d]# cp /usr/share/doc/heartbeat-3.0.4/ha.cf . [root@xxxxx ha.d]# cp /usr/share/doc/heartbeat-3.0.4/authkeys . [root@xxxxx ha.d]# cp /usr/share/doc/heartbeat-3.0.4/haresources .

ha.cf構成ファイルパラメーター説明

# debugfile / var / log / debug log storage position of the ha-debug #heartbeat logfile / var / log ha-log #heartbeat logging / storage position logfacility locall # local1 configured to receive a log by the service device syslog keepalive 2 # heartbeat interval specified time of 2 seconds (time and sent on a broadcast every 2 seconds eth1) If specified deadtime 30 # spare node does not receive the master node heartbeat in 30 seconds, then immediately take over the resources of the main server node warntime 10 # heartbeat specified delay time is 10 seconds. 10 seconds when the backup node can not receive a heartbeat signal, a warning will be written to the log in the log, but this time without switching service initdead 120 # specify heartbeat after the first run, to wait 120 seconds before starting any resource master server, this option is time to solve this situation arising interval. The value of at least twice the deadtime, the encounter vip single binding very slow start, is a normal phenomenon. The reason the value of the field bcast eth1 # indicates heartbeat broadcast interfaces using Ethernet broadcast eth1. The use of two actual network to transmit the heartbeat #bcast eth0 eth1 mcast eth2 225.0.0.1 694 10 # broadcast communication port disposed in use, the default port number 694 used on auth_failback # is used to define when the node recovers, whether the service will automatically switch back node heart-master # master host name, you can 'uname -n' command to check the node heart-backup # standby node host name, you can 'uname -n' command to check, you can use IP crm no # whether to open the Cluster Resource Manager (cluster resource management) function #

Authkeysファイルの構成

#Authentication file. Must be mode 600 # mentioned here, authkey permissions must be 600 #Available methods: crc sha1, md5.Crc does not need / authentication method wat a key # can be set, crc is the most insecure # Sha1 is believed to be the 'best', MD5, next best # sha1 way is the best, what use this

haresources file parameter interpretation

heart-master IPaddr::192.168.1.249/24/eth0 heart-backup IPaddr::192.168.1.250/24/eth0 # Heart-master is the host name, represents the state of the accident will be bound Ip192.168.1.249 in heart-master #IPaddr IP configuration for the default script heartbeat, followed by the IP are all script parameters # 192.168.1.249 / 24 / eth0 external services for VIP clusters, initial start-up on heart-master, 24 for the subnet mask, eth0 bit ip actual physical network card bound for the provision of external services heartbeat communication interface # Similarly 192168.1.250 / 24 / eth0 bit cluster VIP external services, initially started on the heart-backup, 24 subnet mask, eth0 ip actual physical network card bound for the provision of external services heartbeat communication interface # Configuration examples heart-master IPaddr:192.168.1.249/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 rsdata # Heart-master See above # 192.168.1.249 / 24 / eth0 see above, (plus one), equivalent to the implementation herein /etc/ha.d/resource.d/IPaddr 192.168.1.249/24/eth0 stop / start #drbddisk :: data, start drdb data resources. Here is equivalent to performing /etc/ha.d/resource.d/drbddisk dataa stop / start #Filesystem :: / dev / drbd0 :: / data :: ext3, drbd partition mounted to / data directory, equivalent to the implementation /etc/ha.d/resoucre.d/Filesystem / dev / drbd0 / data ext3 stop here / start #rsdata, start mysl service script. Here is equivalent to performing /etc/init.d/rsdata stop / start

作成環境の構成例

#ha.cf [root@xxxxx ha.d]# cat /etc/ha.d/ha.cf #the start by Daniel debugfile /var/log/ha-debug logfile /var/log/ha.log logfacility local1 keepalive 2 deadtime 30 warntime 10 initdead 60 #bcast eth1 mcast eth1 225.0.0.250 694 1 0 auto_failback on node heart-master node heart-backup crm no #the end by Daniel #authenkeys [root@xxxxx ha.d]# cat /etc/ha.d/authkeys auth 1 1 sha1 47c9336850f1db6fa58bc470bc9b7810eb397f04 #haresources [root@xxxxx ha.d]# cat /etc/ha.d/haresources heart-master IPaddr::192.168.1.249/24/eth0 heart-backup IPaddr::192.168.1.250/24/eth0 # Three profiles as master and backup #start up # To start a [root@xxxxx ha.d]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped INFO: Resource is stopped Done. # View VIP [root@xxxxx ha.d]# ip addr | grep 192.168.1 inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.250/24 brd 192.168.1.255 scope global secondary eth0 inet 192.168.1.249/24 brd 192.168.1.255 scope global secondary eth0 # Restart another [root@xxxxx ha.d]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped INFO: Resource is stopped Done. # Check both sides of the VIP [root@xxxxx ha.d]# ip addr | grep 192.168.1. inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.249/24 brd 192.168.1.255 scope global secondary eth0 [root@xxxxx ha.d]# ip addr | grep 192.168.1 inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.250/24 brd 192.168.1.255 scope global secondary eth0 # If there have been 249 and 250 on both sides, it is the occurrence of the split brain

Webサービスを実装するハートビート実際のケースの高可用性

# Installation [root@xxxxx ha.d]# yum -y install httpd [root@xxxxx ha.d]# yum -y install httpd #start up [root@xxxxx ha.d]# /etc/init.d/httpd start [root@xxxxx ha.d]# /etc/init.d/httpd start # [root@xxxxx ha.d]# echo 1.1 > /var/www/html/index.html [root@xxxxx ha.d]# echo 1.2 > /var/www/html/index.html 1.2, down tune master # now access http://192.168.1.249/, displayed 1.1,250 displayed again visit 249, displayed 1.2 # We want to achieve heartbeat control start httpd achieve ip switch # Modify haresources [root@xxxxx ha.d]# cat haresources heart-master IPaddr :: 172.16.50.249/24/eth0 httpd