1、安装redis

首页地址:http://redis.io/

下载地址:http://download.redis.io/ 下载最新的源码包

tar -zxvf redis-stable.tar.gz -C /apps/product/
cd /apps/product/redis-stable/
make MALLOC=libc
make install

2、运行

加载配置文件并后台运行

redis-server /apps/product/redis-stable/redis.conf &

#redis-cli (命令行工具)

3、测试

# redis-benchmark --help 获取帮助信息,其中包含压力测试命令样例

实际测试举例

[root@localhost~]# redis-benchmark -t set -c 20 -n 1000000 -r 100000000
====== SET ======
 1000000 requests completed in 8.92 seconds
 20 parallel clients
 3 bytes payload
 keep alive: 1
100.00% <= 0 milliseconds
112095.06 requests per second  

4、主从配置及测试:

主   gc-redis1 10.10.10.15 6379
gc-redis2 10.10.10.16 6379
gc-redis3 10.10.10.17 6379

#主服务器(10.15)上做如下配置,其他默认即可:

[root@gc-redis1 redis-stable]# vim /apps/product/redis-stable/redis.conf
masterauth "xxoo"
requirepass "xxoo"

#从服务器上(10.16,10.17)做如下配置,其他默认即可:

[root@gc-redis2 redis-stable]# vim /apps/product/redis-stable/redis.conf
slaveof 10.10.10.15 6379
masterauth "xxoo"
requirepass "xxoo" [root@gc-redis3 redis-stable]# vim /apps/product/redis-stable/redis.conf
slaveof 10.10.10.15 6379
masterauth "xxoo"
requirepass "xxoo"

#启动主、从redis服务:

redis-server /apps/product/redis-stable/redis.conf &

#主服务器显示信息:

[13997] 03 Nov 09:57:21.045 * Slave ask for synchronization
[13997] 03 Nov 09:57:21.045 * Starting BGSAVE for SYNC
[13997] 03 Nov 09:57:21.046 * Background saving started by pid 14002
[14002] 03 Nov 09:57:21.058 * DB saved on disk
[14002] 03 Nov 09:57:21.059 * RDB: 0 MB of memory used by copy-on-write
[13997] 03 Nov 09:57:21.070 * Background saving terminated with success
[13997] 03 Nov 09:57:21.070 * Synchronization with slave succeeded

#从服务器显示信息:

  [3496] 03 Nov 09:56:41.953 * Connecting to MASTER...
  [3496] 03 Nov 09:56:41.953 * MASTER <-> SLAVE sync started
  [3496] 03 Nov 09:56:41.954 * Non blocking connect for SYNC fired the event.
  [3496] 03 Nov 09:56:41.954 * Master replied to PING, replication can continue...
  [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: receiving 18 bytes from master
  [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: Loading DB in memory
  [3496] 03 Nov 09:56:42.055 * MASTER <-> SLAVE sync: Finished with success
  [3499] 03 Nov 09:56:42.056 * SYNC append only file rewrite performed
  [3499] 03 Nov 09:56:42.057 * AOF rewrite: 0 MB of memory used by copy-on-write
  [3496] 03 Nov 09:56:42.057 * Background append only file rewriting started by pid 3499
  [3496] 03 Nov 09:56:42.154 * Background AOF rewrite terminated with success
  [3496] 03 Nov 09:56:42.154 * Parent diff successfully flushed to the rewritten AOF (0 bytes)
  [3496] 03 Nov 09:56:42.154 * Background AOF rewrite finished successfully

#主服务器查看主从信息

[root@gc-redis1 ~]# redis-cli -h 127.0.0.1 -a xxoo info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.10.10.16,port=6379,state=online,offset=168812144,lag=1
slave1:ip=10.10.10.17,port=6379,state=online,offset=168812144,lag=0
master_repl_offset:168812281
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:167763706
repl_backlog_histlen:1048576

#从服务器查看主从信息

[root@gc-redis2 ~]# redis-cli -h 127.0.0.1 -a xxoo info replication
# Replication
role:slave
master_host:10.10.10.15
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:168809239
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

#写同步测试

 #主服务器 
[root@gc-redis1 ~]# redis-cli -h 127.0.0.1 -a redispass
 
redis 127.0.0.1:6379> set a 123
OK
redis 127.0.0.1:6379> get a
"123"

#从服务器

[root@gc-redis2~]# redis-cli -h 127.0.0.1 -a xxoo
redis 127.0.0.1:6379> get a
 "123"
[root@gc-redis3~]# redis-cli -h 127.0.0.1 -a xxoo
redis 127.0.0.1:6379> get a
 "123"
 
 redis 127.0.0.1:6379> set b 234
 (error) READONLY You can't write against a read only slave. (开起了只读模式,所以从将不能写入数据,可以保证数据只从主服务器同步至从服务器)
#故障测试
#从服务器宕机将自动从主服务器的主从关系中解除
#主服务器宕机,从服务器显示,并且不能自动切换
[15932] 03 Nov 09:46:25.465 * Connecting to MASTER...
[15932] 03 Nov 09:46:25.465 * MASTER <-> SLAVE sync started
[15932] 03 Nov 09:46:25.466 # Error condition on socket for SYNC: Connection refused

5、Redis sentinel配置

主页地址:http://redis.io/topics/sentinel

sentinel主要功能就是为Redis M-S(master,slaves)集群提供了

1)master存活检测

2)集群中M-S服务监控

3) 自动故障转移,M-S角色转换等能力,从一个方面说是提高了redis集群的可用性.

#添加并编辑配置文件/etc/sentinel.conf,新增内容如下,也可在安装文件中负责sentinel配置文件并作适当修改:

[root@gc-redis1 ~]# vim /apps/product/redis-stable/sentinel.conf
port 26379
sentinel monitor mymaster 10.10.10.15 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 20000
sentinel auth-pass mymaster xxoo
sentinel config-epoch mymaster 2
sentinel leader-epoch mymaster 2
----------------------------------------------------------------------------------------------- [root@gc-redis2 ~]# vim /apps/product/redis-stable/sentinel.conf
port 26380
sentinel monitor mymaster 10.10.10.15 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 20000
sentinel auth-pass mymaster xxoo
sentinel config-epoch mymaster 2
sentinel leader-epoch mymaster 2
----------------------------------------------------------------------------------------------
[root@gc-redis3 ~]# vim /apps/product/redis-stable/sentinel.conf
port 26381
sentinel monitor mymaster 10.10.10.15 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 20000
sentinel auth-pass mymaster xxoo
sentinel config-epoch mymaster 2
sentinel leader-epoch mymaster 2  

#在三个服务器中以sentinel模式启动redis-server

启动sentinel
 
[root@gc-redis1 ~]#redis-server /apps/product/redis-stable/sentinel.conf --sentinel &
[root@gc-redis2 ~]#redis-server /apps/product/redis-stable/sentinel.conf --sentinel &
[root@gc-redis3 ~]#redis-server /apps/product/redis-stable/sentinel.conf --sentinel &

#三台服务器sentinel输出:(注意每个机器输出对应的都是另外两台机器的IP)

#关掉主gc-redis1的redis-server服务
#将重新选举主服务器并重新配置连接到新的主服务器:

#查看主从关系:(gc-redis2为主,gc-redis3为从,如果gc-redis1重新启动,也将为从服务器加入到新的集群)

启动redis
redis-server /usr/local/redis-stable/redis.conf &
 
停止redis
redis-cli -a xxoo shutdown
 
启动sentinel
redis-server /usr/local/redis-stable/sentinel.conf --sentinel &
 
查看主备信息:
redis-cli -h 127.0.0.1 -p 6379 -a xxoo info replication

.

参考文档:http://mrcto.blog.51cto.com/1923168/1319542  

  

Redis 安装,主从配置及Sentinel配置自动Failover的更多相关文章

  1. Redis安装及HA(High Availability)配置

    Redis是一种内存数据库,以KEY-VALUE(即键值对)的形式存储数据.这篇文章主要介绍的是Redis安装及配置,所以不对Redis本身作详细介绍了. 下载: http://redis.io/do ...

  2. Redis安装及HA(High Availability)配置(转)

    出处:http://www.cnblogs.com/morvenhuang/p/4184262.html Redis是一种内存数据库,以KEY-VALUE(即键值对)的形式存储数据.这篇文章主要介绍的 ...

  3. 【Redis安装】部署与基本配置 --基于Mac和Linux

    Redis安装与部署[基于Mac和Linux] 一.Redis简介 基于内存的Key-Value高性能NoSQL数据库 二.Redis下载和解压 进入官网下载最新版的Redis,目前是5.0.0,这个 ...

  4. Redis 部署主从哨兵 C#使用,实现自动获取redis缓存 实例1

    源码示例下载链接: https://pan.baidu.com/s/1eTA63T4 密码: un96 实现目标:windows 下安装 一台master服务 一台salve redis服务器 并且哨 ...

  5. redis 安装 主从同步 哨兵模式

    一.redis 的安装1.先将安装包放到linux的一个文件夹下面 2.解压压缩包如图所示 3.解压后进入解压文件 4.安装: make 出现it.s a good idea to run 'make ...

  6. Redis 部署主从哨兵 C#使用,实现自动获取redis缓存 实例2

    资料查找https://www.cnblogs.com/tdws/p/5836122.html https://www.cnblogs.com/lori/p/5794454.html private ...

  7. Redis安装以及主从实现

    Redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串). list(链表).set(集合)和zset(有序 ...

  8. CentO7 安装 redis, 主从配置,Sentinel集群故障转移切换

        一.Redis的安装(前提是已经安装了EPEL)   安装redis: yum -y install redis 启动/停止/重启 Redis 启动服务: systemctl start re ...

  9. docker+redis安装与配置,主从+哨兵模式

    docker+redis安装与配置 docker安装redis并且使用redis挂载的配置启动 1.拉取镜像 docker pull redis:3.2 2.准备准备挂载的目录和配置文件 首先在/do ...

随机推荐

  1. poj1144 求不同割点的个数

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11914   Accepted: 5519 Descript ...

  2. SpringMVC学习系列(8) 之 国际化

    一.基于浏览器请求的国际化实现: 1)在 spring的配置文件中添加 <bean id="messageSource" class="org.springfram ...

  3. Lucene学习笔记

    师兄推荐我学习Lucene这门技术,用了两天时间,大概整理了一下相关知识点. 一.什么是Lucene Lucene即全文检索.全文检索是计算机程序通过扫描文章中的每一个词,对每一个词建立一个索引,指明 ...

  4. OPENGL之矩阵

    前面的若干重要概念中描述了OPENGL中的几个重要变换,而矩阵是线性代数中的重要数学工具,它被用来对这些变换进行数学上的实现. 矩阵主要有以下几种: 模型视图矩阵:模型视图矩阵是个4*4的矩阵,代表经 ...

  5. Java中的异常处理:何时抛出异常,何时捕获异常?

    今天在看hadoop源码时,想想自己最近在做的那个系统,发现很多异常处理的方式不对,还是按照传统的异常处理方式(即:采用返回值来标识程序出现的异常情况).而hadoop中很多方法的声明是有异常抛出的, ...

  6. web api Post 接收不到参数的问题

    前端: 注意两个点: 1. contentType: "application/json" 请求的格式是Json 2. 要用JSON.stringify(customer)序列化对 ...

  7. 对接微信红包时:CA证书出错,请登录微信支付商户平台下载证书

    今天在对接微信支付的微信红包发放时,出现““CA证书出错,请登录微信支付商户平台下载证书”的错误,特此记录一下: 如果你也在对接微信红包,并且你也在这个页面上下载了demo,再就是你也参照了里面的文档 ...

  8. [JAVA 多种方式读取文件]

    package com.file; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream ...

  9. TortoiseSVN 过滤文件(包括已提交和未提交)

    一:svn 设置过滤文件方式 1.选中需要过滤的文件夹或者文件---右键---TortoiseSVN---Add to Ignore list(如果不显示说明该目录已经被添加) 2.在当前工作区域 不 ...

  10. Beta版本冲刺第六天 12.12

    一.站立式会议照片: 二.项目燃尽图: Android端 后台 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 邮箱验证和用户评价的填写 用户评价的查看以 ...