Redis Sentinel安装、配置和部署

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介:  转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426   实际中,多个sentinel、master、slave不应该在一台机器       一、准备redis(下载、编译、安装、配置目录、数据目录) 1.


 转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426


 
实际中,多个sentinel、master、slave不应该在一台机器
 

   

一、准备redis(下载、编译、安装、配置目录、数据目录)

1. 下载、编译、安装

cd /opt/soft
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
tar xzf redis-3.0.6.tar.gz
cd redis-3.0.6
make
make install

 

2. 配置目录、数据目录

cd /opt/soft/redis-3.0.6
mkdir -p data
mkdir -p conf

 

3.建立软链接:

ln -s /opt/soft/redis-3.0.6 /opt/soft/redis

 

 

二、配置、启动Redis节点(本例子以1主2从,3个sentinel组成Redis Sentinel结构)

 

(1) 配置redis节点,在conf目录下添加3个(7000,7001,7002)redis-${port}.conf作为3个Redis节点的配置文件

      其中7000是主,7001,7002是从

   

   master的配置文件(7000)

port 7000
daemonize yes
pidfile /var/run/redis-7000.pid
logfile "7000.log"
dbfilename "dump-7000.rdb"
appendonly yes
appendfilename "appendonly-7000.aof"
dir "/opt/soft/redis/data/"

 

   生成两个slave的配置文件(7001,7002)

sed 's/7000/7001/g' redis-7000.conf > redis-7001.conf
echo "slaveof 10.10.53.159 7000" >> redis-7001.conf

sed 's/7000/7002/g' redis-7000.conf > redis-7002.conf
echo "slaveof 10.10.53.159 7000" >> redis-7002.conf

  

 

(2) 启动3个节点。

redis-server /opt/soft/redis/conf/redis-7000.conf
redis-server /opt/soft/redis/conf/redis-7001.conf
redis-server /opt/soft/redis/conf/redis-7002.conf

 

 

 

查看节点是否都已经启动:

[@zw_53_162 conf]# ps -ef | grep redis
root     31869     1  0 22:59 ?        00:00:00 redis-server *:7000         
root     31875     1  0 22:59 ?        00:00:00 redis-server *:7001         
root     31885     1  0 22:59 ?        00:00:00 redis-server *:7002 

 

 

查看主从关系:

[@zw_53_162 conf]# redis-cli -p 7000 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.10.53.159,port=7001,state=online,offset=15,lag=1
slave1:ip=10.10.53.159,port=7002,state=online,offset=15,lag=1
master_repl_offset:15
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:14

 

 

三、启动sentinel节点:

    (1). 启动3个sentinel节点(26379,26380,26381),配置如下:

     redis-sentinel-26379.conf

   

port 26379
daemonize yes
pidfile /var/run/redis-26379.pid
logfile "26379.log"
dir /opt/soft/redis/data
sentinel monitor mymaster 10.10.53.159 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

 

  

   redis-sentinel-26380.conf, redis-sentinel-26381.conf

sed 's/26379/26380/g' redis-sentinel-26379.conf > redis-sentinel-26380.conf
sed 's/26379/26381/g' redis-sentinel-26379.conf > redis-sentinel-26381.conf

   

(2) 启动3个sentinel节点。

redis-sentinel /opt/soft/redis/conf/redis-sentinel-26379.conf
redis-sentinel /opt/soft/redis/conf/redis-sentinel-26380.conf
redis-sentinel /opt/soft/redis/conf/redis-sentinel-26381.conf

 

 

查看节点是否都已经启动:

[@zw_53_162 conf]# ps -ef | grep redis-sentinel
root      2949     1  0 23:09 ?        00:00:00 redis-sentinel *:26379 [sentinel]       
root      2955     1  0 23:09 ?        00:00:00 redis-sentinel *:26380 [sentinel]       
root      2961     1  0 23:09 ?        00:00:00 redis-sentinel *:26381 [sentinel]

 

sentinel的info信息查询:

[@zw_53_162 config]# redis-cli -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=10.10.53.159:7000,slaves=2,sentinels=3

 

    

 

 

 

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
22天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
170 2
|
1月前
|
NoSQL Linux Redis
linux安装redis5.0.5
linux安装redis5.0.5
59 1
|
1月前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
18 0
|
1天前
|
NoSQL Redis Docker
Mac上轻松几步搞定Docker与Redis安装:从下载安装到容器运行实测全程指南
Mac上轻松几步搞定Docker与Redis安装:从下载安装到容器运行实测全程指南
10 0
|
1天前
|
NoSQL Linux Redis
本地虚拟机centos7通过docker安装主从redis3.2
本地虚拟机centos7通过docker安装主从redis3.2
|
3天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
16 0
|
10天前
|
NoSQL Redis Docker
使用docker安装redis
该文档介绍了如何使用Docker快速搭建Redis数据库,以便于Spring Boot学习。主要内容包括获取Redis镜像、创建容器、配置持久化存储目录和修改默认配置文件,以及检查和访问Redis容器服务。此外,还提到若需外部访问,需开启宿主机防火墙相应端口。注意,本教程不深入讲解Docker,若想深入学习Docker,建议另寻专门课程。
|
11天前
|
NoSQL Redis
mac下安装redis
mac下安装redis
|
11天前
|
数据安全/隐私保护 Docker Sentinel
docker安装Sentinel
docker安装Sentinel
|
16天前
|
NoSQL Linux Redis
Redis入门到通过之Redis安装
Redis入门到通过之Redis安装
25 0