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 型)一的更多相关文章

  1. redis(二)redis的主从模式和集群模式

    redis(二)redis的主从模式和集群模式 主从模式 集群模式 主从模式 redis的主从模式,指的是针对多台redis实例时候,只存在一台主服务器master,提供读写的功能,同时存在依附在这台 ...

  2. 关于redis主从|哨兵|集群模式

    关于redis主从.哨兵.集群的介绍网上很多,这里就不赘述了. 一.主从 通过持久化功能,Redis保证了即使在服务器重启的情况下也不会损失(或少量损失)数据,因为持久化会把内存中数据保存到硬盘上,重 ...

  3. 深入学习Redis(5):集群

    前言 在前面的文章中,已经介绍了Redis的几种高可用技术:持久化.主从复制和哨兵,但这些方案仍有不足,其中最主要的问题是存储能力受单机限制,以及无法实现写操作的负载均衡. Redis集群解决了上述问 ...

  4. Spring Boot+redis存储session,满足集群部署、分布式系统的session共享

    本文讲述spring-boot工程中使用spring-session机制进行安全认证,并且通过redis存储session,满足集群部署.分布式系统的session共享. 原文链接:https://w ...

  5. redis主从|哨兵|集群模式

    关于redis主从.哨兵.集群的介绍网上很多,这里就不赘述了. 一.主从 通过持久化功能,Redis保证了即使在服务器重启的情况下也不会损失(或少量损失)数据,因为持久化会把内存中数据保存到硬盘上,重 ...

  6. Redis哨兵、复制、集群的设计原理与区别

    一 前言 谈到Redis服务器的高可用,如何保证备份的机器是原始服务器的完整备份呢?这时候就需要哨兵和复制. 哨兵(Sentinel):可以管理多个Redis服务器,它提供了监控,提醒以及自动的故障转 ...

  7. Redis之高可用、集群、云平台搭建

    原文:Redis之高可用.集群.云平台搭建 文章大纲 一.基础知识学习二.Redis常见的几种架构及优缺点总结三.Redis之Redis Sentinel(哨兵)实战四.Redis之Redis Clu ...

  8. Redis运维实战之集群中的脑裂

    1.对于分布式Redis主从集群来说,什么是脑裂? 所谓的脑裂,就是指在主从集群中,同时有两个主节点,它们都能接收写请求.而脑裂最直接的影响,就是客户端不知道应该往哪个主节点写入数据,结果就是不同的客 ...

  9. Redis 实战篇之搭建集群

    Redis 集群简介# Redis Cluster 即 Redis 集群,是 Redis 官方在 3.0 版本推出的一套分布式存储方案.完全去中心化,由多个节点组成,所有节点彼此互联.Redis 客户 ...

  10. Redis.之.环境搭建(集群)

    Redis.之.环境搭建(集群) 现有环境: /u01/app/ |- redis # 单机版 |- redis-3.2.12    # redis源件 所需软件:redis-3.0.0.gem -- ...

随机推荐

  1. 完美解决PYQT5登录界面跳转主界面方法

    该问题,有很多种方法,但是很多方法要么这个有问题,要么那个有问题,最后终于找到一种没问题的方法.记录一下: Login.py(登录窗口)文件 import sys from PyQt5 import ...

  2. 2019-02-03 线性表的顺序储存结构C语言实现

    #include<cstdio> #define MAXSIZE 20 typedef int Elemtype; //Elemtype类型根据实际情况而定,这里取int typedef ...

  3. Phoenix入门到实战(一)

      问题导读1.你认为Apache Phoenix与HBase的关系是什么?2.Phoenix安装需要哪些软件?3.如何部署Phoenix? Introduction Apache Phoenix i ...

  4. (三)JavaMail发送附件

    代码如下: package cases; import com.sun.mail.util.MailSSLSocketFactory; import javax.activation.DataHand ...

  5. 使用LaTeX输入矩阵

    当前各种文本编辑器支持的LaTeX数学公式库大多基于KaTeX,或者在Web中用MathJax的比较多,下面给出一种在Web中输入矩阵的例子 $$\left[ \begin{array}{cccc}a ...

  6. Android学习笔记长按事件的处理

    常见的长按事件 代码示例: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedIns ...

  7. Android选项卡学习

    什么是选项卡 顶部的导航条就是选项卡了. Android开发中添加选项卡的步骤 图片不太懂上代码: activity_main.xml <?xml version="1.0" ...

  8. Linux 半连接队列,全连接队列

    socket 中 listen api中参数backlog指定的是 全队列大小 accept api是从全队列中获取, 没有就阻塞了, 直到有新连接进来. listen中指定的值大小,有一个最大上限, ...

  9. el-checkbox实现全选与单选

    实现目的:实现全选与多选,点击确定的时候获取每个值的id传给后台 1.HTML <el-checkbox v-model="checkAll" @change="h ...

  10. c++11新特性注意点

    本文记录下一些c++11新特性需要注意的方面,供日后参考 一.auto auto可以当成“占位符”,根据右边的类型自动推导出变量的类型.需要注意的是 auto不能解决溢出的问题. auto可以与指针和 ...