The Redis cluster requires at least 3 nodes, because the voting fault tolerance mechanism requires more than half of the nodes to think that a node is down before the node is down, so 2 nodes cannot form a cluster.
There are three nodes in the cluster, and each node has one master and one backup. Requires 6 virtual machines. Build a pseudo-distributed cluster and use 6 redis instances to simulate.
1. Install ruby environment (Recommended learning: Redis video tutorial)
yum install ruby//ruby运行环境 yum install rubygems//ruby包管理器将redis-3.0.0.gem上传到服务器(redis-trib.rb运行需要依赖的包) gem installe redis-3.0.0.gem(安装该依赖包)
2. Build a cluster
(1)Copy bin
mkdir redis-cluster cd redis cp -r bin ../redis-cluster/redis01 //拷贝
(2)Modify the configuration file
cd ../redis-cluster/redis01/rm -f dump.rdb (删除快照文件) vim redis.conf
Modification:
port 7001cluster-enabled yes
(3) Create six nodes
cp -r redis01/ redis02(一直改到6)vim redis02/redis.conf(分别改端口号)
(4)Copy the cluster script to the cluster directory
cd redis-3.0.0/src cp *.rb /usr/local/redis-cluster/
(5) Run 6 redis instances
vim startall.shcd redis01 ./redis-server redis.confcd ..cd redis02 ./redis-server redis.confcd ..cd redis03 ./redis-server redis.confcd ..cd redis04 ./redis-server redis.confcd ..cd redis05 ./redis-server redis.confcd ..cd redis06 ./redis-server redis.confcd .. ./startall.sh
(6) Create a cluster
./redis-trib.rb create --replicas 1 192.168.25.153:7001 192.168.25.153:7002 192.168.25.153:7003192.168.25.153:7004 192.168.25.153:7005 192.168.25.153:7006
For more Redis related technical articles, please visit the Redis Getting Started Tutorial column to learn!
The above is the detailed content of What is needed to build a redis cluster?. For more information, please follow other related articles on the PHP Chinese website!