redis集群搭建以及常见问题

在Linux上搭建redis集群时踩了不少坑在这里记录下来。首先要保证搭建的环境干净要不然很容易报错!!!

创建存放集群配置文件的文件夹:mkdir /redis

cd/ redis
cp /opt//opt/redis-5.0.5/redis.conf redis6380.conf
cp /opt//opt/redis-5.0.5/redis.conf redis6381.conf
cp /opt//opt/redis-5.0.5/redis.conf redis6382.conf
cp /opt//opt/redis-5.0.5/redis.conf redis6383.conf
cp /opt//opt/redis-5.0.5/redis.conf redis6384.conf
cp /opt//opt/redis-5.0.5/redis.conf redis6385.conf

 

配置文件:

## 6380
bind 127.0.0.1 绑定当前机器 IP
port 6380    端口号
daemonize yes 启动集群模式
pidfile 6380.pid pid要与port对应
logfile 6380.log 也要与port对应  
cluster-enabled yes 启动集群模式
cluster-config-file node-6380.conf 与port对应
cluster-node-timeout 10000
appendonly yes
## 6381
bind 127.0.0.1
port 6381
daemonize yes
pidfile 6381.pid
logfile 6381.log
cluster-enabled yes
cluster-config-file node-6381.conf
cluster-node-timeout 10000
appendonly yes
## 6382
bind 127.0.0.1
port 6382
daemonize yes
pidfile 6382.pid
logfile 6382.log
cluster-enabled yes
cluster-config-file node-6382.conf
cluster-node-timeout 10000
appendonly yes
## 6383
bind 127.0.0.1
port 6383
daemonize yes
pidfile 6383.pid
logfile 6383.log
cluster-enabled yes
cluster-config-file node-6383.conf
cluster-node-timeout 10000
appendonly yes
## 6384
bind 127.0.0.1
port 6384
daemonize yes
pidfile 6384.pid
logfile 6384.log
cluster-enabled yes
cluster-config-file node-6384.conf
cluster-node-timeout 10000
appendonly yes
## 6385
bind 127.0.0.1
port 6385
daemonize yes
pidfile 6385.pid
logfile 6385.log
cluster-enabled yes
cluster-config-file node-6385.conf
cluster-node-timeout 10000
appendonly yes

 

安装ruby:

wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.4.tar.gz
tar ruby-2.6.4.tar.gz
cd ruby-2.6.4
./configure --prefix=/opt/ruby
make && make install

 

安装ruby依赖:

yum install gem
gem install redis

 

配置环境变量:

vim /etc/profile.d/ruby.sh
PATH=/opt/ruby/bin:$PATH
source /etc/profile.d/ruby.sh 

 

启动6380-6385六个节点:

[root@localhost redis-5.0.5]#./src/redis-server /redis/redis6380.conf 
[root@localhost redis-5.0.5]#./src/redis-server /redis/redis6381.conf 
[root@localhost redis-5.0.5]#./src/redis-server /redis/redis6382.conf 
[root@localhost redis-5.0.5]#./src/redis-server /redis/redis6383.conf 
[root@localhost redis-5.0.5]#./src/redis-server /redis/redis6384.conf 
[root@localhost redis-5.0.5]#./src/redis-server
/redis/redis6385.conf 

ps -ef|grep redis 查看是否启动成功

 

创建集群:

./src/redis-cli --cluster create --cluster-replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385

 

M: 93a8d761d0e3954c2857dc56644c193e6945fe52 127.0.0.1:6380
   slots:[0-5460] (5461 slots) master
M: a6403a00156e293a3605b026b69b5700de0ebcb6 127.0.0.1:6381
   slots:[5461-10922] (5462 slots) master
M: 77b59aa125fc8550a76b414b6103366e7a6d8d22 127.0.0.1:6382
   slots:[10923-16383] (5461 slots) master
S: 8ab38a76a844f5109a4b7f3f9b9419132fb0392a 127.0.0.1:6383
   replicates a6403a00156e293a3605b026b69b5700de0ebcb6
S: 69f025afe14065e62cf178f7a3366426cc64fe3a 127.0.0.1:6384
   replicates 77b59aa125fc8550a76b414b6103366e7a6d8d22
S: 6918fcaecb46dc77b018acb48a8c30504c9dc7e3 127.0.0.1:6385
   replicates 93a8d761d0e3954c2857dc56644c193e6945fe52
Can I set the above configuration? (type 'yes' to accept): yes

输入yes启动

 

表示成功
 
常用命令:
./src/redis-cli --cluster info 127.0.0.1:6380 查看状态
./src/redis-cli -c -p 6380 连接

 

报错:

 

解决办法:

1. 删除每个节点对应的nodes-xxx.conf配置文件 rm -rf node*

2. 删除每个节点下的aof、rdb文件 rm -rf *.aof rm -rf *.rdb

3. 关掉redis集群各个实例的进程,重新启动

posted @ 2021-02-13 22:28  Ccdjun  阅读(239)  评论(0编辑  收藏  举报