Tag - redis

redis 主备    2017-07-19 22:49:14    847
前提:redis中,主从切换场景中,没有绝对的主和从,只有初始化的主和从,然后当主down后,从就变成主了,而主即使连接上,也是从,不会变为主

1、redis-server的主备关系:

    需要配置的机器,以及主备关系如下

    master:10.118.36.10
    slave1:10.118.36.74
    slave2:10.118.36.161

2、修改redis-server的配置文件:

    切换到redis的根目录
    # cd /home/admin/Downloads/redis-3.0.3

    master配置不变,
    两台slave修改配置文件(# vi redis-3.0.3/redis.conf),添加如下语句,其余用默认配置:
        slaveof 10.118.36.10 6379
3、修改redis-sentinel的配置文件(# vi redis-3.0.3/sentinel.conf),但是这里我使用一个新的文件(# vi redis-3.0.3/sentinel-test.conf):
 
    切换到redis的根目录
    # cd /home/admin/Downloads/redis-3.0.3
    # vi redis-3.0.3/sentinel-test.conf
    三台机器配置相同,如下:
############################代码区域,begin############################
port 26379
#MyMaster
sentinel monitor MyMaster 10.118.36.10 6379 1
sentinel down-after-milliseconds MyMaster 5000
sentinel failover-timeout MyMaster 900000
sentinel parallel-syncs MyMaster 2
############################代码区域,end############################

4、启动redis-server服务和redis-sentinel服务
    切换到redis的根目录
    # cd /home/admin/Downloads/redis-3.0.3
CentOS redis    2017-07-19 22:46:25    782

下载redis的安装包:http://download.redis.io/releases/redis-3.0.3.tar.gz

 

由于我的系统是刚装的,所以需要安装gcc才能编译成功,建议大家都先安装下gcc再安装文件
离线安装gcc方法,请看末尾
yum install gcc

然后再按照下面的方式执行

Installation

Download, extract and compile Redis with:

$ wget http://download.redis.io/releases/redis-3.0.3.tar.gz
$ tar xzf redis-3.0.3.tar.gz
$ cd redis-3.0.3
$ make

The binaries that are now compiled are available in the src directory. Run Redis with:

$ src/redis-server

You can interact with Redis using the built-in client:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
离线安装GCC方法
# rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm # rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm # rpm -ivh cpp-4.4.7-4.el6.x86_64.rpm # rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm # rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm
离线包:http://pan.baidu.com/s/1i3lg73Z

 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/


 
haproxy redis    2017-07-19 22:30:33    1160
环境前提:
    redis sentinel配置,三台主机,且配置运行良好
    

配置文件中添加:

frontend ft_redis
 bind 0.0.0.0:6379 name redis
 default_backend bk_redis

backend bk_redis
 option tcp-check
 tcp-check connect
 tcp-check send PING\r\n
 tcp-check expect string +PONG
 tcp-check send info\ replication\r\n
 tcp-check expect string role:master
 tcp-check send QUIT\r\n
 tcp-check expect string +OK
 server R1 10.118.36.10:6379 check inter 1s
 server R2 10.118.36.74:6379 check inter 1s
 server R3 10.118.5.161:6379 check inter 1s

当结果如下所示,则表示成功,那么试着切换redis的master和slave吧

 

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/