redis集群配置
首先需要安装redis,可以参考此文档redis3.0.7安装指南 http://stephen830.iteye.com/blog/2289017。
安装完毕后,将解压出来的redis-3.0.7目录复制3份(为什么是3份呢?因为redis做集群至少要3个),将着3份的目录分别取名为redis-3.0.7_01、redis-3.0.7_02、redis-3.0.7_03 ,目录名可以按自己喜好定义。
这样,我们就有了3份的redis,然后分别修改redis-3.0.7_01、redis-3.0.7_02、redis-3.0.7_03目录下的redis.conf配置文件。
===========================
redis.conf 需要修改的参数
===========================
port 6379 #端口号,不要相同,可以分别为6379 6380 6381
bind 192.168.1.2 #本机IP地址
cluster-enabled yes #开启cluster模式,默认是no
cluster-config-file nodes-6379.conf #cluster的配置文件,同端口一样,分别设为nodes-6379.conf、nodes-6380.conf、nodes-6381.conf
cluster-node-timeout 5000 #cluster节点超时参数
appendonly yes
dbfilename dump-6379.rdb #缓存实体化保存文件名,同端口一样,分别设为dump-6379.rdb、dump-6380.rdb、dump-6381.rdb
然后,分别启动这3个目录下redis
/usr/local/redis-3.0.7_01/src/redis-server /usr/local/redis-3.0.7_01/redis.conf &
/usr/local/redis-3.0.7_02/src/redis-server /usr/local/redis-3.0.7_02/redis.conf &
/usr/local/redis-3.0.7_03/src/redis-server /usr/local/redis-3.0.7_03/redis.conf &
redis启动完成后,可以看到如下的提示:
--------------------------------------------------------------------------------------------------
29338:M 13 Apr 21:05:00.214 * No cluster configuration found, I'm a1eec932d923b55e23a5fe6a488ed7a97e27c826
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.0 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in cluster mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 29338
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
29338:M 13 Apr 21:05:00.246 # Server started, Redis version 3.0.0
29338:M 13 Apr 21:05:00.247 * DB loaded from disk: 0.000 seconds
29338:M 13 Apr 21:05:00.247 * The server is now ready to accept connections on port 6379
--------------------------------------------------------------------------------------------------
太多调试信息了,只有一句是最重要的:
No cluster configuration found, I'm a1eec932d923b55e23a5fe6a488ed7a97e27c826
这表示我们的redis服务器正在运行在cluster mode ,但是目前这3个redis尚未组成集群,继续执行下面的命令:
/usr/local/redis-3.0.7_01/src/redis-trib.rb create 10.10.228.163:6379 10.10.228.163:6380 10.10.228.163:6381
执行正常的话,会显示如下提升信息:
>>> Creating cluster
Connecting to node 10.10.228.163:6379: OK
Connecting to node 10.10.228.163:6380: OK
Connecting to node 10.10.228.163:6381: OK
>>> Performing hash slots allocation on 3 nodes...
Using 3 masters:
10.10.228.163:6379
10.10.228.163:6380
10.10.228.163:6381
M: 78a5bbdcd545848be8a66126a71dc69dd6d23bc4 10.10.228.163:6379
slots:0-5460 (5461 slots) master
M: 1f6ed2478b461539f76b0b627de2e1b8565df719 10.10.228.163:6380
slots:5461-10922 (5462 slots) master
M: 7a092b06c8c75e98176b7612e74d2e89e8b3eda7 10.10.228.163:6381
slots:10923-16383 (5461 slots) master
Can I set the above configuration? (type 'yes' to accept):
看上去很美,每个节点负责数据的1/3,键入 ‘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: 78a5bbdcd545848be8a66126a71dc69dd6d23bc4 10.10.228.163:6379
slots:0-5460 (5461 slots) master
M: 1f6ed2478b461539f76b0b627de2e1b8565df719 10.10.228.163:6380
slots:5461-10922 (5462 slots) master
M: 7a092b06c8c75e98176b7612e74d2e89e8b3eda7 10.10.228.163:6381
slots:10923-16383 (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
完成了
------------------------------------------------------------------
redis创建集群时可能会遇到的错误或问题:
------------------------------------------------------------------
错误1:
>>> Creating cluster
[ERR] Sorry, can't connect to node 127.0.0.1:6379
错误1解决方法:由于redis设置了密码,将redis.conf中的requirepass xxx这一行注释掉即可。
------------------------------------------------------------------
错误2:
root@10-10-228-163:/usr/local/redis-3.0.7/src# ./redis-trib.rb create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381
>>> Creating cluster
>>> Performing hash slots allocation on 3 nodes...
Using 3 masters:
127.0.0.1:6379
127.0.0.1:6380
127.0.0.1:6381
M: 4f82f807e8024c083595868c2a0bba81bdf19893 127.0.0.1:6379
slots:0-5460,11144,12596,13595,14103,15358,15369 (5467 slots) master
M: 5102c6d494ed594975f5613a2653e9f3c72d07da 127.0.0.1:6380
slots:3225,3698,5461-10922,11144,12596,13595,14103,15358,15369 (5470 slots) master
M: 05119d158b226c76ac0e83f89bb0e053d4dd1356 127.0.0.1:6381
slots:10923-16383 (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
/var/lib/gems/1.9.1/gems/redis-3.3.0/lib/redis/client.rb:121:in `call': ERR Slot 3225 is already busy (Redis::CommandError)
from /var/lib/gems/1.9.1/gems/redis-3.3.0/lib/redis.rb:2700:in `block in method_missing'
from /var/lib/gems/1.9.1/gems/redis-3.3.0/lib/redis.rb:58:in `block in synchronize'
from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
from /var/lib/gems/1.9.1/gems/redis-3.3.0/lib/redis.rb:58:in `synchronize'
from /var/lib/gems/1.9.1/gems/redis-3.3.0/lib/redis.rb:2699:in `method_missing'
from ./redis-trib.rb:212:in `flush_node_config'
from ./redis-trib.rb:775:in `block in flush_nodes_config'
from ./redis-trib.rb:774:in `each'
from ./redis-trib.rb:774:in `flush_nodes_config'
from ./redis-trib.rb:1295:in `create_cluster_cmd'
from ./redis-trib.rb:1695:in `<main>'
root@10-10-228-163:/usr/local/redis-3.0.7/src#
root@10-10-228-163:/usr/local/redis-3.0.7/src#
错误2解决方法:经检查,这是由于上一次配置集群失败时留下的配置信息导致的。 只要把redis.conf中定义的 cluster-config-file 所在的文件删除,重新启动redis-server及运行redis-trib即可.
------------------------------------------------------------------
错误3:
root@10-10-228-163:/usr/local/redis-3.0.7/src# ./redis-cli -p 6379
127.0.0.1:6379> set key1 zjq
(error) MOVED 9189 127.0.0.1:6380
错误3解决方法:必须带参数-c来连接redis操作,即执行命令: ./redis-cli -c -p 6379
------------------------------------------------------------------
安装ruby:
apt-get install ruby-full
------------------------------------------------------------------
安装ruby所需要的redis模块:
root@10-10-228-163:/usr/local/redis-3.0.7# gem install redis
Fetching: redis-3.3.0.gem (100%)
Successfully installed redis-3.3.0
1 gem installed
Installing ri documentation for redis-3.3.0...
Installing RDoc documentation for redis-3.3.0...
root@10-10-228-163:/usr/local/redis-3.0.7#
如果用gem安装redis失败,可以手动下载redis的gem包
下载地址 https://rubygems.global.ssl.fastly.net/gems/redis-3.3.0.gem
然后使用gem安装命令:
zhoujianqiangdeMacBook-Pro:soft zjq$ sudo gem install -l ./redis-3.3.0.gem
Successfully installed redis-3.3.0
Parsing documentation for redis-3.3.0
Installing ri documentation for redis-3.3.0
Done installing documentation for redis after 1 seconds
1 gem installed
zhoujianqiangdeMacBook-Pro:soft zjq$
------------------------------------------------------------------
java链接redis-cluster
------------------------------------------------------------------
private static BinaryJedisCluster jc;
static {
//只给集群里一个实例就可以
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6380));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6381));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6382));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6383));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 6384));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7380));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7381));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7382));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7383));
jedisClusterNodes.add(new HostAndPort("10.10.34.14", 7384));
jc = new BinaryJedisCluster(jedisClusterNodes);
}
@Test
public void testBenchRedisSet() throws Exception {
final Stopwatch stopwatch = new Stopwatch();
List list = buildBlogVideos();
for (int i = 0; i < 1000; i++) {
String key = "key:" + i;
stopwatch.start();
byte[] bytes1 = protostuffSerializer.serialize(list);
jc.setex(key, 60 * 60, bytes1);
stopwatch.stop();
}
System.out.println("time=" + stopwatch.toString());
}
相关推荐
Redis集群配置文件,包含了三个主节点,三个从节点的配置文件,该配置是在docker中运行,有完整的docker-compose.yml文件,只要修改映射的宿主机的路径为你自己的路径。然后直接docker-compose up既可以完成环境启动...
centos7的redis集群配置文件
Rancher搭建redis集群配置Rancher搭建Rancher搭建redis集群配置Rancher搭建Rancher搭建redis集群配置Rancher搭建Rancher搭建redis集群配置Rancher搭建
标题中的“rancher2.3.6部署redis集群配置教程.pdf”暗示了这份文档是针对特定版本的Rancher软件(版本号2.3.6)的使用教程,旨在指导用户如何部署Redis集群。Rancher是一款开源的容器管理平台,可以用来部署、管理...
查询所有Redis集群配置信息-data-2021-05-06 11_08_34.zip
本篇文章将深入探讨如何在Spring Boot中实现对Redis集群的零配置整合,并介绍使用AOP实现的自定义缓存注解。 首先,让我们来看看"Springboot整合Redis集群,零配置方式"。在Spring Boot中,我们可以通过引入`spring-...
在本文中,我们将深入探讨如何在SpringBoot应用中集成Redis集群以及如何配置Redis服务器。首先,Redis是一个开源的、基于键值对的数据存储系统,常用于数据库、缓存和消息中间件。它以其高性能和易用性而备受青睐。...
Kubernetes Redis 集群配置和教程Kubernetes Redis 集群创建磁盘gcloud compute disks create --size=10GB \ 'redis-1' 'redis-2' 'redis-3' \ 'redis-4' 'redis-5' 'redis-6'创建 Redis 集群配置kubectl create ...
以下将详细介绍如何在SpringCloud中配置和使用Redis集群。 首先,你需要了解Redis集群的基本概念。Redis集群通过数据分片(Sharding)技术,将数据分散存储在多个节点上,每个节点只负责一部分数据,从而实现数据的...
kubernetes-redis-cluster, Kubernetes Redis集群配置和教程 Kubernetes Redis集群创建磁盘gcloud compute disks create --size=10GB 'redis-1' 'redis-2' 'redis-3' 'redis-4' 'red
关于Redis集群配置,虽然压缩包中没有直接包含集群配置文件,但通常Redis集群配置涉及以下几个关键步骤: 1. **初始化节点**:至少需要三个主节点来启动一个Redis集群。每个节点都需要运行`redis-trib.rb`脚本来...
linux本地编译安装redis集群配置redis.conf
### Redis 常用配置详解及集群配置指南 #### 一、Redis 安装与配置详解 Redis 是一款开源的键值存储系统,以其高性能、低延迟的特点在缓存、消息队列等领域有着广泛的应用。下面详细介绍如何安装与配置 Redis。 #...
下面将详细介绍 Redis 集群配置文件中的关键参数和设置。 1. **集群模式启用**:在配置文件中,需通过设置 `cluster-enabled yes` 来开启集群模式。这会告诉 Redis 实例它应该作为一个集群节点运行。 2. **集群...
【Redis集群配置】知识点详解 Redis集群是一种分布式数据存储解决方案,它在Redis 3.0版本中引入,旨在提供高可用性和水平扩展性。以下是Redis集群的关键特性、架构及使用方法的详细介绍: 1. **节点自动发现**: ...
1. 前言 在使用redis集群时,发现...关于Redis集群配置代码此处不贴,直接贴配置监听类代码! redis.host1: 10.113.56.68 redis.port1: 7030 redis.host2: 10.113.56.68 redis.port2: 7031 redis.host3: 10.113.56.6
2. Redis集群配置 3. Redis节点配置 4. jemalloc内存分配器 5. ruby和redis gems 6. 防火墙规则 7. 集群功能 延伸阅读: 1. Redis官方文档:http://www.redis.cn/topics/cluster-tutorial.html 2. Redis集群安装和...