Install Redis from Tarball
Redis Cluster Architecture
Masters
redis-1-1
redis-2-1
redis-3-1
Slaves
redis-1-2
redis-2-2
redis-3-2
Redis Prerequisites Installation
Before you intsall Redis, install some prerequisites that makes it easy to install
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install tcl8.5 tk8.5
The first command updates the apt-get packages. The second command installs the compiler with build essential which will help us install Redis from source. And in the last command we install the tk and tcl packages, which together provide a scripts for controlling and extending applications. In our case, tk and tcl will make it easy for redis to have a powerful scripting language.
Installation
Go to the redis download page and get the latest version from download.redis.io/releases/:
wget http://download.redis.io/releases/redis-3.2.4.tar.gz
tar -xvzf redis-3.2.4.tar.gz
cd redis-3.2.4
make
sudo make install
Once the program has been installed, Redis comes with a built in script that sets up Redis to run as a background daemon. To access the script and run it, perform the following commands:
cd utils
sudo ./install_server.sh
You will be prompted to choose desired settings while the script runs. You can just press enter through it all to choose the defaults. Once the script completes, the redis-server will be running in the background. To stop redis, you can simply run the command:
sudo service redis-6379 stop
The 6379 is the default redis port. If you changed the port when prompted after running the ./install_server.sh script, the replace 6379 with the port number you chose.
Installed the redis gem
gem install redis
Cluster Config
Open /etc/redis/6379.conf (even the /build/redis-3.0.1/redis.conf for the heck of it) and find the following variables and make sure that they have the following setting:
# redis.conf
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
Here, i would stop the redis server and restart it again. To stop the server, you can run
sudo service redis_6379 restart
Now, go back and perform ALL the steps we have performed above so far on all the other nodes, in our case, on 5 other nodes. When all the 6 nodes are up and running, we need to create the cluster.
Now that we have all redis instances running, we need to create our cluster by writing some meaningful configuration to the nodes. We can easily accomplish this by running the redis-trib.rb script. The script basically executes special commands in the instances in order to create new clusters, check or reshard an existing cluster, and so forth. The redis-trib utility is in the src directory of the Redis source code distribution. To create your cluster, we are going to run the following command [1]:
cd redis-3.0.2/src
./redis-trib.rb create --replicas 1 redis-1-1_ip:6379 redis-1-2_ip:6379 redis-3-1_ip:6379 \
redis-1-2:6379 redis-2-2:6379 redis-3-2:6379
NOTE: you have to use IP address instead of hostnames for some reason.
The command used here is create, since we want to create a new cluster. The option --replicas 1 means that we want a slave for every master created. The other arguments are the list of addresses of the instances I want to use to create the new cluster. If only want to create a cluster of three and no slaves for example, we would exclude the part "--replicas 1" and just include three ip:port obviously. But our design includes three redis nodes and three slaves.
Redis-trib will propose you a configuration. Accept typing yes. The cluster will be configured and joined, that means, instances will be bootstrapped into talking with each other. Finally if everything went ok you'll see a message like that
OK] All 16384 slots covered
This means that there is at least a master instance serving each of the 16384 slots available. You can now play around with the cluster.
REFERENCES
[1] http://redis.io/topics/cluster-tutorial
[2] https://ilyabylich.svbtle.com/redis-cluster-quick-overview
[3] https://gorails.com/setup/ubuntu/14.04
[4] https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis
[5] http://blog.sensible.io/2013/08/20/setting-up-redis-for-production-environment.html
No comments:
Post a Comment