Creating a Redis Cluster on macOS

minimal Redis cluster setting

brew info redis

cd /usr/local/etc

建立 cluster 目錄

mkdir redis/cluster/7000
mkdir redis/cluster/7001
mkdir redis/cluster/7002
mkdir redis/cluster/7003
mkdir redis/cluster/7004
mkdir redis/cluster/7005

修改配置文件

cp redis.conf redis/cluster/7000/7000.conf
cp redis.conf redis/cluster/7001/7001.conf
cp redis.conf redis/cluster/7002/7002.conf
cp redis.conf redis/cluster/7003/7003.conf
cp redis.conf redis/cluster/7004/7004.conf
cp redis.conf redis/cluster/7005/7005.conf

port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
appendonly yes

啓動 Redis

redis-server /usr/local/etc/redis/cluster/7000/7000.conf &
redis-server /usr/local/etc/redis/cluster/7001/7001.conf &
redis-server /usr/local/etc/redis/cluster/7002/7002.conf &
redis-server /usr/local/etc/redis/cluster/7003/7003.conf &
redis-server /usr/local/etc/redis/cluster/7004/7004.conf &
redis-server /usr/local/etc/redis/cluster/7005/7005.conf &

Creating the cluster

brew update
brew install ruby
sudo gem install redis

Using redis-cli in Redis 5 and redis-trib in Redis 3 and 4.

redis-cli --cluster create 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 --cluster-replicas 1

./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

確認結果

ps -ef |grep redis

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *