redis集群搭建与管理
server1:172.16.16.34
server2:172.16.16.35
redis版本:redis3.
搭建环境:redis集群,server1有7001,7002,7003三主,server2有7001,7002,7003三从,总共六个节点。这样做是为了保证redis的集群的高可用。redis的复制也是采用异步复制的方式。
cd /home/maxiangqian
tar xzf redis-3.2..tar.gz
cd redis-3.2.
yum install gcc
make
2:创建redis目录文件夹
mkdir /home/redis7001/data
mkdir -p /home/redis7001/data /home/redis7001/log /home/redis7001/tmp
mkdir -p /home/redis7002/data /home/redis7002/log /home/redis7002/tmp
mkdir -p /home/redis7003/data /home/redis7003/log /home/redis7003/tmp
3:为server1和server2的三个节点分别配置配置文件
port
timeout daemonize yes
pidfile "/home/redis7001/tmp/redis_7001.pid" loglevel notice
logfile "/home/redis7001/log/redis_7001.log" databases
save
save
save
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/home/redis7001/data" slave-serve-stale-data yes
#slave-read-only yes # yes开启从库只读
repl-diskless-sync no
repl-diskless-sync-delay
repl-disable-tcp-nodelay no
slave-priority appendonly yes
#appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage
auto-aof-rewrite-min-size 64mb lua-time-limit
slowlog-log-slower-than
slowlog-max-len
latency-monitor-threshold requirepass "maxiangqianredis"
masterauth "maxiangqianredis" #cluster
cluster-enabled yes
cluster-config-file /home/redis7001/nodes7001.conf
cluster-node-timeout
上面是redis7001的配置文件内容
redis-server /home/redis7001/redis7001.conf
我们看一下启动日志:
:M May ::53.444 * No cluster configuration found, I'm 363ecec54c92c2548dcab016146bdb4c104e5e84
server1
server1
server1
server2
server2
server2
OK,现在已经有六个已经启动的redis实例了。我们下一步开始做集群
redis-trib.rb create --replicas 10.103.16.34: 10.103.16.34: 10.103.16.34: 10.103.16.35: 10.103.16.35: 10.103.16.35:
执行报错:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb::in `gem_original_require': no such file to load -- redis (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb::in `require'
from /home/maxiangqian/redis-3.2./src/redis-trib.rb:
我们需要安装以下几个包:
yum -y install zlib ruby rubygems
gem install redis
然后重新启动创建集群的操作:
[root@localhost redis7003]# redis-trib.rb create --replicas 10.103.16.34: 10.103.16.34: 10.103.16.34: 10.103.16.35: 10.103.16.35: 10.103.16.35:
>>> Creating cluster
[ERR] Sorry, can't connect to node 10.103.16.34:7001
又报错了我擦。
requirepass "maxiangqianredis"
masterauth "maxiangqianredis"
群集认证是要配置完成再添加的,而且两个参数配置必须一样,我们现在暂时不配置认证模式:
[root@localhost redis7003]# redis-trib.rb create --replicas 10.103.16.34: 10.103.16.34: 10.103.16.34: 10.103.16.35: 10.103.16.35: 10.103.16.35:
>>> Creating cluster
>>> Performing hash slots allocation on nodes...
Using masters:
10.103.16.35:
10.103.16.34:
10.103.16.35:
Adding replica 10.103.16.34: to 10.103.16.35:
Adding replica 10.103.16.35: to 10.103.16.34:
Adding replica 10.103.16.34: to 10.103.16.35:
M: 363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34:
slots:- ( slots) master
S: 93a0e8d405959480fcbd310a5d15a92346c69d43 10.103.16.34:
replicates d015a22abc57c021f568973f4f1c03c7a5c7b772
S: 78f77749f9f9a5f0d7c99427e0311912a3fa04e7 10.103.16.34:
replicates 89147e5837e378b69233dd2b8290267975719bc4
M: d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35:
slots:- ( slots) master
M: 89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35:
slots:- ( slots) master
S: ce9d635236567ccde4c864f78863fa0a4b26f25a 10.103.16.35:
replicates 363ecec54c92c2548dcab016146bdb4c104e5e84
Can I set the above configuration? (type 'yes' to accept):
OK,已经提示成功了,我们直接选择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 10.103.16.34:)
M: 363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34:
slots:- ( slots) master
additional replica(s)
S: 78f77749f9f9a5f0d7c99427e0311912a3fa04e7 10.103.16.34:
slots: ( slots) slave
replicates 89147e5837e378b69233dd2b8290267975719bc4
M: d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35:
slots:- ( slots) master
additional replica(s)
M: 89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35:
slots:- ( slots) master
additional replica(s)
S: ce9d635236567ccde4c864f78863fa0a4b26f25a 10.103.16.35:
slots: ( slots) slave
replicates 363ecec54c92c2548dcab016146bdb4c104e5e84
S: 93a0e8d405959480fcbd310a5d15a92346c69d43 10.103.16.34:
slots: ( slots) slave
replicates d015a22abc57c021f568973f4f1c03c7a5c7b772
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
这样群集就设置成功了。
[root@mxqmongodb2 sa]# redis-cli -c -p
127.0.0.1:> get name
-> Redirected to slot [] located at 10.103.16.34:
"txt"
10.103.16.34:> exit
[root@mxqmongodb2 sa]# redis-cli -c -p
127.0.0.1:> get name
-> Redirected to slot [] located at 10.103.16.34:
"txt"
10.103.16.34:> exit
[root@mxqmongodb2 sa]# redis-cli -c -p
127.0.0.1:> get name
-> Redirected to slot [] located at 10.103.16.34:
"txt"
5:我们接下来查看一下集群的基本信息:
[root@localhost redis7003]# redis-cli -p cluster nodes
78f77749f9f9a5f0d7c99427e0311912a3fa04e7 10.103.16.34: slave 89147e5837e378b69233dd2b8290267975719bc4 connected
d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35: master - connected -
89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35: master - connected -
ce9d635236567ccde4c864f78863fa0a4b26f25a 10.103.16.35: slave 363ecec54c92c2548dcab016146bdb4c104e5e84 connected
93a0e8d405959480fcbd310a5d15a92346c69d43 10.103.16.34: slave d015a22abc57c021f568973f4f1c03c7a5c7b772 connected
363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34: myself,master - connected -
可以看到现在的集群有六个节点,三个主节点和三个从节点。而且每个主节点都会记录自己分配的哈希槽,从中我们可以看到
103.16.: master - connected -
10.103.16.34: myself,master - connected -
10.103.16.35: master - connected -
当然我们也可以对这些节点的哈希槽进行重新的分配,我们现在打算将103.16.35:7001的前100个哈希槽移动到10.103.16.34:7001
[root@localhost redis7003]# redis-trib.rb reshard 10.103.16.34:
然后会提示我输入数值以及从哪里迁移到哪里:
How many slots do you want to move (from to )?
What is the receiving node ID? 363ecec54c92c2548dcab016146bdb4c104e5e84
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #:d015a22abc57c021f568973f4f1c03c7a5c7b772
Source node #:done
执行完以后就可以进行迁移了,迁移完以后我们再打印出来节点信息看一下:
[root@localhost redis7003]# redis-cli -p cluster nodes
78f77749f9f9a5f0d7c99427e0311912a3fa04e7 10.103.16.34: slave 89147e5837e378b69233dd2b8290267975719bc4 connected
d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35: master - connected -
89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35: master - connected -
ce9d635236567ccde4c864f78863fa0a4b26f25a 10.103.16.35: slave 363ecec54c92c2548dcab016146bdb4c104e5e84 connected
93a0e8d405959480fcbd310a5d15a92346c69d43 10.103.16.34: slave d015a22abc57c021f568973f4f1c03c7a5c7b772 connected
363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34: myself,master - connected - -
我们可以很清楚的看到已经迁移成功了。
[root@localhost redis7003]# redis-cli -p cluster nodes | grep master
d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35: master - connected -
89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35: master - connected -
363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34: myself,master - connected - -
我们现在要使10.103.16.35:7001这个主节点断掉,然后重启看一下基本信息
[root@mxqmongodb2 sa]# /home/maxiangqian/redis-3.2./src/redis-cli -p
127.0.0.1:> SHUTDOWN
not connected> exit
[root@mxqmongodb2 sa]# redis-server /home/redis7001/redis7001.conf
然后再打印一下集群信息看一下:
[root@localhost redis7003]# redis-cli -p cluster nodes
78f77749f9f9a5f0d7c99427e0311912a3fa04e7 10.103.16.34: slave 89147e5837e378b69233dd2b8290267975719bc4 connected
d015a22abc57c021f568973f4f1c03c7a5c7b772 10.103.16.35: slave 93a0e8d405959480fcbd310a5d15a92346c69d43 connected
89147e5837e378b69233dd2b8290267975719bc4 10.103.16.35: master - connected -
ce9d635236567ccde4c864f78863fa0a4b26f25a 10.103.16.35: slave 363ecec54c92c2548dcab016146bdb4c104e5e84 connected
93a0e8d405959480fcbd310a5d15a92346c69d43 10.103.16.34: master - connected -
363ecec54c92c2548dcab016146bdb4c104e5e84 10.103.16.34: myself,master - connected - -
通过信息我们可以很明显的看到了10.103.16.35:7001这个主节点已经变成了从节点,而本身他的从节点也上升为主节点了。
./redis-trib.rb add-node 10.103.16.34: 10.103.16.34:
这样我们就把10.103.16.34:7004添加为集群的新的主节点,不过我们要注意的是,这时候他仅仅是一个没有哈希槽的主节点,并不会存储任何数据。
./redis-trib.rb add-node 10.103.16.34: 10.103.16.34:
redis 10.103.16.34::> cluster replicate 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e
将新节点指定为ID为3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e的从节点。
./redis-trib del-node 127.0.0.1: `<node-id>`
但是我们要注意一点,移除主节点的时候必须保证主节点是空的,也就是事先将要移除的主节点的哈希槽给转移到其他的主节点上。
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 ...
- redis集群配置与管理
Redis在3.0版本以后开始支持集群,经过中间几个版本的不断更新优化,最新的版本集群功能已经非常完善.本文简单介绍一下Redis集群搭建的过程和配置方法,redis版本是5.0.4,操作系统是中标麒 ...
- Docker Swarm redis 集群搭建
Docker Swarm redis 集群搭建 环境1: 系统:Linux Centos 7.4 x64 内核:Linux docker 3.10.0-693.2.2.el7.x86_64 Docke ...
- Redis集群搭建的三种方式
一.Redis主从 1.1 Redis主从原理 和MySQL需要主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生性能瓶颈,特别是在读压力上,为了分担压力,Redis支持主从复制. ...
- 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 第一步 ...
随机推荐
- nginx实现多语言跳转不同的url
nginx实现多语言跳转不同的url server { listen 80; server_name www.text.com; location / { if ($http_accept_langu ...
- JAVA学习6:用Maven创建Spring3 MVC项目
一. 环境 spring-framework-3.2.4.RELEASE jdk1.7.0_11 Maven3.0.5 eclipse-jee-juno-SR2-win32 二. ...
- javascript记住用户名和登录密码
javascript记住用户名和登录密码 下面主要通过代码给大家展示下javascript记住用户名和登录密码,具体代码内容请看下文. <script type="text/javas ...
- Cloudera Manager安装之Cloudera Manager安装前准备(Ubuntu14.04)(一)
其实,基本思路跟如下差不多,我就不多详细说了,贴出主要图. 博主,我是直接借鉴下面这位博主,来进行安装的!(灰常感谢他们!) 在线和离线安装Cloudera CDH 5.6.0 Cloudera M ...
- twitter storm常用命令
1.提交Topologies命令格式:storm jar [jar路径] [拓扑包名.拓扑类名][stormIP地址][storm端口][拓扑名称][参数]eg:storm jar /home/sto ...
- Mybatis Dao开发方法(二)
使用Mapper代理的方式进行开发 Mapper开发的原理 使用Mybatis的Mapper代理方式进行开发,使用该方式,只需要编写Mapper接口,不再需要编写实现类,由Mybatis框架通过接 ...
- python-入门教程(-)
# hello worldprint("hello world") # 变量msg = "使用变量"print(msg) # 字符串大小写变换(仅针对英文)na ...
- 新建文件可选类型插件:SublimeTmpl
介绍:SublimeTmpl,新建文件可选类型.编辑模版在:SublimeTmpl\templates"文件夹修改 1.安装: 通过 Package Control Package Cont ...
- Query performance optimization of Vertica
Don't fetch any data that you don't need,or don't fetch any columns that you don't need. Because ret ...
- spring-boot之简单定时任务
首先是pom.xml依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/ ...