红色多瑙河 发表于 2019-1-6 14:35:35

heartbeat 安装使用

  Hearbeat 软件未来发展说明(2.1.4以后):
hearbeat                   群集消息层负责维护集群各节点间的相互通信及基本信息cluster glue               中间层负责调度,包括两个模块:本地资源管理和stonith  resource agents       资源代理层         

实现各种资源的启动、停止、监控等  (pacemaker)资料待补充!
  

  生产场景(主要是为了解决单点):
  1、四层:前端负载均衡器,配合lvs (keeplived有区别的)。
  注意是:hearbeat +lvs + ldirectord(健康检查)
  2、七层:配合haporxy、nginx,负载ip漂移!

  3、配合数据库主库的高可用。

  4、存储的高可用,比如nfs网络文件存储系统。

  5、单点的分布式文件系统。

  

  实验准备: 虚拟机两台;配置各自的vip ;(虚拟网卡模拟直连)
  网卡三块:eth0 外网eth1 内网管理ipeth2 用于服务器心跳 ;vip 应用程序挂载服务。
  配置hosts,ping 测试;
  添加心跳路由: route add -host 10.0.10.22 dev eth2
                 提示:防火墙一定要关闭,成败关键!

  

  安装:
  1、下载软件包:
  

        提示:普通的yum源无此软件
使用epel源安装:
wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm   #注意epel源使用和系统相同版本
rpm -qa |grep epel
安装heartbeat
yum install heartbeat* -y
  提示:
  yum 源跟新网址:http://mirrors.aliyun.com/help/centos
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  yum缓存保留修改设置:
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
  

2、安装检查rpm -aq heartbeat3、启动文件/etc/init.d/heartbeat       #脚本文件
4、配置目录/etc/ha.d/
  5、服务资源
  控制目录
/etc/ha.d/resource.d/       #可以放到init.d
(脚本文件)
  6、 核心配置 文件
ha.cf (参数配置文件) :基本参数
authkey(认证文件)   :高可用服务器之间根据对端的authkey,对对端认证harresource(资源配置文件):配置启动ip资源及脚本程序,服务等
提示:配置文件模版 路径:   /usr/share/doc/heartbeat-3.0.4/                                              # 文件包括:haresources、ha.cf、authkeys
  

配置文件ha.cf配置 说明:  生产配置范例(/etc/ha.d/ha.cf):
#the start by kong 2015/7/5
debugfile /var/log/ha-debug
logfile/var/log/ha-log
logfacilitylocal1
keepalive 2
deadtime 30
warntime 10
initdead 60
#bcasteth1
mcast eth2 225.0.0.7 694 1 0
auto_failback on
node A
node B
crmno
#the end by kong  #提示两台主机heartbaet 配置时相同的
  

  debugfile /var/log/ha-debug
heartbeat 调试日志存放位置       #24 行logfile /var/log/ha-log普通log                                       # 29 行logfacility local0在syslog服务中配置通过locall设备接收日志      #34 行  keepalive2
  (心跳间隔时间)
  指定心跳间隔时间为2秒(即每2秒在eth1上发一次广播)   # 48 行
  deadtime30
  (宣布死亡时间)
指定若备用节点在30秒内没有收到主节点的心跳信号,则立即接管主节点的资源服务                           # 56 行  wamtime10
  (警告延迟时间)
指定心跳延迟的时间为10秒。当10秒钟内备份节点不能接收到主节点的心跳信号时,就会往日志中写入一个警告日志,但此时不会切换服务  initdead    120
  (初始化死亡时间)
  指定在 HEARTBEAT 首次运行后,需要等待120秒才启动主服务器的任何资源。该选项用于解决这种情况产生的时间间隔。取值至少
  为deadtime的两倍。单机启动时会遇到vip绑定慢,为正常现象。该值设置长的原因。
  #bcast eth1
  (广播方式)
  指明心跳使用以太网广播方式在eth1接口上进行广播。如使用两个实际网络传送心跳则 #bcast eth0 eth1
  mcast eth2255.0.0.1 694 1 0   (多播)
  设置广播通信使用的端口,694 为默认使用端口 ;
  eth2 设备
  255.0.0.1 地址
auto failback on#用来定义当主节点回复后,是否将服务自动切回。 |建议人工nodehostname#主节点主机名 。使用uname -n 查看nodehostname2#备用节点主机名。crm no是否开启集群资源管理功能
  

  配置文件/etc/ha.d/authkeys配置说明:
  #如下为默认配置文件
#
#Authentication file.Must be mode 600
#      提示:authkey权限必须为600
#
#Must have exactly one auth directive at the front.
#authsend authentication using this method-id
#
#Then, list the method and key that go with that method-id
#
#Available methods: crc sha1, md5.Crc doesn't need/want a key.
#       提示:可以设置的认证方法 ,总计有三类
#You normally only have one authentication method-id listed in this file
#
#Put more than one to make a smooth transition when changing auth
#methods and/or keys.
#
#
#sha1 is believed to be the "best", md5 next best.
#   提示:sha1的方式是最好的
#crc adds no security, except from packet corruption.
#Use only on physically secure networks.
#
#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
#默认是crc方法,这是不加密的,不够安全
生成方法:# echo kong|sha1sum   # 用的sha1
5e1d19b4602d90f43ab23a1470bb3d3a8939799a-
  编辑配置文件:
  提示:两台机器配置相同
# cat authkeys
auth 1
1 sha1 5e1d19b4602d90f43ab23a1470bb3d3a8939799a
# chmod 600 authkeys
  

配置文件/etc/ha.d/haresource配置说明(两台配置相同):
  生产配置
  范例:
# cat haresources
#kong services
A   IPaddr::10.0.0.18/24/eth0
B   IPaddr::10.0.0.19/24/eth0

#A 为主机名,表示初始状态会在A绑定ip 10.0.0.17#IPaddr为heartbeat 配置ip的默认脚本,其后的ip等都是脚本的参数 #10.0.0.17/24 eth0  #为集群对外服务的vip,初始启动在A 上;
  #24为子网掩码;
  #eth0为ip绑定的实际物理网卡,为heartbeat提供对外服务的通信接口
         更多说明:  来自 Mysql+drdb+Heartbeat 文档
  

http://s3.运维网.com/wyfs02/M02/6F/57/wKiom1WZTFvBlINiAAONLLuubpw543.jpg
文件分析  haresource:
  data-1-2 kong::test abc:test:ab   shipeng
  分析:data-1-2 优先启动脚本:
  /etc/ha.d/resource.d/kong test start
  /etc/ha.d/resource.d/abc test ab start
  /etc/ha.d/resource.d/shipeng start
  放到haresource下面的内容都要支持 /etc/ha.d/resource.d/shipeng start/stop这样的控制模式。
  

  

  启动服务
# /etc/init.d/heartbeatstrat
Usage: /etc/init.d/heartbeat {start|stop|status|restart|reload|force-reload}
# /etc/init.d/heartbeatstart
Starting High-Availability services: INFO:Resource is stopped
INFO:Resource is stopped
Done.  服务器 A :


vip检查:
# ip addr |grep -E "10.0.0.19|10.0.0.18"
    inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0

服务器 B :
# ip a|grep -E "10.0.0.18|10.0.0.19"
    inet 10.0.0.19/24 brd 10.0.0.255 scope global secondary eth0

  关停其中一台(B):
  vip检查:
# ip addr |grep -E "10.0.0.19|10.0.0.18"
    inet 10.0.0.18/24 brd 10.0.0.255 scope global secondary eth0
    inet 10.0.0.19/24 brd 10.0.0.255 scope global secondary eth0

提示:防火墙切记关闭
  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  




页: [1]
查看完整版本: heartbeat 安装使用