注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

曾国藩的博客

 
 
 

日志

 
 

Heartbeat apache 通过心跳实现双机高可用  

2013-05-23 16:21:59|  分类: 网络/系统架构/版 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://blog.sina.com.cn/s/blog_75d63f000101c7lp.html

  1. Heartbeat+apache实战环境部署

    测试环境
    Mastereth0:192.168.142.129 eth1:10.0.0.2
    eth1心跳用)
    Backupeth0:192.168.142.130 eth1:10.0.0.3
    eth1心跳用)
    VIP
    192.168.142.131


    A:Master

     

    vi /etc/sysconfig/network


    NETWORKING=yes
    NETWORKING_IPV6=no
    HOSTNAME=master

    cat /etc/hosts
    127.0.0.1  localhost.localdomain localhost
    ::1 localhost6.localdomain6 localhost6
    192.168.142.129 node01
    192.168.142.130 node02

     

    reboot

     

    uname –n

     

    yum –y install PyXML


    注意安装顺序不可以颠倒

     

    rpm -ivh heartbeat-pils-2.1.3-3.el5.centos.x86_64.rpm

    rpm -ivh heartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpm

    rpm -ivh heartbeat-2.1.3-3.el5.centos.x86_64.rpm 

     

    或者通过yum来安装:

    yum -y install PyXML

    yum -y install heartbeat-pils

    yum -y install heartbeat-stonith

    yum -y install heartbeat

    cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/              //主配置文件

    cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/           //认证文件

    cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/      //资源管理的配置

    chmod 600 /etc/ha.d/authkeys

    sed -n '/^#/!p' /etc/ha.d/ha.cf //修改以下几处(这里没考虑优化,只是简单的功能实现)

    vim /etc/ha.d/ha.cf
    logfile /var/log/ha-log
    logfacility local0
    keepalive 2
    deadtime 30
    warntime 10
    initdead 120
    udpport 694
    bcast eth1 # Linux  //
    心跳网卡
    ucast eth1 10.0.0.3 //
    心跳网卡连接对方心跳地址
    auto_failback on
    node node01
    node node02

    本人建议这样写,如下vim /etc/ha.d/ha.cf 

    logfile /var/log/ha-log

    node node01

    node node02

    keepalive 1

    deadtime 6

    watchdog /dev/watchdog

    udpport 6996

    ucast eth1 10.0.0.3

    auto_failback off

    ping 192.168.142.1 //检测全网是否连通

    sed -n '/^#/!p' /etc/ha.d/authkeys //采用crc认证(对系统资源要求最小)

    vim /etc/ha.d/authkeys
    auth 1
    1 crc

    sed -n '/^#/!p' /etc/ha.d/haresources //这里只设置VIP和开启apache

    vim /etc/ha.d/haresources
    node01 192.168.142.131 httpd 
    建议这样写node01 IPaddr::192.168.142.131/24/eth0

    B:Backup

    vi /etc/sysconfig/network

    NETWORKING=yes
    NETWORKING_IPV6=no
    HOSTNAME=backup

    cat /etc/hosts
    127.0.0.1 node02 localhost.localdomain localhost
    ::1 localhost6.localdomain6 localhost6
    192.168.142.129 node01
    192.168.142.130 node02

    reboot

    uname -n
    Backup
    安装配置方法同master

    vim /etc/ha.d/ha.cf

    sed -n '/^#/!p' /etc/ha.d/ha.cf同上
    logfile /var/log/ha-log
    logfacility local0
    keepalive 2
    deadtime 30
    warntime 10
    initdead 120
    udpport 694
    bcast eth1 # Linux
    ucast eth1 10.0.0.2 //
    心跳网卡连接对方心跳地址
    auto_failback on
    node node01
    node node02

    ping 192.168.142.1

    建议这样写:

    logfile /var/log/ha-log

    node node01

    node node02

    keepalive 1

    deadtime 6

    watchdog /dev/watchdog

    udpport 6996

    ucast eth1 10.0.0.2

    auto_failback off

     

    sed -n '/^#/!p' /etc/ha.d/authkeys //采用crc认证(对系统资源要求最小)
    vim /etc/ha.d/authkeys

    auth 1
    1 crc

    sed -n '/^#/!p' /etc/ha.d/haresources  //这里只设置VIP和开启apache

    vim /etc/ha.d/haresources
    node01 192.168.142.131 httpd //
    注意这里书写的master必须要和master节点的相同(建议写成如下)

    node01 IPaddr::192.168.142.131/24/eth0


    测试

    yum -y install httpd

    service httpd restart

    echo "This 192.168.142.129 master web">/var/www/html/index.html   

    master httpd测试页

    echo "This 192.168.142.130 backup web">/var/www/html/index.html

    backup httpd测试页

    service iptables stop
    双节点均开启heartbeta

    service heartbeat start|stop

    ps -aux |grep heartbeat|xargs kill -9 杀掉所有进程

    ping 10.0.0.3master操作

    ping 10.0.0.2backup操作

    ip add master操作,会有如下结果,但是在backup上操作不会有VIP出现
    1: lo: mtu 16436 qdisc noqueue 
    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: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:f2:51:1c brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.129/24 brd 192.168.142.255 scope global eth0
    inet 192.168.142.131/24 brd 192.168.142.255 scope global secondary eth0:0
    inet6 fe80::20c:29ff:fef2:511c/64 scope link 
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:f2:51:26 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.2/8 brd 10.255.255.255 scope global eth1
    inet6 fe80::20c:29ff:fef2:5126/64 scope link 
    valid_lft forever preferred_lft forever
    4: sit0: mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0 
    IE
    打开测试,输入VIP 192.168.142.131,结果如下
      

    Heartbeat apache 通过心跳实现双机高可用 - 曾国藩 - 曾国藩的博客
     

    service heartbeat stop 停止masterheartbeat


  2. Heartbeat apache 通过心跳实现双机高可用 - 曾国藩 - 曾国藩的博客
     
  3. ip add此时在backup节点操作,会出现VIP
    1: lo: mtu 16436 qdisc noqueue 
    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: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:da:ef:9a brd ff:ff:ff:ff:ff:ff
    inet 192.168.142.130/24 brd 192.168.142.255 scope global eth0
    inet 192.168.142.131/24 brd 192.168.142.255 scope global secondary eth0:0
    inet6 fe80::20c:29ff:feda:ef9a/64 scope link 
    valid_lft forever preferred_lft forever
    3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:da:ef:a4 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.3/8 brd 10.255.255.255 scope global eth1
    inet6 fe80::20c:29ff:feda:efa4/64 scope link 
    valid_lft forever preferred_lft forever
    4: sit0: mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
    同时你ping VIP一直不会断
    当启动master节点的heartbeat服务时,backup VIP会自动消失,VIP会切换到最初状态 
    测试完成! 

  4.  

  评论这张
 
阅读(721)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018