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 -- ...
随机推荐
- Serval and Parenthesis Sequence【思维】
Serval and Parenthesis Sequence 题目链接(点击) Serval soon said goodbye to Japari kindergarten, and began ...
- 不适合使用Mycat的场景
1.非分片字段查询 Mycat中的路由结果是通过分片字段和分片方法来确定的.例如下图中的一个Mycat分库方案: 根据 tt_waybill 表的 id 字段来进行分片 分片方法为 id 值取 3 的 ...
- matplotlib添加子图(拼图功能)
我们已经知道,matplotlib是python中的一个十分好用的作图库,它的简单的使用方法可以在之前的随笔中找到.传送门:https://www.cnblogs.com/chester-cs/p/1 ...
- GitHub如何回滚代码?
1.git log 查看commit hash值 执行git log:查看commit hash值. 2.执行git reset --hard xxxx xxxx表示的是commit hash 值. ...
- 打个总结:Web性能优化
前段时间优化一个公司历史老项目的Web性能,却引出了一系列的问题,让我反思良多. 我通过Chrome的Lighthouse工具可以看出一些性能参数和问题反馈,我逐一对其进行优化. 根据资源请求的不同, ...
- 图解leetcode5-10 | 和233酱一起刷leetcode系列(2)
本周我们继续来看5道磨人的小妖精,图解leetcode6-10- 多说一句,leetcode10 杀死了233酱不少脑细胞... 另: 沉迷算法,无法自拔.快来加入我们吧! 别忘了233酱的一条龙服务 ...
- Css教程玉女心经版本
视频参见:php中文网css玉女心经视频教程 Css教程玉女心经版本 第1章 :css快速入门 1.1 什么是css 改变html框架的样式. 1.2 css的三种引入形式 第 ...
- keras中loss与val_loss的关系
loss是训练集的损失值,val_loss是测试集的损失值 以下是loss与val_loss的变化反映出训练走向的规律总结: train loss 不断下降,test loss不断下降,说明网络仍在学 ...
- onunload对应的js代码为什么不能执行?和onbeforeunload的区别?
为什么onunload对应的js代码不能执行? 为什么onbeforeunload才可以在离开页面时执行相应的js代码? 1.onunload和onbeforeunload都是在离开页面或者刷新页面的 ...
- Spring-AliasRegistry
使用Spring 的时候我们可以很容易的为某个bean 配置一个或多个别名 <bean id="app:dataSource" class="..."&g ...