Skip to content
Browse files

Initial commit with README.

  • Loading branch information...
1 parent 03898dc commit bb6a0f3212d6698904a9defe6f09faaa9b1b3d08 @swhitt committed
View
3 .gitignore
@@ -16,3 +16,6 @@ tmp
.yardoc
_yardoc
doc/
+
+.DS_Store
+.vagrant
View
4 Gemfile
@@ -0,0 +1,4 @@
+# A sample Gemfile
+source "https://rubygems.org"
+
+gem "redis_failover"
View
29 Gemfile.lock
@@ -0,0 +1,29 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ backports (2.5.3)
+ little-plugger (1.1.3)
+ logging (1.7.2)
+ little-plugger (>= 1.1.3)
+ multi_json (1.3.6)
+ redis (3.0.1)
+ redis-namespace (1.2.0)
+ redis (~> 3.0.0)
+ redis_failover (0.8.7)
+ multi_json (~> 1)
+ redis (~> 3)
+ redis-namespace
+ zk (~> 1.6)
+ zk (1.6.3)
+ backports (~> 2.5.1)
+ logging (~> 1.7.2)
+ zookeeper (~> 1.2.4)
+ zookeeper (1.2.10)
+ backports (~> 2.5.1)
+ logging (~> 1.7.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ redis_failover
51 README.md
@@ -1,2 +1,51 @@
redis-failover-test
-===================
+===================
+
+This setup will start up 3 separate VMs using vagrant in order to simulate a 2-server Redis installation and a single-server Apache ZooKeeper installation in order to test the `redis-failover` gem in a non-trivial configuration.
+
+How to Start
+------------
+
+To download the base box and start/configure the 3 VMs, run `vagrant up` in the root of the project. It may take a while the first time you start it as it has to compile ruby and redis as well as install a few packages.
+
+Once this is finished, you can connect to the different boxes using the `vagrant ssh` command:
+
+ vagrant ssh zookeeper
+ vagrant ssh redis_master
+ vagrant ssh redis_slave
+
+Or, you can access the machines individually by using the host-only IP addresses given by vagrant (which are completely accessible to the host machine with no firewall):
+
+<table>
+ <tr>
+ <th>IP</th><th>Machine</th>
+ </tr>
+ <tr>
+ <td>192.168.50.10</td><td>zookeeper</td>
+ </tr>
+ <tr>
+ <td>192.168.50.20</td><td>redis_master</td>
+ </tr>
+ <tr>
+ <td>192.168.50.21</td><td>redis_slave</td>
+ </tr>
+</table>
+
+Using `redis_node_manager`
+--------------------------
+To set up Redis Node Manager (this handles the actual failing-over and provides a view at the console of what's going on in the entire system), `vagrant ssh zookeper` and run the following from the home directory:
+
+ redis_node_manager -C redis_node_manager.yml
+
+This will check all of the Redis instances in the list provided by the YAML file and periodically poll them to ensure that they are up. If the master goes down, it will promote one of the slaves to master.
+
+Connecting to redis using RedisFailover
+---------------------------------------
+```ruby
+require 'rubygems'
+require 'bundler/setup'
+
+require 'redis-failover'
+client = RedisFailover::Client.new(:zkservers => '192.168.50.10:2181')
+```
+You'll now have a `client` object that has the same interface as a normal `redis`-gem client object that always communicates directly with the current master redis instance.
View
30 Vagrantfile
@@ -0,0 +1,30 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant::Config.run do |config|
+ config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
+ config.vm.box = "lucid32"
+
+ config.vm.define :zookeeper do |zk_config|
+ zk_config.vm.network :hostonly, "192.168.50.10"
+ zk_config.vm.provision(:chef_solo) { |chef| chef.add_recipe("zookeeperbox") }
+ end
+
+ config.vm.define :redis_master do |master_config|
+ master_config.vm.network :hostonly, "192.168.50.20"
+ master_config.vm.provision(:chef_solo) { |chef| chef.add_recipe("redisbox") }
+ end
+
+ config.vm.define :redis_slave do |slave_config|
+ slave_config.vm.network :hostonly, "192.168.50.21"
+ slave_config.vm.provision(:chef_solo) do |chef|
+ chef.json = {
+ :redis => {
+ :slave => '192.168.50.20'
+ }
+ }
+ chef.add_recipe("redisbox")
+ end
+ end
+
+end
View
9 cookbooks/redis/attributes/default.rb
@@ -0,0 +1,9 @@
+default[:redis][:dir] = "/etc/redis"
+default[:redis][:data_dir] = "/var/lib/redis"
+default[:redis][:log_dir] = "/var/log/redis"
+# one of: debug, verbose, notice, warning
+default[:redis][:loglevel] = "notice"
+default[:redis][:user] = "redis"
+default[:redis][:port] = 6379
+default[:redis][:bind] = "127.0.0.1"
+default[:redis][:slave] = false
View
70 cookbooks/redis/recipes/default.rb
@@ -0,0 +1,70 @@
+package "build-essential" do
+ action :install
+end
+
+user node[:redis][:user] do
+ action :create
+ system true
+ shell "/bin/false"
+end
+
+directory node[:redis][:dir] do
+ owner "root"
+ mode "0755"
+ action :create
+end
+
+directory node[:redis][:data_dir] do
+ owner "redis"
+ mode "0755"
+ action :create
+end
+
+directory node[:redis][:log_dir] do
+ mode 0755
+ owner node[:redis][:user]
+ action :create
+end
+
+remote_file "#{Chef::Config[:file_cache_path]}/redis.tar.gz" do
+ source "http://redis.googlecode.com/files/redis-2.4.15.tar.gz"
+ action :create_if_missing
+end
+
+bash "compile_redis_source" do
+ cwd Chef::Config[:file_cache_path]
+ code <<-EOH
+ tar zxf redis.tar.gz
+ cd redis-2.4.15
+ make && make install
+ EOH
+ creates "/usr/local/bin/redis-server"
+end
+
+service "redis" do
+ provider Chef::Provider::Service::Upstart
+ subscribes :restart, resources(:bash => "compile_redis_source")
+ supports :restart => true, :start => true, :stop => true
+end
+
+template "redis.conf" do
+ path "#{node[:redis][:dir]}/redis.conf"
+ source "redis.conf.erb"
+ owner "root"
+ group "root"
+ mode "0644"
+ notifies :restart, resources(:service => "redis")
+end
+
+template "redis.upstart.conf" do
+ path "/etc/init/redis.conf"
+ source "redis.upstart.conf.erb"
+ owner "root"
+ group "root"
+ mode "0644"
+ notifies :restart, resources(:service => "redis")
+end
+
+service "redis" do
+ action [:enable, :start]
+end
View
17 cookbooks/redis/templates/default/redis.conf.erb
@@ -0,0 +1,17 @@
+port <%= node[:redis][:port] %>
+loglevel <%= node[:redis][:loglevel] %>
+dir <%= node[:redis][:data_dir] %>
+
+
+daemonize no
+logfile stdout
+databases 16
+save 900 1
+save 300 10
+save 60 10000
+rdbcompression yes
+dbfilename dump.rdb
+
+<% if node[:redis][:slave] %>
+slaveof <%= node[:redis][:slave] %> <%= node[:redis][:port] %>
+<% end %>
View
14 cookbooks/redis/templates/default/redis.upstart.conf.erb
@@ -0,0 +1,14 @@
+#!upstart
+description "Redis Server"
+
+env USER=<%= node[:redis][:user] %>
+
+start on startup
+stop on shutdown
+
+respawn
+
+exec sudo -u $USER sh -c "/usr/local/bin/redis-server \
+ /etc/redis/redis.conf 2>&1 >> \
+ <%= node[:redis][:log_dir] %>/redis.log"
+
View
9 cookbooks/redisbox/recipes/default.rb
@@ -0,0 +1,9 @@
+require_recipe "redis"
+# require_recipe "rvm::system"
+# require_recipe "rvm::vagrant"
+
+# rvm_gem "resque" do
+# ruby_string "ruby-1.9.3-p194"
+# action :install
+# end
+
1 cookbooks/rvm
@@ -0,0 +1 @@
+Subproject commit 6411f1194c2f57dc2578e87d9ca89199561512dd
View
67 cookbooks/zookeeperbox/recipes/default.rb
@@ -0,0 +1,67 @@
+require_recipe "rvm::system"
+require_recipe "rvm::vagrant"
+
+rvm_gem "redis_failover" do
+ ruby_string "ruby-1.9.3-p194"
+ action :install
+end
+
+package "openjdk-6-jre-headless" do
+ action :install
+end
+
+remote_file "#{Chef::Config[:file_cache_path]}/zookeeper.tar.gz" do
+ source "http://apache.deathculture.net/zookeeper/zookeeper-3.3.5/zookeeper-3.3.5.tar.gz"
+ action :create_if_missing
+end
+
+bash "open_zookeeper_up" do
+ cwd Chef::Config[:file_cache_path]
+ code <<-EOH
+ tar zxf zookeeper.tar.gz
+ mv zookeeper-3.3.5 /home/vagrant/zookeeper
+ EOH
+ creates "/home/vagrant/zookeeper"
+end
+
+service "zoo" do
+ provider Chef::Provider::Service::Upstart
+ subscribes :restart, resources(:bash => "open_zookeeper_up")
+ supports :restart => true, :start => true, :stop => true
+end
+
+template "zoo.cfg" do
+ path "/home/vagrant/zookeeper/conf/zoo.cfg"
+ source "zoo.cfg.erb"
+ owner "vagrant"
+ group "vagrant"
+ mode "0644"
+end
+
+directory "/tmp/zookeeper" do
+ owner "vagrant"
+ group "vagrant"
+ mode "0755"
+ action :create
+end
+
+template "redis_node_manager.yml" do
+ path "/home/vagrant/redis_node_manager.yml"
+ source "redis_node_manager.yml.erb"
+ owner "vagrant"
+ group "vagrant"
+ mode "0644"
+end
+
+template "zoo.upstart.conf" do
+ path "/etc/init/zoo.conf"
+ source "zoo.upstart.conf.erb"
+ owner "root"
+ group "root"
+ mode "0644"
+ notifies :restart, resources(:service => "zoo")
+end
+
+service "zoo" do
+ action [:enable, :start]
+end
View
7 cookbooks/zookeeperbox/templates/default/redis_node_manager.yml.erb
@@ -0,0 +1,7 @@
+---
+:max_failures: 2
+:nodes:
+ - 192.168.50.20:6379
+ - 192.168.50.21:6379
+:zkservers:
+ - localhost:2181
View
12 cookbooks/zookeeperbox/templates/default/zoo.cfg.erb
@@ -0,0 +1,12 @@
+# The number of milliseconds of each tick
+tickTime=2000
+# The number of ticks that the initial
+# synchronization phase can take
+initLimit=10
+# The number of ticks that can pass between
+# sending a request and getting an acknowledgement
+syncLimit=5
+# the directory where the snapshot is stored.
+dataDir=/tmp/zookeeper
+# the port at which the clients will connect
+clientPort=2181
View
11 cookbooks/zookeeperbox/templates/default/zoo.upstart.conf.erb
@@ -0,0 +1,11 @@
+#!upstart
+description "Zookeeper Server"
+
+env USER=vagrant
+
+start on startup
+stop on shutdown
+
+respawn
+
+exec sudo -u $USER sh -c "/home/vagrant/zookeeper/bin/zkServer.sh start-foreground"
View
6 redis_failover_test.rb
@@ -0,0 +1,6 @@
+require "rubygems"
+require "bundler/setup"
+
+require "redis_failover"
+
+client = RedisFailover::Client.new(:zkservers => '192.168.50.10:2181')

0 comments on commit bb6a0f3

Please sign in to comment.
Something went wrong with that request. Please try again.