zoukankan      html  css  js  c++  java
  • 采用heartbeat做Redis的主从切换

    一、准备

    1.redis的主从准备

       192.168.81.132(hadoop1) 主

       192.168.81.130(hadoop2)从

    2.heartbeat安装(主从都需要)

    二、配置

    1.Master配置

     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/

    <1 vim /etc/ha.d/ha.cf

    debugfile /var/log/ha-debug --debug日志
    logfile /var/log/ha-log --日志
    logfacility     local0 --日志设备
    keepalive 2 --心跳时间
    deadtime 30 --心跳死亡时间,也就是说多少秒收不到心跳认为死亡
    warntime 10 --收不到心跳后多少秒,会在日志里写入一个警告,必须小于deadtime
    initdead 120
    udpport 694 --端口
    ucast eth0 192.168.81.130
    auto_failback on --slave接管了服务,master重新启动后,会自动再次接管服务成为master
    node    hadoop1
    node    hadoop2 --master和slave的主机名
    ping_group group1 192.168.81.1 192.168.81.130
    respawn hacluster /usr/lib/heartbeat/ipfail
    apiauth ipfail gid=haclient uid=hacluster

    <2.vim /etc/ha.d/authkeys

       auth 1 --表示使用第一种认证方式
       1 crc

    chmod 600 /etc/ha.d/authkeys

    <3.vim /etc/ha.d/haresources 

    hadoop1 IPaddr::192.168.81.100/24/eth0:0 redisd

    2.slave配置

     scp /etc/ha.d/ha.cf hadoop2:/etc/ha.d/
     scp /etc/ha.d/authkeys hadoop2:/etc/ha.d/
     scp /etc/ha.d/haresources hadoop2:/etc/ha.d/

    <1.vim /etc/ha.d/ha.cf

    ucast eth0 192.168.81.130

    chmod 600 /etc/ha.d/authkeys

    三、测试

    1.主从都启动 /etc/init.d/heartbeat   start

    2.查看是否获取到浮动IP eth0:0 192.168.81.100

    3.将主的网络停止,测试slave是否接管

    4., 手工进行资源的切换
    #/usr/lib/heartbeat/hb_standby   --手工把资源让给另一台
    #/usr/lib/heartbeat/hb_takeover --手工把资源从另一台抢过来

    四、备注

    vim /etc/ha.d/haresources 

    hadoop1 IPaddr::192.168.81.100/24/eth0:0 redisd

    redisd脚本自定义如下:

    #!/bin/sh 
    #chkconfig: 345 86 14 
    #description: Startup and shutdown script for Redis   
    
    PROGDIR=/home/hadoop/source/redis-2.8.7/src
    PROGNAME=redis-server 
    DAEMON=$PROGDIR/$PROGNAME 
    CONFIG=/home/hadoop/source/redis-2.8.7/redis.conf 
    PIDFILE=/var/run/redis.pid 
    DESC="redis daemon" 
    SCRIPTNAME=/etc/init.d/redisd   
    
    start()
    
    { 
    
             if test -x $DAEMON 
    
             then 
    
            echo -e "Starting $DESC: $PROGNAME" 
    
                       if $DAEMON $CONFIG 
    
                       then 
    
                                echo -e "OK" 
    
                       else 
    
                                echo -e "failed" 
    
                       fi 
    
             else 
    
                       echo -e "Couldn't find Redis Server ($DAEMON)" 
    
             fi 
    
    } 
    
      
    
    stop() 
    
    { 
    
             if test -e $PIDFILE 
    
             then 
    
                       echo -e "Stopping $DESC: $PROGNAME" 
    
                       if kill `cat $PIDFILE` 
    
                       then 
    
                                echo -e "OK" 
    
                       else 
    
                                echo -e "failed" 
    
                       fi 
    
             else 
    
                       echo -e "No Redis Server ($DAEMON) running" 
    
             fi 
    
    } 
    
      
    
    restart() 
    
    { 
    
        echo -e "Restarting $DESC: $PROGNAME" 
    
        stop 
    
             start 
    
    } 
    
      
    
    list() 
    
    { 
    
             ps aux | grep $PROGNAME 
    
    } 
    
      
    
    case $1 in 
    
             start) 
    
                       start 
    
            ;; 
    
             stop) 
    
            stop 
    
            ;; 
    
             restart) 
    
            restart 
    
            ;; 
    
             list) 
    
            list 
    
            ;; 
    
      
    
             *) 
    
            echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2 
    
            exit 1 
    
            ;; 
    
    esac  
    
    exit 0

     redis.conf的bind 注释

     应用系统链接地址为

    protected static RedisClient Redis_Write = new RedisClient("192.168.81.100", 6379);//redis服务IP和端口

  • 相关阅读:
    介绍本近期出的好书《软件调试》
    【转贴】Ogre的官僚主义批判
    Module切换,如何实现loading效果
    cacheAsBitmap = ‘true' 可以降低cpu,提高效率?
    设相对布局,则x,y更改无效 horizontalCenter="0" verticalCenter="120"
    flex 1119错误 找不到属性 static 解决方法,编译选项中选中 不启用rsl
    as3的get,set方法实现
    flex的Release编译会把trace也编译进去,
    Alert按钮的事件侦听
    一天编程发现的css名称问题,不支持下划线
  • 原文地址:https://www.cnblogs.com/bobsoft/p/3650115.html
Copyright © 2011-2022 走看看