设为首页 收藏本站
查看: 1212|回复: 0

[经验分享] Heartbeat安装与配置

[复制链接]
累计签到:5 天
连续签到:1 天
发表于 2015-11-21 12:39:36 | 显示全部楼层 |阅读模式
1、环境描述

  服务器A(主) 192.85.1.175
  服务器B(从) 192.85.1.176
  Mysql版本:5.1.61
  系统版本:System OS:ubuntu 10.10 X86
2.安装heartbeat

  1)安装heartbeat
  

     sudo apt-get install heartbeat
  
  2)配置说明
  heartbeat的安装目录为/etc/ha.d目录下,
  安装完成后,需要三个配置文件,为 ha.cf,haresources,authkeys。
  此时目录下没有这三个文件,需要创建,我们可以在
  /usr/share/doc/heartbeat目录里找到ha.cf、haresources、authkeys三个文件,只需将其拷贝到
  /etc/ha.d目录下,即可
  *.gz文件,使用 gunzip 命令解压
3.175服务器配置信息:

  (1)etc/hosts 文件内容:
  

192.85.1.175    primary # Added by NetworkManager
  
  (2)ha.cf 文件内容:(主配置文件)
  

#
#There are lots of options in this file.  All you have to have is a set
#of nodes listed {"node ...} one of {serial, bcast, mcast, or ucast},
#and a value for "auto_failback".
#
#ATTENTION: As the configuration file is read line by line,
#   THE ORDER OF DIRECTIVE MATTERS!
#
#In particular, make sure that the udpport, serial baud rate
#etc. are set before the heartbeat media are defined!
#debug and log file directives go into effect when they
#are encountered.
#
#All will be fine if you keep them ordered as in this example.
#
#
#       Note on logging:
#       If all of debugfile, logfile and logfacility are not defined,
#       logging is the same as use_logd yes. In other case, they are
#       respectively effective. if detering the logging to syslog,
#       logfacility must be "none".
#
#File to write debug messages to
debugfile /var/log/ha-debug  #调试日志文件
#
#
# File to write other messages to
#
logfile/var/log/ha-log  #系统运行日志文件
#
#
#Facility to use for syslog()/logger
#
logfacilitylocal0   # 日志记录等级
#
#
#A note on specifying "how long" times below...
#
#The default time unit is seconds
#10 means ten seconds
#
#You can also specify them in milliseconds
#1500ms means 1.5 seconds
#
#
#keepalive: how long between heartbeats?
#
keepalive 2  #心跳频率,2表示2秒;200ms则表示200毫秒
#
#deadtime: how long-to-declare-host-dead?
#
#If you set this too low you will get the problematic
#split-brain (or cluster partition) problem.
#See the FAQ for how to use warntime to tune deadtime.
#
deadtime 30  #节点死亡时间,就是过了10秒后还没有收到心跳就认为主节点死亡
#
#warntime: how long before issuing "late heartbeat" warning?
#See the FAQ for how to use warntime to tune deadtime.
#
warntime 10   #告警时间
#
#
#Very first dead time (initdead)
#
#On some machines/OSes, etc. the network takes a while to come up
#and start working right after you've been rebooted.  As a result
#we have a separate dead time for when things first come up.
#It should be at least twice the normal dead time.
#
initdead 120 #初始化时间
#
#
#What UDP port to use for bcast/ucast communication?
#
udpport694  #心跳信息传递的udp端口
#
#What interfaces to broadcast heartbeats over?
#
bcasteth0# Linux  #采用udp广播播来通知心跳,建议在备用节点不只一台时使用
#bcasteth1 eth2# Linux
#bcastle0# Solaris
#bcastle1 le2# Solaris
#
#Set up a multicast heartbeat medium
#mcast [dev] [mcast group] [port] [ttl] [loop]
#
#[dev]device to send/rcv heartbeats on
#[mcast group]multicast group to join (class D multicast address
#224.0.0.0 - 239.255.255.255)
#[port]udp port to sendto/rcvfrom (set this value to the
#same value as "udpport" above)
#[ttl]the ttl value for outbound heartbeats.  this effects
#how far the multicast packet will propagate.  (0-255)
#Must be greater than zero.
#[loop]toggles loopback for outbound multicast heartbeats.
#if enabled, an outbound packet will be looped back and
#received by the interface it was sent on. (0 or 1)
#Set this value to zero.
#
#
#bcast eth0 225.0.0.1 694 1 0
#
#Set up a unicast / udp heartbeat medium
#ucast [dev] [peer-ip-addr]
#
#[dev]device to send/rcv heartbeats on
#[peer-ip-addr]IP address of peer to send packets to
#
ucast eth0 192.85.1.175
auto_failback on  #如果主节点重新恢复过来,主节点将主动将资源抢占过来,如果为off,则只当备用节点当掉后,主节点才取回资源
watchdog /dev/watchdog  #看门狗。如果本节点在超过1分钟后还没有发出心跳,那么本节点自动重启
#      
#Tell what machines are in the cluster
#nodenodename ...-- must match uname -n
node primary #主节点名称,与uname -n显示必须一致
node backup #备用节点名称
#
#Less common options...
#
#Treats 10.10.10.254 as a psuedo-cluster-member
#Used together with ipfail below...
#note: don't use a cluster node as ping node
#
ping 192.85.1.1 #通过ping网关来监测心跳是否正常

  
  (3) haresources  (资源配置文件)
  

primary   192.85.1.177/24http,mysql,phpmyadmin  #虚拟IP配置及对应的访问资源配置


  
  (4) authkeys (认证信息配置文件)
  #通讯密钥,两台机器上的文件内容必须完全一致

auth 3
3 md5 Hello
  #authkeys需要设置读写权限:chmod 600 ./authkeys
  
4.176服务器配置信息:

  (1)etc/hosts 文件内容:
  

192.85.1.176    backup # Added by NetworkManager
  
  (2)ha.cf 文件内容:

#
#There are lots of options in this file.  All you have to have is a set
#of nodes listed {"node ...} one of {serial, bcast, mcast, or ucast},
#and a value for "auto_failback".
#
#ATTENTION: As the configuration file is read line by line,
#   THE ORDER OF DIRECTIVE MATTERS!
#
#In particular, make sure that the udpport, serial baud rate
#etc. are set before the heartbeat media are defined!
#debug and log file directives go into effect when they
#are encountered.
#
#All will be fine if you keep them ordered as in this example.
#
#
#       Note on logging:
#       If all of debugfile, logfile and logfacility are not defined,
#       logging is the same as use_logd yes. In other case, they are
#       respectively effective. if detering the logging to syslog,
#       logfacility must be "none".
#
#File to write debug messages to
debugfile /var/log/ha-debug  #调试日志文件
#
#
# File to write other messages to
#
logfile/var/log/ha-log  #系统运行日志文件
#
#
#Facility to use for syslog()/logger
#
logfacilitylocal0   # 日志记录等级
#
#
#A note on specifying "how long" times below...
#
#The default time unit is seconds
#10 means ten seconds
#
#You can also specify them in milliseconds
#1500ms means 1.5 seconds
#
#
#keepalive: how long between heartbeats?
#
keepalive 2  #心跳频率,2表示2秒;200ms则表示200毫秒
#
#deadtime: how long-to-declare-host-dead?
#
#If you set this too low you will get the problematic
#split-brain (or cluster partition) problem.
#See the FAQ for how to use warntime to tune deadtime.
#
deadtime 30  #节点死亡时间,就是过了10秒后还没有收到心跳就认为主节点死亡
#
#warntime: how long before issuing "late heartbeat" warning?
#See the FAQ for how to use warntime to tune deadtime.
#
warntime 10   #告警时间
#
#
#Very first dead time (initdead)
#
#On some machines/OSes, etc. the network takes a while to come up
#and start working right after you've been rebooted.  As a result
#we have a separate dead time for when things first come up.
#It should be at least twice the normal dead time.
#
initdead 120 #初始化时间
#
#
#What UDP port to use for bcast/ucast communication?
#
udpport694  #心跳信息传递的udp端口
#
#What interfaces to broadcast heartbeats over?
#
bcasteth0# Linux  #采用udp广播播来通知心跳,建议在备用节点不只一台时使用
#bcasteth1 eth2# Linux
#bcastle0# Solaris
#bcastle1 le2# Solaris
#
#Set up a multicast heartbeat medium
#mcast [dev] [mcast group] [port] [ttl] [loop]
#
#[dev]device to send/rcv heartbeats on
#[mcast group]multicast group to join (class D multicast address
#224.0.0.0 - 239.255.255.255)
#[port]udp port to sendto/rcvfrom (set this value to the
#same value as "udpport" above)
#[ttl]the ttl value for outbound heartbeats.  this effects
#how far the multicast packet will propagate.  (0-255)
#Must be greater than zero.
#[loop]toggles loopback for outbound multicast heartbeats.
#if enabled, an outbound packet will be looped back and
#received by the interface it was sent on. (0 or 1)
#Set this value to zero.
#
#
#bcast eth0 225.0.0.1 694 1 0
#
#Set up a unicast / udp heartbeat medium
#ucast [dev] [peer-ip-addr]
#
#[dev]device to send/rcv heartbeats on
#[peer-ip-addr]IP address of peer to send packets to
#
ucast eth0 192.85.1.176
auto_failback on  #如果主节点重新恢复过来,主节点将主动将资源抢占过来,如果为off,则只当备用节点当掉后,主节点才取回资源
watchdog /dev/watchdog  #看门狗。如果本节点在超过1分钟后还没有发出心跳,那么本节点自动重启
#      
#Tell what machines are in the cluster
#nodenodename ...-- must match uname -n
node primary #主节点名称,与uname -n显示必须一致
node backup #备用节点名称
#
#Less common options...
#
#Treats 10.10.10.254 as a psuedo-cluster-member
#Used together with ipfail below...
#note: don't use a cluster node as ping node
#
ping 192.85.1.1 #通过ping网关来监测心跳是否正常

  (3) haresources
  

primary   192.85.1.177/24http,mysql,phpmyadmin   #虚拟IP配置及对应的访问资源配置  
  (4) authkeys
  #通讯密钥,两台机器上的文件内容必须完全一致

auth 3
3 md5 Hello
  #authkeys需要设置读写权限:chmod 600 ./authkeys
  
5.HA服务的启动、关闭以及测试

  启动HA: service heartbeat start  或  /etc/init.d/heartbeat


  关闭HA; service heartbeat stop  或  /etc/init.d/heartbeat


  系统在启动时已经自动把heartbeat加载了。
  使用http服务测试 heartbeat
  首先启动httpd服务
  #service httpd start
  编辑各自主机的测试用html文件,放到/var/www/html/目录下。
  启动node1的heartbeat,并执行这个指令进行监控: heartbeat status
  例如直接使用  http://192.85.1.177/phpmyadmin  ,可以登录管理数据库

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-141816-1-1.html 上篇帖子: Heartbeat+Mon简单测试- 下篇帖子: CentOS5.5下Heartbeat+LVS(VS/DR)+Ldirectord 分步骤实验
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表