redis學習系列(十) redis 集群安裝

2021-08-09 19:54:21 字數 4915 閱讀 3401

今天終於要開始集群安裝了。

1.單機版安裝路徑:

/usr/local/redis

2.redis路徑

/usr/redis/redis-3.0.0

1.新建集群資料夾

mkdir /usr/local/redis-cluster
2.進入redis安裝路徑下的redis/bin資料夾下,執行copy操作

cp -r  bin    ../redis-cluster/redis01

cp -r bin ../redis-cluster/redis02

cp -r bin ../redis-cluster/redis03

cp -r bin ../redis-cluster/redis04

cp -r bin ../redis-cluster/redis05

cp -r bin ../redis-cluster/redis06

3.進入redis01-redis06檔案下,更新每個redis.conf檔案,修改埠號為7001-7006,以及開啟每個配置檔案內的cluster-enable

4.將建立集群的ruby指令碼複製到redis-cluster下,這邊需要進入redis的原始檔案下/redis/redis-3.0.0

cd /usr/redis/redis-3.0.0/src
5.複製

cp  *.rb     /usr/local/redis-cluster/
6.回到redis-cluster下,建立startall.sh用於一起啟動

vim startall.sh

cd redis01  

./redis-server redis.conf

cd ..

cd redis02

./redis-server redis.conf

cd ..

cd redis03

./redis-server redis.conf

cd ..

cd redis04

./redis-server redis.conf

cd ..

cd redis05

./redis-server redis.conf

cd ..

cd redis06

./redis-server redis.conf

cd ..

7.賦予許可權

chmod  +x  startall.sh
8.指令碼啟動

./startall.sh
9.檢視狀態

ps  aux|grep  redis
[root@localhost redis-cluster]# ps -aux | grep redis

root 9129 0.0 0.0 131616 2356 ? ssl 17:02 0:00 ./redis-server *:7001 [cluster]

root 9131 0.0 0.0 131616 2352 ? ssl 17:02 0:00 ./redis-server *:7002 [cluster]

root 9133 0.0 0.0 131616 2356 ? ssl 17:02 0:00 ./redis-server *:7003 [cluster]

root 9139 0.0 0.0 131616 2360 ? ssl 17:02 0:00 ./redis-server *:7004 [cluster]

root 9141 0.0 0.0 131616 2360 ? ssl 17:02 0:00 ./redis-server *:7005 [cluster]

root 9145 0.0 0.0 131616 2356 ? ssl 17:02 0:00 ./redis-server *:7006 [cluster]

root 9165 0.0 0.0 112656 984 pts/0 r+ 17:02 0:00 grep --color=auto redis

10.安裝gem

gem  install  redis
11.建立集群

./redis-trib.rb create --replicas 1 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  127.0.0.1:7006
12結果,出現選擇是否設定,yes

>>> performing hash slots allocation on 6 nodes...

using 3 masters:

127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

adding replica 127.0.0.1:7004 to 127.0.0.1:7001

adding replica 127.0.0.1:7005 to 127.0.0.1:7002

adding replica 127.0.0.1:7006 to 127.0.0.1:7003

m: 4f3dd6ac051fd53588a0a54513c1a834e591e94f 127.0.0.1:7001

slots:0-5460 (5461 slots) master

m: ee69242ebf2ca320b28794a8b2eb6019b9bf0acc 127.0.0.1:7002

slots:5461-10922 (5462 slots) master

m: 7ac8d14d1a644f3099eefccb73f604e56e4728c1 127.0.0.1:7003

slots:10923-16383 (5461 slots) master

s: a15b4aeb80133aa940bae0d1e81798852442c317 127.0.0.1:7004

replicates 4f3dd6ac051fd53588a0a54513c1a834e591e94f

s: afc075dc730f434df6815cca778cc6d3c97f7f7a 127.0.0.1:7005

replicates ee69242ebf2ca320b28794a8b2eb6019b9bf0acc

s: 7a6e1f12d4ccd1637de1f66792c697e177cb0cd9 127.0.0.1:7006

replicates 7ac8d14d1a644f3099eefccb73f604e56e4728c1

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 127.0.0.1:7001)

m: 4f3dd6ac051fd53588a0a54513c1a834e591e94f 127.0.0.1:7001

slots:0-5460 (5461 slots) master

m: ee69242ebf2ca320b28794a8b2eb6019b9bf0acc 127.0.0.1:7002

slots:5461-10922 (5462 slots) master

m: 7ac8d14d1a644f3099eefccb73f604e56e4728c1 127.0.0.1:7003

slots:10923-16383 (5461 slots) master

m: a15b4aeb80133aa940bae0d1e81798852442c317 127.0.0.1:7004

slots: (0 slots) master

replicates 4f3dd6ac051fd53588a0a54513c1a834e591e94f

m: afc075dc730f434df6815cca778cc6d3c97f7f7a 127.0.0.1:7005

slots: (0 slots) master

replicates ee69242ebf2ca320b28794a8b2eb6019b9bf0acc

m: 7a6e1f12d4ccd1637de1f66792c697e177cb0cd9 127.0.0.1:7006

slots: (0 slots) master

replicates 7ac8d14d1a644f3099eefccb73f604e56e4728c1

[ok] all nodes agree about slots configuration.

>>> check for open slots...

>>> check slots coverage...

[ok] all 16384 slots covered.

13.集群時三主三從模式。後續繼續基於此測試。

Redis學習系列 Redis基本教程

1.redis資料型別 redis支援五種資料型別 string 字串 hash 雜湊 list 列表 set 集合 及zset sorted set 有序集合 2.字串 string 示例 127.0 0.1 6379 set key1 value1 ok127.0 0.1 6379 get ke...

Redis系列學習 一 Redis簡介

2.4 總結 3.redis的特點 4.redis的應用場景 5.redis總結 redis是乙個開源的 遵守bsd協議 支援網路 可基於記憶體亦可持久化的日誌型 高效能 nosql key value資料庫。nosql資料庫的產生就是為了解決大規模資料集合多重資料種類帶來的挑戰,尤其是大資料應用難...

redis系列 redis的連線

redis 是完全開源免費的,遵守bsd協議,先進的key value持久化產品。它通常被稱為資料結構伺服器,因為值 value 可以是 字串 string 雜湊 map 列表 list 集合 sets 和 有序集合 sorted sets 等型別。redis客戶端連線比較簡單,但日常中redis的...