首页 / REDIS / redis集群搭建以及常见问题
redis集群搭建以及常见问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了redis集群搭建以及常见问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3550字,纯文字阅读大概需要6分钟。
内容图文
![redis集群搭建以及常见问题](/upload/InfoBanner/zyjiaocheng/864/9a49d52db42b444abbea62c8a1cdc9de.jpg)
在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启动
![redis集群搭建以及常见问题 - 文章图片](/upload/getfiles/0001/2021/5/7/20210507072731622.jpg)
./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集群各个实例的进程,重新启动
内容总结
以上是互联网集市为您收集整理的redis集群搭建以及常见问题全部内容,希望文章能够帮你解决redis集群搭建以及常见问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。