参考

第一个节点

第一个节点为本地的机器 IP:192.168.23.148

检查机器配置

$ uname -a
Linux wangya-Lenovo-G480 4.8.0-52-generic #55~16.04.1-Ubuntu SMP Fri Apr 28 14:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/cpuinfo
...
model name : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
...

安装包

解压

$ cd  /home/wangya/dev/redis
$ tar zxvf redis-3.2.9.tar.gz

编译安装

$ cd redis-3.2.9/
$ make && make install

出现下面的结果

make[1]: Leaving directory '/home/wangya/dev/redis/redis-3.2.9/src'
cd src && make install
make[1]: Entering directory '/home/wangya/dev/redis/redis-3.2.9/src' Hint: It's a good idea to run 'make test' ;) INSTALL install
install: 无法创建普通文件'/usr/local/bin/redis-server': 权限不够
Makefile:266: recipe for target 'install' failed
make[1]: *** [install] Error 1
make[1]: Leaving directory '/home/wangya/dev/redis/redis-3.2.9/src'
Makefile:9: recipe for target 'install' failed
make: *** [install] Error 2

先暂时不管报错,按照提示执行 // TODO

$ make test

等个2分钟左右,显示如下

          The End

Execution time of different units:
0 seconds - unit/printver
0 seconds - unit/type/incr
1 seconds - unit/auth
...
...
...
110 seconds - unit/type/list-3
93 seconds - unit/obuf-limits
106 seconds - integration/replication-psync \o/ All tests passed without errors! Cleanup: may take some time... OK
make[1]: Leaving directory '/home/wangya/dev/redis/redis-3.2.9/src'

集群

$ mkdir redis_cluster
$ cd redis_cluster/
$ mkdir 7000 7001 7002
$ cd ..
$ cp redis.conf redis_cluster/7000
$ cp redis.conf redis_cluster/7001
$ cp redis.conf redis_cluster/7002

依次修改对应的配置文件

port 7000                              //端口7000,7002,7003
bind 192.168.23.148
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 15000 //释放 默认15秒,可自行设置
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志 

启动

$ cd /home/wangya/dev/redis/redis-3.2.9
$ ./src/redis-server redis_cluster/7000/redis.conf
$ ./src/redis-server redis_cluster/7001/redis.conf
$ ./src/redis-server redis_cluster/7002/redis.conf

查看进程

$ ps -ef | grep redis
wangya 14113 1670 0 16:16 ? 00:00:00 ./src/redis-server 192.168.23.148:7000 [cluster]
wangya 14129 1670 0 16:17 ? 00:00:00 ./src/redis-server 192.168.23.148:7001 [cluster]
wangya 14133 1670 0 16:17 ? 00:00:00 ./src/redis-server 192.168.23.148:7002 [cluster]
wangya 14158 7556 0 16:18 pts/0 00:00:00 grep --color=auto
$ netstat -tnlp | grep redis
(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)
tcp 0 0 192.168.23.148:7000 0.0.0.0:* LISTEN 14113/redis-server
tcp 0 0 192.168.23.148:7001 0.0.0.0:* LISTEN 14129/redis-server
tcp 0 0 192.168.23.148:7002 0.0.0.0:* LISTEN 14133/redis-server
tcp 0 0 192.168.23.148:17000 0.0.0.0:* LISTEN 14113/redis-server
tcp 0 0 192.168.23.148:17001 0.0.0.0:* LISTEN 14129/redis-server
tcp 0 0 192.168.23.148:17002 0.0.0.0:* LISTEN 14133/redis-server

第二个节点

第二个节点为Mac主机 IP:192.168.23.149

配置

$ uname -a
Darwin lanjingdeMacBook-Pro.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

参考相同的办法搭建

$ ps -ef | grep redis
501 93858 1 0 5:33下午 ?? 0:00.07 ./src/redis-server 192.168.23.149:7003 [cluster]
501 93863 1 0 5:33下午 ?? 0:00.07 ./src/redis-server 192.168.23.149:7004 [cluster]
501 93865 1 0 5:34下午 ?? 0:00.06 ./src/redis-server 192.168.23.149:7005 [cluster]
501 93910 64442 0 5:35下午 ttys002 0:00.00 grep redis

创建集群

执行

$ ./src/redis-trib.rb create --replicas 1 192.168.23.148:7000  192.168.23.148:7001  192.168.23.148:7002 192.168.23.149:7003 192.168.23.149:7004  192.168.23.149:7005

结果出错

$ ./src/redis-trib.rb create --replicas 1 192.168.23.148:7000  192.168.23.148:7001  192.168.23.148:7002 192.168.23.149:7003 192.168.23.149:7004  192.168.23.149:7005
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./src/redis-trib.rb:25:in `<main>'

这说明需要提供ruby访问redis的客户端

$ gem install redis

安装一下就OK啦

如果没有Ruby,或者版本太低的话,那么根据自己平台自行安装

最后再次执行上面的命令

$ ./src/redis-trib.rb create --replicas 1 192.168.23.148:7000  192.168.23.148:7001  192.168.23.148:7002 192.168.23.149:7003 192.168.23.149:7004  192.168.23.149:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.23.148:7000
192.168.23.149:7003
192.168.23.148:7001
Adding replica 192.168.23.149:7004 to 192.168.23.148:7000
Adding replica 192.168.23.148:7002 to 192.168.23.149:7003
Adding replica 192.168.23.149:7005 to 192.168.23.148:7001
M: 3e491c2f1b74776887198004628c27a402b02235 192.168.23.148:7000
slots:0-5460 (5461 slots) master
M: d44d2b25b051f390fa97a696f65a04cbd11d438d 192.168.23.148:7001
slots:10923-16383 (5461 slots) master
S: 01ade8ffc5e11a8ab646be5550f0ca9d53ef70cd 192.168.23.148:7002
replicates ad24d813be329053df26993e8cb529a0fb350695
M: ad24d813be329053df26993e8cb529a0fb350695 192.168.23.149:7003
slots:5461-10922 (5462 slots) master
S: fddfa2c20518c42733bf3680b2fb6b5d0e1c9a2d 192.168.23.149:7004
replicates 3e491c2f1b74776887198004628c27a402b02235
S: e35177d7f5b1378ec24a6cf7b31a0a8bda2385cf 192.168.23.149:7005
replicates d44d2b25b051f390fa97a696f65a04cbd11d438d
Can I set the above configuration? (type 'yes' to accept): 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.23.148:7000)
M: 3e491c2f1b74776887198004628c27a402b02235 192.168.23.148:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: fddfa2c20518c42733bf3680b2fb6b5d0e1c9a2d 192.168.23.149:7004
slots: (0 slots) slave
replicates 3e491c2f1b74776887198004628c27a402b02235
S: 01ade8ffc5e11a8ab646be5550f0ca9d53ef70cd 192.168.23.148:7002
slots: (0 slots) slave
replicates ad24d813be329053df26993e8cb529a0fb350695
M: ad24d813be329053df26993e8cb529a0fb350695 192.168.23.149:7003
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: e35177d7f5b1378ec24a6cf7b31a0a8bda2385cf 192.168.23.149:7005
slots: (0 slots) slave
replicates d44d2b25b051f390fa97a696f65a04cbd11d438d
M: d44d2b25b051f390fa97a696f65a04cbd11d438d 192.168.23.148:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

搭建完成

测试

$ ./src/redis-cli -h 192.168.23.148 -c -p 7001
192.168.23.149:7003> set age 26
-> Redirected to slot [741] located at 192.168.23.148:7000
OK
192.168.23.148:7000> keys *
1) "age"
192.168.23.148:7000> get age
"26"
192.168.23.148:7000> get name
-> Redirected to slot [5798] located at 192.168.23.149:7003
"wangya"
192.168.23.149:7003> keys *
1) "name"

然后换第二节点获取数据

$ ./src/redis-cli -h 192.168.23.149 -c -p 7004
192.168.23.149:7004> get name
-> Redirected to slot [5798] located at 192.168.23.149:7003
"wangya"
192.168.23.149:7003> get age
-> Redirected to slot [741] located at 192.168.23.148:7000
"26"
192.168.23.148:7000> keys *
1) "age"
192.168.23.148:7000>

测试通过

redis集群搭建实践的更多相关文章

  1. [转载] Redis集群搭建最佳实践

    转载自http://blog.csdn.net/sweetvvck/article/details/38315149?utm_source=tuicool 要搭建Redis集群,首先得考虑下面的几个问 ...

  2. Redis集群搭建最佳实践

    要搭建Redis集群.首先得考虑以下的几个问题; Redis集群搭建的目的是什么?或者说为什么要搭建Redis集群? Redis集群搭建的目的事实上也就是集群搭建的目的.全部的集群主要都是为了解决一个 ...

  3. 分享知识-快乐自己:redis集群搭建

    Redis介绍: 1.开源的NoSql数据库 2.C语言编写 3.基于内存运行,并且支持持久化 4.Key value存储 5.是主流的Nosql数据库之一 Redis优点: 1.内存使用方面,表现优 ...

  4. 25.redis集群搭建笔记

    ###Redis集群### 0.准备 软件: redis-3.0.0.gem redis-3.0.0.tar.gz#源码   1.安装ruby环境 redis基于ruby槽位计算,hash算法技术,k ...

  5. Redis 集群搭建详细指南

    先有鸡还是先有蛋? 最近有朋友问了一个问题,说毕业后去大城市还是小城市?去大公司还是小公司?我的回答都是大城市!大公司! 为什么这么说呢,你想一下,无论女孩男孩找朋友都喜欢找个子高胸大的.同样的道理嘛 ...

  6. 二、redis集群搭建

    redis集群搭建 redis3.0后支持集群.集群中应该至少有三个节点,每个节点有一备份节点.需要6台服务器.搭建伪分布式,需要6个redis实例.搭建集群的步骤: 一.安装单机版redis 第一步 ...

  7. redis集群搭建及注意事项

    上一篇:redis的安装及注意事项 这里,在一个Linux虚拟机上搭建6个节点的redis伪集群,思路很简单,一台虚拟机上开启6个redis实例,每个redis实例有自己的端口.这样的话,相当于模拟出 ...

  8. Linux Redis集群搭建与集群客户端实现(Python)

    硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...

  9. Linux Redis集群搭建与集群客户端实现

    硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...

随机推荐

  1. USACO Section 1.1-1 Your Ride Is Here

    USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...

  2. webpack搭建服务器,随时修改刷新

    前提:1.对webpack有一定了解,本文不做介绍 2.安装node.js 手把手操作: 1.创建一个名为webpack-server的文件夹(随便取的) 2.cd到当前文件夹:cd webpack- ...

  3. 利用jackson-databind,复杂对象对象和json数据互转

    如果简单对象,那么转换的方式比较多,这里指的复杂对象,是指对象里面存在cycle引用,比如: /** * @author ding * */@Entity@Table(name = "ser ...

  4. JS比较思维模型

    在这里,要分享的JS中两种思维方式: 1)面向对象风格示例: function Foo(who){ this.me = who; } Foo.prototype.identify = function ...

  5. HTTP长连接、短连接使用及测试

    概念 HTTP短连接(非持久连接)是指,客户端和服务端进行一次HTTP请求/响应之后,就关闭连接.所以,下一次的HTTP请求/响应操作就需要重新建立连接. HTTP长连接(持久连接)是指,客户端和服务 ...

  6. 如何给远程主机开启mysql远程登录权限

    # 如何给远程主机开启mysql远程登录权限 > 在千锋学习PHP的有些学员会在阿里或者腾讯云去购买自己的云服务器.在初级阶段的项目上线时会遇到一个问题,就是无法使用远程连接工具操作自己线上的m ...

  7. Javascript中call和apply

    在上一章http://www.cnblogs.com/meiyh/p/6207671.html 我有提到javascript很重要的this关键字,现在我们结合这个关键字使用的下面的两个关键字: ca ...

  8. Windows7 x64 编译Dlib库

    最近用到Dlib库,需要先编译. 本文利用 cmake + Sublime Text 2 + MinGW实现编译. 1. 下载dlib源码[dlib18.17]http://pan.baidu.com ...

  9. 前端工作日常爬坑之——单页面微信开发Jssdk相关,以及jssdk图片直传自己服务器的实现。

    日常爬坑 遇到的情况大致说明: 项目基于Vue2全家桶实现,vue-router控制前端路由,路由模式是History(主要是领导追求太高,觉得hash带#号太丑,然后遇到了小坑...),主要是服务于 ...

  10. 发送验证码(××s后重新发送)

    html: <input class="tel" type="text" name="tel" placeholder="手 ...