一、heartbeat介绍

heartbeat是HA高可用集群的一个重要组件,heartbeat实现了资源转移和心跳信息传递。它的常用组合方式为heartbeat v1,heartbeat v2+crm,heartbeat v3 + pacemaker,目前版本为v3版本。

二、编译前准备

heartbeat官方站点http://hg.linux-ha.org/

  Cluster Glue官方站点https://github.com/ClusterLabs/cluster-glue

  Resource Agents官方站点 https://github.com/ClusterLabs/resource-agents

node1:192.168.0.15

node2:192.168.0.16

配置集群前提:

(1)各节点时间一致,便于心跳信息传递,使用ntp实现

(2)节点间需要通过主机名互相通信,必须解析主机至IP地址

(a)建议名称解析功能使用hosts文件来实现

(b)通信中使用的名字与节点名字必须保持一致 “uname -n” 或hostname展示出的名字保持一致

(3)考虑仲裁设备是否会用到

(4)建立各节点之间的root用户能够给予密钥认证

(5)定义为集群中的资源,不能开机启动

  1. #使用ntpdate命令同步时间,并建立周期性任务
  2. #可使用任意节点服务器作为ntp时间服务器,如各节点可上公网,可直接指定公网ntp服务器
  3.  
  4. 、安装ntp
  5. [root@node2 ~]# yum install -y ntp
  6. [root@node2 ~]# vim /etc/ntp.conf #修改配置文件允许本网段客户端获取地址
  7. 将下面的语句
  8. restrict default kod nomodify notrap nopeer noquery
  9. 修改为
  10. restrict default nomodify
  11. restrict 192.168.0.0 mask 255.255.255.0 nomodify
  12.  
  13. [root@node2 ~]# service ntpd start
  14. Starting ntpd: [ OK ]
  15.  
  16. 查看同步过程
  17. [root@node2 ~]# ntpq -p
  18. remote refid st t when poll reach delay offset jitter
  19. ==============================================================================
  20. *202.118.1.81 202.118.1.47 u 92.249 8.602 0.714
  21. 202.112.31.197 .INIT. u - 0.000 0.000 0.000
  22.  
  23. 、客户端创建周期任务,每3秒同步时间
  24. [root@node1 ~]# crontab -e
  25. */ * * * * /usr/sbin/ntpdate 192.168.0.16 &> /dev/null
  26. [root@node1 ~]# service crond start
  27.  
  28. #手动同步成功,因ntp一般为自动,手动前kill掉所有ntp进程即可
  29. [root@node1 ~]# ntpdate 192.168.0.16
  30. Nov :: ntpdate[]: adjust time server 192.168.0.16 offset -0.004440 sec
  31.  
  32. 、时间同步
  33. [root@node2 ~]# date; ssh 192.168.0.15 'date'
  34. Mon Nov :: CST
  35. root@192.168.0.15's password:
  36. Mon Nov :: CST
  37.  
  38. [root@node2 ~]# vim /etc/hosts
  39. 192.168.0.15 node1
  40. 192.168.0.16 node2
  41.  
  42. 、生成密钥对
  43. [root@node1 ~]# ssh-keygen -t rsa
  44. Generating public/private rsa key pair.
  45. Enter file in which to save the key (/root/.ssh/id_rsa):
  46. Enter passphrase (empty for no passphrase):
  47. Enter same passphrase again:
  48. Your identification has been saved in /root/.ssh/id_rsa.
  49. Your public key has been saved in /root/.ssh/id_rsa.pub.
  50. The key fingerprint is:
  51. a8:ad:2c::::ff:::9d::::ae:da:c9 root@centfils
  52. The key's randomart image is:
  53. +--[ RSA ]----+
  54. | |
  55. | |
  56. | |
  57. | . = |
  58. | * S |
  59. |.. o o |
  60. |+ . . o o o |
  61. |+ ooo*.. + |
  62. | o +*E+ |
  63. +-----------------+
  64.  
  65. 、把公钥传输至远程服务器对应用户的家目录
  66. [root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.16
  67. The authenticity of host '192.168.0.16 (192.168.0.16)' can't be established.
  68. RSA key fingerprint is e5::6c:f7:c0::3d:0b::b6:1e::0d::8b:.
  69. Are you sure you want to continue connecting (yes/no)? yes
  70. Warning: Permanently added '192.168.0.16' (RSA) to the list of known hosts.
  71. root@192.168.0.16's password:
  72. Now try logging into the machine, with "ssh 'root@192.168.0.16'", and check in:
  73.  
  74. .ssh/authorized_keys
  75.  
  76. to make sure we haven't added extra keys that you weren't expecting.
  77.  
  78. 、测试
  79. [root@node2 ~]# date; ssh root@192.168.0.15 'date'
  80. Mon Nov :: CST
  81. Mon Nov :: CST

准备工作

三、编译安装  

 1、安装依赖包(node1和node2同步安装)

  1. [root@node2 ~]# yum -y install autoconf automake gcc-c++ asciidoc libxslt-devel libtool libtool-ltdl-devel libxml2 libxml2-devel bzip2-devel glib2-devel mercurial *openssl* net-snmp OpenIPMI flex bison e2fsprogs-devel

  2、源码编译安装

  1. 下载地址http://linux-ha.org/wiki/Download
  2. #下载heartbeat
  3. [root@node2 ~]# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
  4. #下载cluster glue
  5. [root@node2 ~]# wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
  6. #下载cluster resource agents 注意:需要翻墙
  7. [root@node1 ~]# wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz

  3、创建用户与组

  1. [root@node1 ~]# groupadd haclient
  2. [root@node1 ~]# useradd -g haclient hacluster -M -s /sbin/nologin

 4、编译

  1. cluster glue
  2. [root@node1 ~]# tar xf 0a7add1d9996.tar.bz2
  3. [root@node1 ~]# cd Reusable-Cluster-Components-glue--0a7add1d9996/
  4. [root@node1 Reusable-Cluster-Components-glue--0a7add1d9996]# ./autogen.sh
  5. ]# ./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1' --with-daemon-user=hacluster --with-daemon-group=haclient
  6. #LIBS如果是32位系统自行更改
  7. ]# make && make install
  8.  
  9. resource agents
  10. [root@node1 ~]# tar xf resource-agents-3.9..tar.gz
  11. [root@node1 ~]# cd resource-agents-3.9.
  12. [root@node1 resource-agents-3.9.]# ./autogen.sh
  13. [root@node1 resource-agents-3.9.]# ./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1' --with-daemon-user=hacluster --with-daemon-group=haclient
  14. [root@node1 resource-agents-3.9.]# make && make install
  15.  
  16. heartbeat
  17. [root@node1 ~]# tar xf 958e11be8686.tar.bz2
  18. [root@node1 ~]# cd Heartbeat---958e11be8686/
  19. [root@node1 Heartbeat---958e11be8686]# ./bootstrap
  20. ]# ./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1' --with-daemon-user=hacluster --with-daemon-group=haclient
  21.  
  22. #编译报错,路径重复,google后得出删除 glue_config.h 中配置文件路径即可
  23. [root@node1 Heartbeat---958e11be8686]# make && make install
  24. ../include/config.h::: error: this is the location of the previous definition
  25. gmake[]: *** [strlcpy.lo] Error
  26. gmake[]: Leaving directory `/root/Heartbeat---958e11be8686/replace'
  27. make: *** [all-recursive] Error
  28.  
  29. [root@node1 Heartbeat---958e11be8686]# vim /usr/local/heartbeat/include/heartbeat/glue_config.h
  30. define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/"
  31. #删除最后一行即上行内容
  32.  

  5、复制配置文件至/etc//heartbeat/ha.d中

  1. [root@node1 Heartbeat---958e11be8686]# cp doc/ha.cf /etc/heartbeat/ha.d/
  2. [root@node1 Heartbeat---958e11be8686]# cp doc/haresources /etc/heartbeat/ha.d/
  3. [root@node1 Heartbeat---958e11be8686]# cp doc/authkeys /etc/heartbeat/ha.d/

  6、将heartbeat加入系统服务,并开机启动

  1. [root@node1 ~]# chkconfig --add heartbeat
  2. #之后可以用service来进行start|stop操作了
  3. [root@node1 ~]# chkconfig heartbeat on

7、修改认证文件权限为600,不然heartbeat无法工作

  1. [root@node1 ~]# chmod /etc/heartbeat/ha.d/authkeys

  8、为resource-agents建立脚本软连接

  1. [root@node1 ~]# ln -s /usr/local/heartbeat/usr/lib/ocf /usr/lib/ocf

四、配置文件

  1. 、配置authkeys文件,指明启用何种算法,使用何种密钥,本文件须更改权限为400
  2. auth
  3. # crc
  4. sha1 2SIEok+gXAvB6G4seA8mhw
  5. # md5 Hello!
  6.  
  7. 生成随机字符串作为密钥
  8. [root@node2 ~]# openssl rand -base64
  9. 2SIEok+gXAvB6G4seA8mhw==
  10.  
  11. 、配置ha.cf文件,定义高可用集群的基本工作方式
  12.  
  13. 定义日志文件位置(二选一) logfacility为将日志交由syslog管理
  14. logfile /var/log/ha-log
  15. #logfacility local0
  16. 多长时间发送一次心跳信息,默认为2
  17. #keepalive
  18. 多长时间宣布某节点死亡,默认30
  19. #deadtime
  20. 多长时间警告对方心跳信息延迟了,默认10
  21. #warntime
  22. 第一次死去时间,避免因网络问题导致宣布死亡
  23. #initdead
  24. 使用udp694端口传递心跳,并选择哪种方式传递心跳
  25. #udpport
  26. 串行线缆传递心跳
  27. #serial /dev/ttyS0 # Linux
  28. #serial /dev/cuaa0 # FreeBSD
  29. #serial /dev/cuad0 # FreeBSD .x
  30. #serial /dev/cua/a # Solaris
  31. 串行线缆的工作频率
  32. #baud
  33. 广播传递心跳
  34. #bcast eth0 # Linux
  35. #bcast eth1 eth2 # Linux
  36. #bcast le0 # Solaris
  37. #bcast le1 le2 # Solaris
  38. 多播传递心跳,网卡必须支持多播,ifconfig | grep MULTICAST
  39. mcast eth0 225.0.0.1 #端口694,TTL为1,不允许回传为0
  40. #启用网卡支持多播
  41. [root@node1 ha.d]# ip link set eth0 multicast on
  42.  
  43. 单薄传递心跳
  44. #ucast eth0 192.168.1.2
  45. 自动故障转回
  46. auto_failback on
  47. 指明节点
  48. #node ken3
  49. #node kathy
  50. node node1
  51. node node2
  52. 指明网关为ping node设备(仲裁设备)
  53. #ping 10.10.10.254
  54. ping 192.168.0.1
  55. 指明一个组为ping node设备(仲裁设备)
  56. #ping_group group1 10.10.10.254 10.10.10.253
  57. 指明节点间传送的压缩算法
  58. compression bz2
  59. 指明节点间传送数据压缩的最小数据为2KB
  60. compression_threshold
  61.  
  62. 、配置haresources文件,定义集群资源
  63. 直接加入资源
  64. node1 192.168.0.17//eth0/192.168.0.255 httpd
  65.  
  66. 、将httpd设置为开机不启动
  67. [root@node1 ha.d]# chkconfig httpd off
  68.  
  69. 、启动服务
  70. [root@node1 ~]# service heartbeat start

以上所有配置均所有节点一致

heartbeat 编译安装配置的更多相关文章

  1. haproxy1.7编译安装配置

    #haproxy1.7编译安装配置#高可用.负载均衡 使用 #haproxy1.7编译安装配置 #centos7 x86_64 #高可用.负载均衡 使用 #下载 #http://www.haproxy ...

  2. azkaban编译安装配置文档

    azkaban编译安装配置文档 参考官方文档: http://azkaban.github.io/azkaban/docs/latest/ azkaban的配置文件说明:http://azkaban. ...

  3. Visual Studio 2015编译安装配置QT5.5.1(含QTWEBKIT)

    尽管QT5.5.1和VisualStudio 2015都已经发布很久了,但是QT项目组视乎不会为QT5.5.1专门发布预编译的QT5.5.1 for windows(2015)版本的,也不会专门发布V ...

  4. blfs(systemd版本)学习笔记-编译安装配置dhcpcd

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! dhcpcd项目地址:http://www.linuxfromscratch.org/blfs/view/stable-syst ...

  5. blfs(systemv版本)学习笔记-编译安装配置dhcpcd

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! dhcpcd项目地址:http://www.linuxfromscratch.org/blfs/view/8.3/basicne ...

  6. cloudera impala编译 安装 配置 启动

    无论是采用GDB调试impala或者尝试修改impala源码,前提都是需要本地环境编译impala,这篇文章详细的分享一下impala编译方法以及编译过程遇到的棘手的问题: 前言: impala官方的 ...

  7. CentOS 7.4下源码编译安装配置LAMP环境详解

    CentOS 7.4搭建LAMP,LAMP:Linux.Apache.MySQL.PHP. 目录:第一部分 准备工作第二部分 安装Apache服务第三部分 安装MySQL服务第四部分 搭建PHP运行环 ...

  8. Linux下编译安装配置MariaDB数据库

    说明:操作系统:CentOS 6.6  64位MariaDB版本:mariadb-5.5.33aMariaDB数据库存放目录:/data/mysql准备:一.配置防火墙,开启3306端口vi /etc ...

  9. 安装Hadoop系列 — eclipse plugin插件编译安装配置

    [一].环境参数 eclipse-java-kepler-SR2-linux-gtk-x86_64.tar.gz //现在改为eclipse-jee-kepler-SR2-linux-gtk-x86_ ...

随机推荐

  1. Aggregate (GROUP BY) Function Descriptions

    w Table 13.25 Aggregate (GROUP BY) Functions Name Description AVG() Return the average value of the ...

  2. VMwareWorkstation与Device/CredentialGuard不兼容

    win10的虚拟与VMware Workstation的虚拟有冲突,需要关闭win10自带的虚拟Hyper-V功能. 1.Windows键 --- 设置 --- 搜索 “控制面板” --- 程序  - ...

  3. Junit 3.8.1 源码分析之两个接口

    1. Junit源码文件说明 runner framework:整体框架; extensions:可以对程序进行扩展; textui:JUnit运行时的入口程序以及程序结果的呈现方式; awtui:J ...

  4. HDFS分布式集群安装

    HDFS集群安装: 1.准备工作 虚拟机(电脑8G内存 磁盘500GB) 3台 linux系统(1台namenode 2台datanode) (1)关闭防火墙 firewall-cmd --state ...

  5. Secure Sockets Layer(安全套接层)

    SSL SSL(Secure Sockets Layer安全套接层)及其继任者传输层安全(Transport Layer Security,TLS)是为网络通信提供安全及数据完整性的一种安全协议.TL ...

  6. UVA Team Queue

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013840081/article/details/26180081 题目例如以下: Team Qu ...

  7. 出现 Request Entity Too Large问题的解决方法

    根据经验判断应该是上传文件大小被限制了,检查了应用配置是10M,把它设置成100M,重启服务也不能解决问题. 原来我们的tomcat是通过nginx发现服务代理的,问题就出现nginx服务器上,原来n ...

  8. UVA10341:Solve It(二分+math.h库)

    题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/E 题目要求:p*e-x+ q*sin(x) + r*co ...

  9. HDU1003:Max Sum(简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1003 题意一目了然就不说了,算法是从左往右扫,一个暂时保存结果的值,如果区间结果<0,那么就更改左右 ...

  10. 20165324 Java实验三 敏捷开发与XP实验

    20165324 Java实验三 敏捷开发与XP实验 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:何春江 学号:20165324 指导教师:娄嘉鹏 实验日期:2018年4月16日 ...