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. [转] C++项目中的extern "C" {}

    点击阅读原文 引言 在用C++的项目源码中,经常会不可避免的会看到下面的代码: #ifdef __cplusplus extern "C" { #endif /*...*/ #if ...

  2. 动作函数-web_submit_data

    web_submit_data("login.pl", "Action=http://127.0.0.1:1080/WebTours/login.pl", &q ...

  3. Arduino + RFID 读取 IC 卡 Arduino uno中获得RFID的UID 并通过串口转发RFID卡号

    RFID简介:射频识别即RFID(Radio Frequency IDentification)技术,又称无线射频识别,是一种通信技术,可通过无线电讯号识别特定目标并读写相关数据,而无需识别系统与特定 ...

  4. The following packages will be SUPERCEDED by a higher-priority channel是什么意思?

    参考资料: https://stackoverflow.com/questions/42015732/the-following-packages-will-be-superceded-by-a-hi ...

  5. Android学习笔记:实现层级导航

    层级导航示例 层级导航案例 1.收下准备两个Activity的布局文件 activity_main.xml <?xml version="1.0" encoding=&quo ...

  6. S7-1200视频教程: S7-1200的功能与特点-跟我学 - 1/112

    S7-1200视频教程: S7-1200的功能与特点-跟我学 - 1/112 观看连接: http://www.elearning.siemens.com.cn/video/Course/201012 ...

  7. LeetCode 题解目录

    前言 本目录将不断更新记录leetcode的刷题日记. 二叉树 序号 标题 难度 标签 1 108 将有序数组转换为二叉搜索树 简单 树.深度优先搜索 2 538 把二叉搜索树转换为累加树 简单 树 ...

  8. Springboot项目整合Swagger2报错

    SpringBoot2.2.6整合swagger2.2.2版本的问题,启动SpringBoot报如下错: Error starting ApplicationContext. To display t ...

  9. IOT设备SmartConfig实现

    一般情况下,IOT设备(针对wifi设备)在智能化过程中需要连接到家庭路由.但在此之前,需要将wifi信息(通常是ssid和password,即名字和密码)发给设备,这一步骤被称为配网.移动设备如An ...

  10. Spring WebFlux 01 (原理及使用场景)

    一.什么是 Spring WebFlux 好多人以为Spring WebFlux就是Spring MVC的升级版,其实不然,那到底什么是Spring WebFlux呢,首先就要搞清楚Spring We ...