There should be at least three nodes in a Redis cluster. To ensure high availability of the cluster, a backup machine is required for each node. A Redis cluster requires at least 6 servers.
Build pseudo-distributed. You can run 6 Redis instances using a single virtual machine.
Modifying the port number of a Redis 7001-7006
Use a ruby script to build a cluster. Install Ruby
yum install ruby
yum install rubygems
Install the package used by the Ruby script run
gem install redis-3.0.0.gem
Ruby Script Location
redis源码/src/redis-trib.rb
Create 6 Redis instances, modify REDIS.CONF configuration, configure ports, enable cluster
cluster-enabled yes
Start all Redis instances using Ruby script to build a cluster
./redis-trib.rb create --replicas 1192.168.25.128:7001 192.168.25.128:7002 192.168.25.128:7003 192.168.25.128:7004192.168.25.128:7005 192.168.25.128:7006
Using the cluster
redis-cli -p 7002 -c
-c means connecting to the cluster
Note
- Cluster Start batch Processing
cd /usr/local/src/redis-cluster/redis7001./redis-server redis.confcd /usr/local/src/redis-cluster/redis7002./redis-server redis.confcd /usr/local/src/redis-cluster/redis7003./redis-server redis.confcd /usr/local/src/redis-cluster/redis7004./redis-server redis.confcd /usr/local/src/redis-cluster/redis7005./redis-server redis.confcd /usr/local/src/redis-cluster/redis7006./redis-server redis.confcd /usr/local/src
- Cluster off batch Processing
cd /usr/local/src/redis-cluster/redis7001 ./redis-cli -p 7001 shutdown ./redis-cli -p 7002 shutdown ./redis-cli -p 7003 shutdown ./redis-cli -p 7004 shutdown ./redis-cli -p 7005 shutdown ./redis-cli -p 7006 shutdown cd /usr/local/src
Centos7:redis Cluster Construction