redis集群搭建实践
第一个节点
第一个节点为本地的机器 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集群搭建实践的更多相关文章
- [转载] Redis集群搭建最佳实践
转载自http://blog.csdn.net/sweetvvck/article/details/38315149?utm_source=tuicool 要搭建Redis集群,首先得考虑下面的几个问 ...
- Redis集群搭建最佳实践
要搭建Redis集群.首先得考虑以下的几个问题; Redis集群搭建的目的是什么?或者说为什么要搭建Redis集群? Redis集群搭建的目的事实上也就是集群搭建的目的.全部的集群主要都是为了解决一个 ...
- 分享知识-快乐自己:redis集群搭建
Redis介绍: 1.开源的NoSql数据库 2.C语言编写 3.基于内存运行,并且支持持久化 4.Key value存储 5.是主流的Nosql数据库之一 Redis优点: 1.内存使用方面,表现优 ...
- 25.redis集群搭建笔记
###Redis集群### 0.准备 软件: redis-3.0.0.gem redis-3.0.0.tar.gz#源码 1.安装ruby环境 redis基于ruby槽位计算,hash算法技术,k ...
- Redis 集群搭建详细指南
先有鸡还是先有蛋? 最近有朋友问了一个问题,说毕业后去大城市还是小城市?去大公司还是小公司?我的回答都是大城市!大公司! 为什么这么说呢,你想一下,无论女孩男孩找朋友都喜欢找个子高胸大的.同样的道理嘛 ...
- 二、redis集群搭建
redis集群搭建 redis3.0后支持集群.集群中应该至少有三个节点,每个节点有一备份节点.需要6台服务器.搭建伪分布式,需要6个redis实例.搭建集群的步骤: 一.安装单机版redis 第一步 ...
- redis集群搭建及注意事项
上一篇:redis的安装及注意事项 这里,在一个Linux虚拟机上搭建6个节点的redis伪集群,思路很简单,一台虚拟机上开启6个redis实例,每个redis实例有自己的端口.这样的话,相当于模拟出 ...
- Linux Redis集群搭建与集群客户端实现(Python)
硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...
- Linux Redis集群搭建与集群客户端实现
硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...
随机推荐
- 看看我做的一款 时间轴 插件 timegliderJs
TimegliderJs 是一款基于jQuery的时间轴插件.完成后效果. 介绍 Timeglider JS是一个由javascript支持缩放,数据驱动的时间轴组件.非常适合显示项目历史,项目计划及 ...
- PHP的laravel框架后台实现数据导出excel的功能
要想在PHP后台实现excel导入导出功能,一种简单有效的方法就是使用phpexcel插件. 要使用phpexcel插件,首先需要下载composer,这个工具是专门用来管理项目中库之间的依赖关系的. ...
- MySQL最常用日期时间函数
日期和时间函数 可能的需求: 当前时间是多少.下个月的今天是星期几.统计截止到当前日期前 3 天的收入总和-- 上述需求就需要使用日期和时间函数来实现: MySQL服务器中的三种时区设置: ①系统时区 ...
- [bug] Cannot proceed because system tables used by Event Scheduler were found damaged at server start
本地:mac 10.12.3 mysql 5.6 远程:linux 7.3 mysql 5.7.18. (远程数据库yum安装,又5.6升级到5.7) 步骤:从本地数据库导出数据到远程数据库 ...
- 存储容量和IOPS的关系
在云计算时代,数据量成几何形式增加,必然会考虑增加存储容量,但是增加存储容量不简单存储性能得到提升,他们之间没有必然的联系: 存储容量,就是指存储设备上能够存储数据的大小,比如,一个磁盘阵列有50T的 ...
- express4.x的使用
①.安装 npm install -g express ②.创建应用 express [目录] 会在目录下生成 node_modules, 存放所有的项目依赖库.(每个项目管理自己的依赖,与Ma ...
- 一个想法照进现实-《IT连》创业项目:创业时该不该用新手程序员
前言: 距离上一篇文章,转眼已然一个多月了,这段时间没出来和大伙汇报创业的进度,怪我了. 最近又感冒了,已经一个多星期了,还在感冒中,不过感冒也不能偷懒了,每天都有大把的事情等着我解决~~~ 不过今天 ...
- iOS刨根问底-深入理解RunLoop
开源的RunloopRef 通常所说的RunLoop指的是NSRunloop或者CFRunloopRef,CFRunloopRef是纯C的函数,而NSRunloop仅仅是CFRunloopRef的OC ...
- 获取安卓的SH1安全码
用于获取手机联系人 信息 public static String sHA1(Context context) { try { PackageInfo info = context.getPac ...
- [ERR] Node 172.168.63.202:7001 is not empty. Either the nodealready knows other nodes (check with CLUSTER NODES) or contains some
关于启动redis集群时: [ERR] Node 172.168.63.202:7001 is not empty. Either the nodealready knows other nodes ...