복붙노트

[REDIS] resque 장애 조치 레디 스를위한 솔루션

REDIS

resque 장애 조치 레디 스를위한 솔루션

클러스터 레디 스의 작품에 여전히 있기 때문에, 자동으로 주인이 지금까지 내려 가서해야 레디 스 슬레이브로 장애 조치됩니다 Resque에서이 메커니즘은 무엇입니까?

해결법

  1. ==============================

    1.그렇게 생각하지 않아요. 그러나 아파치 사육사를 사용하여 마스터 선거 메커니즘 아주 쉽게 자신을 구현할 수 있습니다 :

    그렇게 생각하지 않아요. 그러나 아파치 사육사를 사용하여 마스터 선거 메커니즘 아주 쉽게 자신을 구현할 수 있습니다 :

    require "rubygems"
    require "zookeeper"
    
    def log(msg)
      puts "[#{Process.pid}] #{msg}"
    end
    
    def debug(obj)
      log(obj.inspect)
    end
    
    def on_master_changed(&block)
      loop do
        wcb = Zookeeper::WatcherCallback.new
        resp = @zookeeper.get_children(:path => @base_path, :watcher => wcb, :watcher_context => @base_path)
        children = resp[:children].map{|name| "#{@base_path}/#{name}"}
        new_master = children.sort.first
    
        block.call(new_master)
    
        while !wcb.completed?
          sleep(0.1)
        end
      end
    end
    
    @zookeeper = Zookeeper.new("localhost:2181")
    
    if @zookeeper.state != Zookeeper::ZOO_CONNECTED_STATE
      log 'Unable to connect to Zookeeper!'
      exit(1)
    end
    
    @base_path = "/nodes"
    
    @zookeeper.create(:path => @base_path)
    resp = @zookeeper.create(:path => "#{@base_path}/node-", :ephemeral => true, :sequence => true, :data => Process.pid.to_s)
    my_node = resp[:path]
    is_master = false
    
    log "My node is: #{my_node}"
    
    on_master_changed do |new_master|
      if new_master == my_node
        if is_master
          log "I am still the master. Bow before me or die!"
        else
          log "I am the new master. Behold!"
        end
        is_master = true
      else
        pid = @zookeeper.get(:path => new_master)[:data]
        log "New master is process #{pid}"
      end
    end
    

    당신은 위의 스크립트를 수정할 수 있습니다 :

  2. ==============================

    2.나는 사육사와 루비 레디 스 페일 오버를 제공하는 redis_failover 보석을 발표했습니다 :

    나는 사육사와 루비 레디 스 페일 오버를 제공하는 redis_failover 보석을 발표했습니다 :

    https://github.com/ryanlecompte/redis_failover

  3. from https://stackoverflow.com/questions/7759572/solutions-for-resque-failover-redis by cc-by-sa and MIT license