资讯专栏INFORMATION COLUMN

redis主从配置

zhaot / 1870人阅读

摘要:下载检查一下看有没有问题安装完之后,会在目录下生成几个可执行文件,分别是。其中是启动服务的,是进入客户端的。

1、下载redis3.2.3

wget http://download.redis.io/releases/redis-3.2.3.tar.gz
tar -zxvf redis-3.2.3.tar.gz
cd redis-3.2.3
make
make test //检查一下 看有没有问题
make install

安装完之后,会在src目录下生成几个可执行文件,分别是mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server。其中redis-server是启动Redis服务的,redis-cli是进入Redis客户端的。

mkdir etc
mkdir bin
mv redis.conf etc/
mv sentinel.conf etc/
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-sentinel redis-server redis-trib.rb redis-cli ../bin
cp -R /usr/local/jenkins/redis/redis-3.2.3                                  /usr/local/jenkins/redis/redis-master-3.2.3
   cp -R /usr/local/jenkins/redis/redis-3.2.3     /usr/local/jenkins/redis/redis-slave-3.2.3

2、配置主从redis

cd  /usr/local/jenkins/redis/redis-master-3.2.3/etc/
cp redis.conf master.conf
cd  /usr/local/jenkins/redis/redis-slave-3.2.3/etc/
cp redis.conf slave_6380.conf
cp redis.conf slave_6381.conf
mkdir  /usr/local/jenkins/redis/redis-master-3.2.3/logs
mkdir  /usr/local/jenkins/redis/redis-master-3.2.3/run
mkdir  /usr/local/jenkins/redis/redis-slave-3.2.3/logs
mkdir  /usr/local/jenkins/redis/redis-slave-3.2.3/run

修改主配置文件master.conf

port 6379
pidfile /usr/local/jenkins/redis/redis-master-3.2.3/run/redis_6379.pid
# slaveof  
logfile "/usr/local/jenkins/redis/redis-master-3.2.3/logs/redis.master.log"
requirepass 123456
daemonize yes
bind 0.0.0.0
masterauth 123456

修改从配置文件slave_6380.conf(slave_6381.conf)

port 6380
pidfile /usr/local/jenkins/redis/redis-slave-3.2.3/run/redis_6380.pid
slaveof 127.0.0.1 6379
logfile "/usr/local/jenkins/redis/redis-slave-3.2.3/logs/redis.slave6380.log"
requirepass 123456
daemonize yes
bind 0.0.0.0
masterauth 123456

3、启动redis

./redis-server /usr/local/jenkins/redis/redis-master-3.2.3/etc/master.conf 

./redis-server /usr/local/jenkins/redis/redis-slave-3.2.3/etc/slave_6380.conf 
./redis-server /usr/local/jenkins/redis/redis-slave-3.2.3/etc/slave_6381.conf

主redis打印的日志

启动哨兵

 ./redis-sentinel /usr/local/jenkins/redis/redis-slave-3.2.3/etc/sentinel_26379.conf
 ./redis-sentinel /usr/local/jenkins/redis/redis-slave-3.2.3/etc/sentinel_26380.conf
 ./redis-sentinel /usr/local/jenkins/redis/redis-slave-3.2.3/etc/sentinel_26381.conf

sentinel_26379.conf配置文件

port 26379
dir /usr/local/jenkins/redis/redis-sentinel-3.2.3/tmp26379
daemonize yes
logfile "/usr/local/jenkins/redis/redis-sentinel-3.2.3/logs/redis.sentinel26379.log"
sentinel monitor mymaster 192.168.1.135 6379 1
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

查看信息:

redis-cli -h 127.0.0.1 -p 6379 -a 123456 info replication
redis-cli -h 127.0.0.1 -p 6380 -a 123456 info replication

用redis-cli工具登录其中一个哨兵

./redis-cli -p 26379

连接成功后运行如下命令

sentinel master mymaster

4、测试
登录主redis

 ./redis-cli -h 127.0.0.1 -p 6379 -a 123456
set name zhangsan
set addr shanghai
set curTime 2016-07-11

登录从reids

./redis-cli -h 127.0.0.1 -p 6380
get name
get addr
get curTime

5、测试主redis宕机,切换从reids为主
关闭主redis

./redis-cli  -h 127.0.0.1 -p 6379 -a 123456 shutdown

切换从reids为主reids

./redis-cli -p 6380 -a 123456 slaveof NO ONE

测试从redis是否切换从主redis是否成功

./redis-cli -h 127.0.0.1 -p 6380 -a 123456
set name zhangsan

更多技术文章:

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/70794.html

相关文章

  • Redis主从复制以及主从复制原理

    摘要:前者称为主节点,后者称为从节点数据的复制是单向的,只能由主节点到从节点。主从复制的作用数据冗余主从复制实现了数据的热备份,是持久化之外的一种数据冗余方式。检测主节点当前是否可接受处理命令。 showImg(https://segmentfault.com/img/bVboOAF?w=1772&h=591); Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化...

    snowLu 评论0 收藏0
  • 那一天,我被Redis主从架构支配的恐惧

    摘要:面试官要不你来讲讲你最近在看的点呗可以拉出来一起讨论下今天我也不知道要问什么候选者最近在看相关的内容面试官嗯,我记得已经问过的基础和持久化了面试官要不你来讲讲你公司的是什么架构的咯候选者我前公司的架构是分片集群,使用的是层来对进行分流到不同面试官:要不你来讲讲你最近在看的点呗?可以拉出来一起讨论下(今天我也不知道要问什么)候选者:最近在看「Redis」相关的内容面试官:嗯,我记得已经问过Re...

    curried 评论0 收藏0

发表评论

0条评论

zhaot

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<