>搭建环境:

a)redis的安装包,redis-5.0.8.tar.gz

b)gcc安装包gcc_rpm.tar.gz

c)VM10

d)CentOS镜像文件

>搭建步骤:

1、准备工作:

(1)在linux下新建一个存储集群的目录redis-cluster:

(2)检查是否安装gcc:

2、解压编译安装一个Redis服务

(1)将redis-5.0.8.tar.gz放到目录下

(2)解压:tar xzf redis-5.0.8.tar.gz

(3)进入目录:cd redis-5.0.8

(4)编译安装:make install PREFIX=/home/dareway/redis-cluster/redis-5.0.8

(5)修改配置文件(说明可见:https://blog.csdn.net/AhaQianxun/article/details/107014991):

启动服务:

[dareway@localhost redis-cluster]$ ./redis-5.0.8/bin/redis-server ./redis-5.0.8/redis.conf
1744:C 28 Jun 2020 19:34:08.081 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1744:C 28 Jun 2020 19:34:08.081 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=1744, just started
1744:C 28 Jun 2020 19:34:08.081 # Configuration loaded

查看进程可以看到在6379默认端口:

[dareway@localhost redis-cluster]$ ps -ef|grep redis
dareway    1745      1  0 19:34 ?        00:00:00 ./redis-5.0.8/bin/redis-server *:6379
dareway    1750   1510  0 19:34 pts/0    00:00:00 grep --color=auto redis

使用redis-cli 连接测试:

[dareway@localhost redis-cluster]$ ./redis-5.0.8/bin/redis-cli
127.0.0.1:6379> 

可以使用Jdis客户端连接:

     // jedisJedis jedis = new Jedis("192.168.79.129", 6379);jedis.auth("123456");jedis.set("name", "redis-value");String value = jedis.get("name");System.out.println(value);jedis.close();

出现问题:连接超时

这里绑定了本机,我们把这个备注掉;

# bind 127.0.0.1

配置完后

[root@localhost redis]# ./bin/redis-cli shutdown

[root@localhost redis]# ./bin/redis-server ./redis.conf

要重启下redis服务;

又出现问题:远程连接Redis自我保护

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.at redis.clients.jedis.Protocol.processError(Protocol.java:127)at redis.clients.jedis.Protocol.process(Protocol.java:161)at redis.clients.jedis.Protocol.read(Protocol.java:215)at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:96)at redis.clients.jedis.Connection.sendCommand(Connection.java:126)at redis.clients.jedis.Connection.sendCommand(Connection.java:117)at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:564)at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2138)at com.dareway.test.RedisConnTest.main(RedisConnTest.java:16)

有两种方法 解决

第一种 直接去掉自我保护功能(不推荐)

[root@localhost redis]# vi /usr/local/redis/redis.conf

进入配置

找到 protected-mode yes 改成 no即可

第二种 设置redis连接密码

进入客户端

[root@localhost redis]# ./bin/redis-cli

127.0.0.1:6379> config set requirepass 123456

设置密码 123456

127.0.0.1:6379> quit

[root@localhost redis]# ./bin/redis-cli

127.0.0.1:6379> auth 123456

OK

再测试一下,可以了

3、多机多节点Redis集群搭建(3主 + 6从)

克隆三台CentOS虚拟机,分别在每台虚拟机上8001-8003端口创建三个节点,注意要修改配置。

在每台机器redis-cluster目录下,mkdir 8001 8002 8003,可以从上面安装过的6379拷贝配置文件到文件夹下分别进行修改,也可以将整个5.0目录分别拷贝到8001-8003。

(1)分别修改配置(参考自己实际的IP和端口进行调整配置):

port 7001  //六个节点配置文件分别是7001-7003bind 192.168.79.129    //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访,和单机集群有区别daemonize yes        //redis后台运行pidfile /var/run/redis_7001.pid   //pidfile文件对应7001-7003cluster-enabled yes   //开启集群cluster-config-file nodes_7001.conf  //保存节点配置,自动创建,自动更新对应7001-7003cluster-node-timeout 5000    //集群超时时间,节点超过这个时间没反应就断定是宕机appendonly yes   //存储方式,aof,将写操作记录保存到日志中dbfilename dump_7001.rdb

补充配置:masterauth xxx //设置集群节点间访问密码

(2)分别启动多个节点:

[dareway@localhost redis-cluster]$ ps -ef|grep redis
dareway    2146      1  0 20:03 ?        00:00:00 ./8001/redis-5.0.8/bin/redis-server 192.168.79.129:8001 [cluster]
dareway    2151      1  0 20:04 ?        00:00:00 ./8002/redis-5.0.8/bin/redis-server 192.168.79.129:8002 [cluster]
dareway    2156      1  0 20:04 ?        00:00:00 ./8003/redis-5.0.8/bin/redis-server 192.168.79.129:8003 [cluster]
dareway    2162   1510  0 20:04 pts/0    00:00:00 grep --color=auto redis

(3)开放集群端口或者直接干掉防火墙

systemctl stop firewalld.service

(4)通过redis-cli 命令创建集群

./redis-5.0.8/bin/redis-cli --cluster create 192.168.79.129:8001 192.168.79.130:8001 192.168.79.131:8001 192.168.79.129:8002 192.168.79.129:8003 192.168.79.130:8002 192.168.79.130:8003 192.168.79.131:8002 192.168.79.131:8003 --cluster-replicas 2 -a 123456

2代表一个master有2个slave,前三个ip是master。

补充:如果未设置密码 无需 -a xxxxxx 命令

运行结果:

[root@localhost redis-cluster]# systemctl stop firewalld.service
[root@localhost redis-cluster]# ./redis-5.0.8/bin/redis-cli --cluster create 192.168.79.129:8001 192.168.79.130:8001 192.168.79.131:8001 192.168.79.129:8002 192.168.79.129:8003 192.168.79.130:8002 192.168.79.130:8003 192.168.79.131:8002 192.168.79.131:8003 --cluster-replicas 2
>>> Performing hash slots allocation on 9 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.79.130:8002 to 192.168.79.129:8001
Adding replica 192.168.79.131:8002 to 192.168.79.129:8001
Adding replica 192.168.79.129:8003 to 192.168.79.130:8001
Adding replica 192.168.79.131:8003 to 192.168.79.130:8001
Adding replica 192.168.79.130:8003 to 192.168.79.131:8001
Adding replica 192.168.79.129:8002 to 192.168.79.131:8001
M: 6b6fe21cb7a9eb1d39bd1124b462026018131246 192.168.79.129:8001slots:[0-5460] (5461 slots) master
M: 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29 192.168.79.130:8001slots:[5461-10922] (5462 slots) master
M: 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf 192.168.79.131:8001slots:[10923-16383] (5461 slots) master
S: a32f31b3df9210b0f19ba132f158257ac2ac5265 192.168.79.129:8002replicates 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf
S: b687a59fc61eda12defdd477bd4b0da422eb5106 192.168.79.129:8003replicates 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29
S: e90f0459e297e3c0714bde2d5552530749237295 192.168.79.130:8002replicates 6b6fe21cb7a9eb1d39bd1124b462026018131246
S: f8e4acbf4e072eb2b9ac53921af83aee4acabfc9 192.168.79.130:8003replicates 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf
S: 630f84d3c456d7ec5ee90931c5efabd7e4fe2a37 192.168.79.131:8002replicates 6b6fe21cb7a9eb1d39bd1124b462026018131246
S: e28d453f3bc528c9eb595643f1bad69b74848698 192.168.79.131:8003replicates 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29
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.79.129:8001)
M: 6b6fe21cb7a9eb1d39bd1124b462026018131246 192.168.79.129:8001slots:[0-5460] (5461 slots) master2 additional replica(s)
S: e90f0459e297e3c0714bde2d5552530749237295 192.168.79.130:8002slots: (0 slots) slavereplicates 6b6fe21cb7a9eb1d39bd1124b462026018131246
S: e28d453f3bc528c9eb595643f1bad69b74848698 192.168.79.131:8003slots: (0 slots) slavereplicates 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29
M: 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf 192.168.79.131:8001slots:[10923-16383] (5461 slots) master2 additional replica(s)
S: b687a59fc61eda12defdd477bd4b0da422eb5106 192.168.79.129:8003slots: (0 slots) slavereplicates 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29
S: f8e4acbf4e072eb2b9ac53921af83aee4acabfc9 192.168.79.130:8003slots: (0 slots) slavereplicates 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf
S: a32f31b3df9210b0f19ba132f158257ac2ac5265 192.168.79.129:8002slots: (0 slots) slavereplicates 0c15b4949bdfe04b4a3d31bc4fd3d1109271d6cf
S: 630f84d3c456d7ec5ee90931c5efabd7e4fe2a37 192.168.79.131:8002slots: (0 slots) slavereplicates 6b6fe21cb7a9eb1d39bd1124b462026018131246
M: 9e81870e2a4beeb3568f9fa9c85d82bc93b70e29 192.168.79.130:8001slots:[5461-10922] (5462 slots) master2 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

显示分配哈希槽,启动成功,可以用了。

(5)验证连接:

./redis-cli -h 10.1.50.207 -c -p 8001 -a redis123(-a访问服务端密码,-c表示集群模式,指定ip地址和端口号)

cluster info查看集群信息

./redis-cli --cluster info 10.1.50.208:8001 -a redis123检查集群状态

[root@localhost redis-cluster]# ./redis-5.0.8/bin/redis-cli -h 192.168.79.130 -c -p 8001
192.168.79.130:8001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:9
cluster_size:3
cluster_current_epoch:9
cluster_my_epoch:2
cluster_stats_messages_ping_sent:715
cluster_stats_messages_pong_sent:275
cluster_stats_messages_fail_sent:24
cluster_stats_messages_sent:1014
cluster_stats_messages_ping_received:275
cluster_stats_messages_pong_received:216
cluster_stats_messages_received:491

lettuce客户端连接测试:

RedisURI redisUri = RedisURI.builder().withHost("192.168.79.129").withPort(8001).withTimeout(Duration.of(60, ChronoUnit.SECONDS)).build();RedisClient redisClient = RedisClient.create(redisUri);StatefulRedisConnection<String, String> connection = redisClient.connect();// 创建线程安全的连接RedisCommands<String, String> redisCommands = connection.sync();String result = redisCommands.set("RedisLettuce-01", "RedisLettuce-01");System.out.println(result);System.out.println(redisCommands.get("RedisLettuce-01"));connection.close();redisClient.shutdown();

搭建完成!

Redis 多机多节点集群搭建方案(5.0版本)相关推荐

  1. RocketMQ集群搭建-4.2.0版本

    首发于我的博客: www.liutf.com/ 首发链接:www.liutf.com/posts/14196- 背景 由于公司内部用的RocketMQ消息中间件是个单点实例,随着业务发展,越来越多的应 ...

  2. flume多节点集群搭建

    概览 1.Flume流程简介 2.规划 3.配置 4.启动测试 5.注意 准备 操作系统:CentOS 7 搭建好hadoop集群 Flume版本:1.8.0 jdk版本:1.8.0_141 工具:X ...

  3. 【有料】4 种高可用 RocketMQ 集群搭建方案!

    背景 笔者所在的业务线,最初化分为三个服务,由于业务初期业务复杂度相对简单,三个业务服务都能很好的独立完成业务功能. 随着产品迭代,业务功能越来越多后慢慢也要面对高并发.业务解耦.分布式事务等问题,所 ...

  4. Cloudera Manager安装之利用parcels方式安装单节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(CentOS6.5)(四)...

    前期博客 Cloudera Manager安装之Cloudera Manager 5.3.X安装(三)(tar方式.rpm方式和yum方式) 说在前面的话(看清楚就好!!!) 我这篇博客,是两种方式都 ...

  5. Cloudera Manager安装之利用parcels方式安装3或4节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(CentOS6.5)(五)...

    参考博客 Cloudera Manager安装之利用parcels方式安装单节点集群  Cloudera Manager安装之Cloudera Manager 5.3.X安装(三)(tar方式.rpm ...

  6. Cloudera Manager安装之利用parcels方式(在线或离线)安装3或4节点集群(包含最新稳定版本或指定版本的安装)(添加服务)(Ubuntu14.04)(五)...

    如果大家,在启动的时候,比如遇到如下问题,则 明明已经授权了啊,怎么被拒绝,纳尼??? 解决办法 然后,再来这样,就可以了. 注意,在此之前. ubuntucmbigdata1机器上,则需要执行 bi ...

  7. Redis三主三从集群搭建

    一.引子 主从复制以及哨兵,他们可以提高读的并发,但是单个master容量有限,数据达到一定程度会有瓶颈,这个时候可以通过水平扩展为多master-slave集群(看原理图). 所以一起来学习redi ...

  8. Redis三主三从集群搭建(三台机器)

    介绍 redis三种模式 一.主从模式 Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构. ...

  9. redis指定配置文件启动_深入学习 Redis 集群搭建方案及实现原理

    " 在前面的文章中已经介绍了 本文将详细介绍集群,主要内容包括: 集群的作用 集群的搭建方法及设计方案 集群的基本原理 客户端访问集群的方法 实践须知(集群伸缩.故障转移.参数优化等) 集群 ...

最新文章

  1. vue从创建到完整的饿了么(12)miste.vue
  2. redis 漏洞利用与防御
  3. postman 安装失败_【Postman】14 Postman与Jenkins集成使用
  4. 访问控制管理的积极意义案例
  5. 设计模式之_Iterator_01
  6. 可视化图形(二):热力图-imshow()
  7. 利用Arcgis for javascript API绘制GeoJSON并同时弹出多个Popup
  8. 论文浅尝 | 打通推荐系统与知识图谱: 第一个公开的大规模链接数据集合
  9. linq查询不包含某个值的记录_MySQL行(记录)的详细操作
  10. 二、Zabbix-zabbix server部署-LNMP
  11. EasyUI:动态更改combox下拉框中选项
  12. 【WC2013】糖果公园
  13. 20190914每日一句
  14. C 语言是“最环保”的编程语言
  15. 爬取淘宝评论以及词云图
  16. BPC电波授时信号的“零成本”伪造
  17. 如何配置shopex网店静态化(URL重写)
  18. Python float()函数
  19. python后缀是什么_python文件的后缀名是什么
  20. wifi mesh组网

热门文章

  1. kafka 常见问题( 持续更新... ... )
  2. C 关于链表的一些操作
  3. 基于gateway网关实现限流
  4. [转] 2018年冬流感通知
  5. Js获取下拉框当前选择项的文本和值
  6. 美国组建半导体工作组或与中国推进海外并购冲突
  7. Day9-HTML body属性
  8. php--字符串常用函数
  9. 一个以标签为特色的社交网站——易寻
  10. 删除 setup.py 安装的 Python 软件包