redis(二十二):Redis 集群(proxy 型)一
redis伪集群搭建
搭建环境是vmware虚拟机+ubuntu-14.04,以redis伪集群的方式搭建搭建,一共实现了6台机器集群的搭建,三个master节点和三个slave节点。
<pre name="code" class="cpp">#首先安装redis的集群管理需要ruby和zlib
sudo apt-get install zlib ruby
#以及安装和redis有关的ruby package
sudo gem install redis
#下载安装包,编译安装redis-3.0.
mkdir redis
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar -zxvf redis-3.0..tar.gz
cd redis-3.0.
make & make test &make install
编译安装以后,运行redis-server如果打印出以下的结果就表示安装成功了。
<pre name="code" class="cpp">:C Oct ::12.324 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
:M Oct ::12.325 # You requested maxclients of requiring at least max file descriptors.
:M Oct ::12.325 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
:M Oct ::12.326 # Current maximum open files is . maxclients has been reduced to to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 61702
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Oct ::12.332 # Server started, Redis version 3.0.
:M Oct ::12.332 # WARNING overcommit_memory is set to ! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
:M Oct ::12.332 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
:M Oct ::12.333 # WARNING: The TCP backlog setting of cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of .
:M Oct ::12.333 * The server is now ready to accept connections on port
然后我们关闭掉已经打开的redis-server程序,开始伪集群的搭建。
首先在redis-3.0.0目录下创建cluster目录
<pre name="code" class="cpp">ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ mkdir cluster
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ cd cluster
#创建node-.conf node-.conf node-.conf node-.conf node-.conf node-.conf
#这些分别是7000,,,,,7005六个节点的redis-server配置文件
#配置文件内容如下
ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7000.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7000.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7001.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7001.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7002.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7002.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7003.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7003.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7004.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7004.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ cat node-.conf
pidfile /home/ubuntu/redis-3.0./cluster/pid/node7005.pid
logfile "/home/ubuntu/redis-3.0.0/cluster/logs/node-7005.log"
dir /home/ubuntu/redis-3.0./cluster/data/node-
port
daemonize yes
cluster-enabled yes
cluster-config-file node-.conf
cluster-node-timeout
appendonly yes
最后在cluster目录下创建log data文件夹,以及node-7000.log node-7001.log node-7002.log node-7003.log #node-7004.log node-7005.log等6哥log文件,最后cluster目录下的文件如下:
<pre name="code" class="cpp">ubuntu@ubuntu-virtual-machine:~/redis-3.0./cluster$ ls
data node-.conf node-.conf node-.conf node-.conf node-.conf node-.conf
logs node-.log node-.log node-.log node-.log node-.log node-.log
最后,配置文件都ok了,开始启动6个”单机”redis-server服务,启动命令如下:
<pre name="code" class="cpp">ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ redis-server cluster/node-.conf
把每一台机器加入集群中
<pre name="code" class="cpp">ubuntu@ubuntu-virtual-machine:~/redis-3.0.$ ./src/redis-trib.rb create --replicas 192.168.39.153: 192.168.39.153: 192.168.39.153: 192.168.39.153: 192.168.39.153: 192.168.39.153:
打印出以下的结果,就代表集群启动成功了。
<pre name="code" class="cpp">: 192.168.39.153: 192.168.39.153:
>>> Creating cluster
Connecting to node 192.168.39.153:: OK
Connecting to node 192.168.39.153:: OK
Connecting to node 192.168.39.153:: OK
Connecting to node 192.168.39.153:: OK
Connecting to node 192.168.39.153:: OK
Connecting to node 192.168.39.153:: OK
>>> Performing hash slots allocation on nodes...
Using masters:
192.168.39.153:
192.168.39.153:
192.168.39.153:
Adding replica 192.168.39.153: to 192.168.39.153:
Adding replica 192.168.39.153: to 192.168.39.153:
Adding replica 192.168.39.153: to 192.168.39.153:
M: 57d0ccdc7dc98ab786c961e0979b8a8f135f60cd 192.168.39.153:
slots:- ( slots) master
M: adfbf48901b1e7e7e7e2fe0a1b87c86f57530ebd 192.168.39.153:
slots:- ( slots) master
M: 314cbd10bbc4c1339fb737575af41f04408c2087 192.168.39.153:
slots:- ( slots) master
S: fb2d1830a4b429fcb80da7edbbdacc50ed439d63 192.168.39.153:
replicates 57d0ccdc7dc98ab786c961e0979b8a8f135f60cd
S: 1384a16ccb208828d9634f49695556ae11ec57a7 192.168.39.153:
replicates adfbf48901b1e7e7e7e2fe0a1b87c86f57530ebd
S: 9d9350c96c50fe88621575047a6a07250a287b51 192.168.39.153:
replicates 314cbd10bbc4c1339fb737575af41f04408c2087
Can I set the above configuration? (type 'yes' to accept): yes#这里输入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.39.153:)
M: 57d0ccdc7dc98ab786c961e0979b8a8f135f60cd 192.168.39.153:
slots:- ( slots) master
M: adfbf48901b1e7e7e7e2fe0a1b87c86f57530ebd 192.168.39.153:
slots:- ( slots) master
M: 314cbd10bbc4c1339fb737575af41f04408c2087 192.168.39.153:
slots:- ( slots) master
M: fb2d1830a4b429fcb80da7edbbdacc50ed439d63 192.168.39.153:
slots: ( slots) master
replicates 57d0ccdc7dc98ab786c961e0979b8a8f135f60cd
M: 1384a16ccb208828d9634f49695556ae11ec57a7 192.168.39.153:
slots: ( slots) master
replicates adfbf48901b1e7e7e7e2fe0a1b87c86f57530ebd
M: 9d9350c96c50fe88621575047a6a07250a287b51 192.168.39.153:
slots: ( slots) master
replicates 314cbd10bbc4c1339fb737575af41f04408c2087
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
至此,一个集群就搭建起来了,从上边的信息我们也可以看出来,192.168.39.153:7000,192.168.39.153:7001,192.168.39.153:7002是master节点,另外三个是slave节点。
本文参考了http://lib.csdn.net/article/redis/35915
————————————————
版权声明:本文为CSDN博主「mindlesslcc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sanwenyublog/article/details/52946669
redis(二十二):Redis 集群(proxy 型)一的更多相关文章
- redis(二)redis的主从模式和集群模式
redis(二)redis的主从模式和集群模式 主从模式 集群模式 主从模式 redis的主从模式,指的是针对多台redis实例时候,只存在一台主服务器master,提供读写的功能,同时存在依附在这台 ...
- 关于redis主从|哨兵|集群模式
关于redis主从.哨兵.集群的介绍网上很多,这里就不赘述了. 一.主从 通过持久化功能,Redis保证了即使在服务器重启的情况下也不会损失(或少量损失)数据,因为持久化会把内存中数据保存到硬盘上,重 ...
- 深入学习Redis(5):集群
前言 在前面的文章中,已经介绍了Redis的几种高可用技术:持久化.主从复制和哨兵,但这些方案仍有不足,其中最主要的问题是存储能力受单机限制,以及无法实现写操作的负载均衡. Redis集群解决了上述问 ...
- Spring Boot+redis存储session,满足集群部署、分布式系统的session共享
本文讲述spring-boot工程中使用spring-session机制进行安全认证,并且通过redis存储session,满足集群部署.分布式系统的session共享. 原文链接:https://w ...
- redis主从|哨兵|集群模式
关于redis主从.哨兵.集群的介绍网上很多,这里就不赘述了. 一.主从 通过持久化功能,Redis保证了即使在服务器重启的情况下也不会损失(或少量损失)数据,因为持久化会把内存中数据保存到硬盘上,重 ...
- Redis哨兵、复制、集群的设计原理与区别
一 前言 谈到Redis服务器的高可用,如何保证备份的机器是原始服务器的完整备份呢?这时候就需要哨兵和复制. 哨兵(Sentinel):可以管理多个Redis服务器,它提供了监控,提醒以及自动的故障转 ...
- Redis之高可用、集群、云平台搭建
原文:Redis之高可用.集群.云平台搭建 文章大纲 一.基础知识学习二.Redis常见的几种架构及优缺点总结三.Redis之Redis Sentinel(哨兵)实战四.Redis之Redis Clu ...
- Redis运维实战之集群中的脑裂
1.对于分布式Redis主从集群来说,什么是脑裂? 所谓的脑裂,就是指在主从集群中,同时有两个主节点,它们都能接收写请求.而脑裂最直接的影响,就是客户端不知道应该往哪个主节点写入数据,结果就是不同的客 ...
- Redis 实战篇之搭建集群
Redis 集群简介# Redis Cluster 即 Redis 集群,是 Redis 官方在 3.0 版本推出的一套分布式存储方案.完全去中心化,由多个节点组成,所有节点彼此互联.Redis 客户 ...
- Redis.之.环境搭建(集群)
Redis.之.环境搭建(集群) 现有环境: /u01/app/ |- redis # 单机版 |- redis-3.2.12 # redis源件 所需软件:redis-3.0.0.gem -- ...
随机推荐
- laravel表单中文错误提示本地化
<?php return [ /* |-------------------------------------------------------------------------- | V ...
- (七)MySQL常见的数据类型、约束和标识列
一.MySQL常见数据类型 1.数值型: ①整型:tinyint.smllint.mediumint.int/integer.bigint 图源:尚硅谷李玉婷 案例1:关键表格teacher,分别添加 ...
- TensorFlow从0到1之XLA加速线性代数编译器(9)
加速线性代数器(Accelerated linear algebra,XLA)是线性代数领域的专用编译器.根据 https://www.tensorflow.org/performance/xla/, ...
- (六)获取http状态码和处理返回结果
int StatusCode = httpResponse.getStatusLine().getStatusCode(); 处理返回结果: /** * 处理返回结果 * @param respons ...
- 使用vscode 开发go项目的最新姿势. go版本1.14.2
使用了go 1.14.2. 版本, 再也不用建src, pkg, bin 目录了, 以及再也不用强制配置GOPATH了 前提条件: 必须是 go mod 项目. 在工程目录下, 执行这样的命令生成 ...
- GitHub 热点速览 Vol.25:距离优雅编程你差个它
作者:HelloGitHub-小鱼干 摘要:如何优雅地夸一个程序员呢?vscode-rainbow-fart 作为一个彩虹屁的项目,深得程序员心,能在你编程时疯狂称赞你的除了你自己,还有它.除了鼓励之 ...
- 一小时彻底搞懂RabbitMQ
windows上面安装rabbitmq-server-3.7.4.exe 首先需要安装otp_win64_20.3.exe 步骤1:安装Erlang RabbitMQ 它依赖于Erlang,需要先安装 ...
- Spring IoC component-scan 节点详解
前言 我们在了解 Spring 容器的扩展功能 (ApplicationContext) 之前,先介绍下 context:component-scan 标签的解析过程,其作用很大是注解能生效的关键所在 ...
- 作为一个Java开发你用过Jib吗
1. 前言 Jib是Google开发的可以直接构建 Java应用的Docker和OCI镜像的类库,以Maven和Gradle插件形式提供.它最骚操作的是可以在没有Docker守护程序的情况下构建,也就 ...
- Apache Dubbo Provider默认反序列漏洞复现(CVE-2020-1948)
Apache Dubbo Provider默认反序列漏洞(CVE-2020-1948) 0x01 搭建漏洞环境 漏洞介绍 2020年06月23日, 360CERT监测发现Apache Dubbo 官方 ...