redis 5.0 叢集搭建
阿新 • • 發佈:2019-05-18
2018年十月 Redis 釋出了穩定版本的 5.0 版本,推出了各種新特性,其中一點是放棄 Ruby的叢集方式,改為 使用 C語言編寫的 redis-cli的方式,是叢集的構建方式複雜度大大降低。下面進行叢集搭建說明
1,首先下載redis
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar xzf redis-5.0.0.tar.gz
cd redis-5.0.0
make
2,安裝redis
cd src
make install PREFIX=/home/hui/software/redis
3,建立叢集資料夾
mkdir redis-cluster cd redis-cluster/ mkdir 7001 mkdir 7002 mkdir 7003 mkdir 7004 mkdir 7005 mkdir 7006
4,拷貝redis安裝指令碼
cp ./redis.conf /bin
cp -r ./bin/* ./redis-cluster/700[1-6]
5,修改配置檔案(redis.conf)
port 7001 #埠 bind 192.168.43.11 #主機ip cluster-enabled yes #啟用叢集模式 cluster-config-file nodes.conf #自動生成的節點配置 cluster-node-timeout 5000 #超時時間 appendonly yes daemonize yes #後臺執行 protected-mode no #非保護模式 pidfile /home/hui/software/redis/redis-cluster/7001/7001.pid
其中 port 和 pidfile 需要隨著 資料夾的不同調增
6,編寫啟動指令碼
vim start-all.sh,內容如下
cd /home/hui/software/redis/redis-cluster/7001 ./redis-server ./redis.conf cd /home/hui/software/redis/redis-cluster/7002 ./redis-server ./redis.conf cd /home/hui/software/redis/redis-cluster/7003 ./redis-server ./redis.conf cd /home/hui/software/redis/redis-cluster/7004 ./redis-server ./redis.conf cd /home/hui/software/redis/redis-cluster/7005 ./redis-server ./redis.conf cd /home/hui/software/redis/redis-cluster/7006 ./redis-server ./redis.conf
7,啟動例項
sh start-all.sh
8,編寫啟動叢集指令碼
vim start-cluster.sh ,內容如下
/home/hui/software/redis/src/redis-cli --cluster create 192.168.43.11:7001 192.168.43.11:7002 192.168.43.11:7003 192.168.43.11:7004 192.168.43.11:7005 192.168.43.11:7006 --cluster-replicas 1
啟動 叢集:sh start-cluster.sh,結果如下:
[hui@hadoop11 redis-cluster]$ sh start-cluster.sh
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.43.11:7004 to 192.168.43.11:7001
Adding replica 192.168.43.11:7005 to 192.168.43.11:7002
Adding replica 192.168.43.11:7006 to 192.168.43.11:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 2a4e1320781105790a61051b84efc640dff19fed 192.168.43.11:7001
slots:[0-5460] (5461 slots) master
M: 1bca19101b9556bf688ff35ce7b7905083474c3e 192.168.43.11:7002
slots:[5461-10922] (5462 slots) master
M: 69f1bca60c7833b4bf6866b40334c1cacc24d0f2 192.168.43.11:7003
slots:[10923-16383] (5461 slots) master
S: 8dfcdee38afceabf0e0bdad56f51b2cd4be07ba8 192.168.43.11:7004
replicates 1bca19101b9556bf688ff35ce7b7905083474c3e
S: 26985f449573ea6bd67e97046d14fcb354494f1c 192.168.43.11:7005
replicates 69f1bca60c7833b4bf6866b40334c1cacc24d0f2
S: 5b7b86078ae011aa64ecf1590083358ea80a6295 192.168.43.11:7006
replicates 2a4e1320781105790a61051b84efc640dff19fed
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 192.168.43.11:7001)
M: 2a4e1320781105790a61051b84efc640dff19fed 192.168.43.11:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 69f1bca60c7833b4bf6866b40334c1cacc24d0f2 192.168.43.11:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 5b7b86078ae011aa64ecf1590083358ea80a6295 192.168.43.11:7006
slots: (0 slots) slave
replicates 2a4e1320781105790a61051b84efc640dff19fed
S: 8dfcdee38afceabf0e0bdad56f51b2cd4be07ba8 192.168.43.11:7004
slots: (0 slots) slave
replicates 1bca19101b9556bf688ff35ce7b7905083474c3e
S: 26985f449573ea6bd67e97046d14fcb354494f1c 192.168.43.11:7005
slots: (0 slots) slave
replicates 69f1bca60c7833b4bf6866b40334c1cacc24d0f2
M: 1bca19101b9556bf688ff35ce7b7905083474c3e 192.168.43.11:7002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
檢視叢集狀態
cd 7001
./redis-cli -c -p 7001 -h 192.168.43.11
cluster nodes #檢視節點情況