Heartbeat v2 Implementation of HA Web based on haresources

Source: Internet
Author: User

Objective:

The article cost the author a lot of time to write, reproduced please reply to obtain the author's consent!



Achieve the goal:

Use heartbeat and haresources to achieve high availability of web clusters

Terminology Explanation:


What is heartbeat:

The Heartbeat project is an integral part of the LINUX-HA project, which implements a highly available cluster system


Why to use heartbeat:

High availability of services in Linux requires HA clusters, and HA clusters require software that provides messaging layer and cluster Resource Manager functionality

Components to implement CRM:

The heartbeat V2 version has two components that can be implemented in CRM, Haresources,crm. Here we use haresources to manage the resources of each node


Lab Environment:

system:centos6.7

Host

Primary:node1.anyisalin.com

Standby:node2.anyisalin.com

Network Configure:

NODE1:172.16.100.7/24 eth0

NODE2:172.16.100.8/24 eth0

Float IP:172.16.100.1/24 #对外提供服务的IP


Experimental steps:

1. Use the Hosts file to implement nodes in an HA cluster to resolve the host names of each node

2. Using public key authentication to realize mutual trust communication between hosts

3. Installation Configuration heartbeat,httpd

4. Test the Web server for high availability



1. Use the Hosts file to implement nodes in an HA cluster to resolve the host names of each node

[Email protected] ~]# vim/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.100.7 node1.anyisalin.com
172.16.100.8 node2.anyisalin.com
[Email protected] ~]# scp-p/etc/hosts node1.anyisalin.com:/etc/


2. Using public key authentication to realize mutual trust communication between hosts

[[email protected] ~]# ssh-keygen-t rsa-p '-f ~/.ssh/id_rsa[[email protected] ~]# ssh-copy-id-i ~/.ssh/id_rsa.pub nod E1.anyisalin.com[[email protected] ~]# ssh-keygen-t rsa-p "'-f ~/.ssh/id_rsa[[email protected] ~]# ssh-copy-id-t ~/.SS H/id_rsa node2.anyisalin.com

3. Installation Configuration heartbeat,httpd

[[email protected] ~]# wget -o /etc/yum.repos.d /centos.repo https://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/centos?codeblock=2  ## Using the USTC image source [[Email protected] ~]# yum install epel-rpm-macros.noarch -y[[email  protected] ~]# yum instsall heartbeat httpd -y[[email protected]  ~]# ssh node2.anyisalin.com  "Yum install -y epel-rpm-macros.noarch" [[Email  protected] ~]# ssh node2.anyisalin.com  "Yum install -y heartbeat  HTTPD "[[EMAIL PROTECTED] ~]# CP /USR/SHARE/DOC/HEARTBEAT-3.0.4/{AUTHKEYS,HA.CF, Haresources} /etc/ha.d/[[email protected] ~]# chmod 600 /etc/ha.d/authkeys 
[Email protected] ~]# Vim/etc/ha.d/authkeys
# #在最后添加两行
Auth 1
1 MD5 d41d8cd98f00b204e9800998ecf8427e-
# #保存退出


[Email protected] ~]# VIM/ETC/HA.D/HA.CF
# #在结尾添加几行
Bcast eth0
Logfile/var/log/ha-log
KeepAlive 1
Node Node1.anyisalin.com #这里的主机名必须和uname-N Display consistent
Node node2.anyisalin.com #同上
# #保存退出


[Email protected] ~]# vim/etc/ha.d/haresources
# #在最后添加一行
Node1.anyisalin.com Ipaddr::172.16.100.1/24/eth0 httpd
# #结束


[[email protected] ~]# SCP/ETC/HA.D/{AUTHKEYS,HARESOURCES,HA.CF} node2.anyisalin.com:/etc/ha.d/[[email protected] ~]  # echo "This is HA node1" >/var/www/html/index.html #创建网页文件 [[email protected] ~]# ssh node2.anyisalin.com ' echo ' this is HA node2 ">/var/www/html/index.html" #为node2创建网页文件 [[email protected] ~]# service heartbeat start #启动heartbeat服务 [ [Email protected] ~]# ssh node2.anyisalin.com "service Heartbeat start" #为node2启动heartbeat服务


[Email protected] ~]# Tail/var/log/ha-log #监控日志文件

ResourceManager (default) [8766]:2016/01/02_06:22:00 info:running/etc/ha.d/resource.d/ipaddr 172.16.100.1/24/eth0 Start
IPADDR (ipaddr_172.16.100.1) [8916]:2016/01/02_06:22:00 info:adding inet address 172.16.100.1/24 with broadcast address 172.16.100.255 to Device eth0
IPADDR (ipaddr_172.16.100.1) [8916]:2016/01/02_06:22:00 info:bringing device eth0 up
IPADDR (ipaddr_172.16.100.1) [8916]:2016/01/02_06:22:00 INFO:/usr/libexec/heartbeat/send_arp-i 200-r 5-p/var/run/ resource-agents/send_arp-172.16.100.1 eth0 172.16.100.1 Auto not_used not_used
/USR/LIB/OCF/RESOURCE.D//HEARTBEAT/IPADDR (ipaddr_172.16.100.1) [8890]:2016/01/02_06:22:00 info:success
ResourceManager (default) [8766]:2016/01/02_06:22:00 info:running/etc/init.d/httpd start


[[Email protected] ~]# IP a # #node1为主节点
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:cf:c0:42 BRD FF:FF:FF:FF:FF:FF
inet 172.16.100.7/24 BRD 172.16.100.255 Scope Global eth0
inet 172.16.100.1/24 BRD 172.16.100.255 scope Global secondary eth0
Inet6 FE80::20C:29FF:FECF:C042/64 Scope link
Valid_lft Forever Preferred_lft Forever


4. Test the Web server for high availability

[[email protected] ~]# Curl 172.16.100.1 #测试Web服务器, page displays the page file for the main node Node1
This is HA node 1
[Email protected] ~]#/usr/share/heartbeat/hb_standby #使用heartbeat内置脚本模拟FailOver (fail over)
[[Email protected] ~]# IP A
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:cf:c0:38 BRD FF:FF:FF:FF:FF:FF
inet 172.16.100.7/24 BRD 172.16.100.255 Scope Global eth0
Inet6 FE80::20C:29FF:FECF:C038/64 Scope link
Valid_lft Forever Preferred_lft Forever


[[Email protected] ~]# IP A
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:cf:c0:42 BRD FF:FF:FF:FF:FF:FF
inet 172.16.100.8/24 BRD 172.16.100.255 Scope Global eth0
inet 172.16.100.1/24 BRD 172.16.100.255 scope Global secondary eth0
Inet6 FE80::20C:29FF:FECF:C042/64 Scope link
Valid_lft Forever Preferred_lft Forever

[[email protected] ~]# Curl 172.16.100.1 #重新发起请求, the page appears as a Web page file Node2 from the node
This is HA Node2



Experiment Summary:

Heartbeat and haresources enable the high availability of web clusters, which can be transferred to the standby node via CRM in the case of a primary node failure, but there are many factors that are not considered in this experiment, but there is much to explain

This article from the "The Anyisalin Blog" blog, reproduced please contact the author!

Heartbeat v2 Implementation of HA Web based on haresources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.