Redis cluster in a single machine
程序员文章站
2022-07-13 22:07:06
...
Environment
OS: Linux
Redis: redis-3.0.5
Steps
Install redis
Please refer to https://blog.csdn.net/yaominhua/article/details/49657923
Create folders
cd /home/jason/redis/
mkdir cluster-test
cd cluster-test/
mkdir 7000 7001 7002 7003 7004 7005
Create redis.conf for each folder
step into the folder 7000 to 7005 and create the configure file show below:
# redis host
bind 127.0.0.1
# redis port, each folder will have different value
port 7000
# run in background
daemonize yes
# enable the cluster mode
cluster-enabled yes
# the cluster configuration file
cluster-config-file nodes.conf
# the max limit time allowd for the node which not available(15s)
cluster-node-timeout 15000
appendonly yes
Start redis server for each redis.conf
redis-server /home/jason/redis/cluster-test/7000/redis.conf
redis-server /home/jason/redis/cluster-test/7001/redis.conf
redis-server /home/jason/redis/cluster-test/7002/redis.conf
redis-server /home/jason/redis/cluster-test/7003/redis.conf
redis-server /home/jason/redis/cluster-test/7004/redis.conf
redis-server /home/jason/redis/cluster-test/7005/redis.conf
Configure cluster
You must install ruby and rubygems
sudo apt-get install ruby
sudo apt-get install rubygems
Install redis-3.0.5.gem
wget https://rubygems.global.ssl.fastly.net/gems/redis-3.0.5.gem
sudo gem install -l ./redis-3.0.5.gem
Create cluster
cd /home/jason/redis/redis-3.0.5/src/
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
# [OK] All nodes agree about slots configuration
# [OK] All 16384 slots covered