redis 5.0 集羣搭建

2018年十月 Redis 發佈了穩定版本的 5.0 版本,推出了各類新特性,其中一點是放棄 Ruby的集羣方式,改成 使用 C語言編寫的 redis-cli的方式,是集羣的構建方式複雜度大大下降。下面進行集羣搭建說明node

0,安裝gccc++

yum install gcc-c++ -y

1,首先下載redisredis

​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,安裝redisvim

[root@hadoop12 redis]# pwd
/opt/module/redis
[root@hadoop11 redis]# make install PREFIX=/home/hui/software/redis

3,建立集羣文件夾bash

mkdir redis-cluster
cd redis-cluster/
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
mkdir 7006

4,拷貝redis配置文件app

cp ./redis.conf /bin
cp -r ./bin/* ./redis-cluster/700[1-6]

5,修改配置文件(redis.conf)oop

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 須要隨着 文件夾的不一樣調增ui

6,編寫啓動腳本.net

vim start-all.sh,內容以下code

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 #查看節點狀況

參考:https://my.oschina.net/ruoli/blog/2252393

低版本redis集羣搭建:https://blog.csdn.net/yerenyuan_pku/article/details/72860432

低版本redis單機安裝:https://blog.csdn.net/yerenyuan_pku/article/details/72849612

相關文章
相關標籤/搜索