• 安装环境

这里使用三台服务器,每台服务器上开启一个redis-server和redis-sentinel服务,redis-server端口为6379,redis-sentinel的端口为26379。

redis-server说明

192.168.10.3:6379  主

192.168.10.4:6379  从

192.168.10.5:6379  从

redis-sentinel说明

192.168.10.3:26379

192.168.10.4:26379

192.168.10.5:26379

目录规划:

配置文件目录:        /data/apps/conf/redis

数据目录:               /data/apps/data/redis_6379

日志目录:               /data/apps/log/redis

pid文件目录:          /data/apps/var/redis

sentinel数据目录:   /data/apps/var/sentinel

  •  安装Redis

操作主机:192.168.10.3 192.168.10.4 192.168.10.5

1、下载redis安装包

下载完毕后使用tar命令解压到当前目录。

[root@localhost ~]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[root@localhost ~]# tar zxvf redis-3.2.8.tar.gz

2、编译redis

进入安装目录下,执行make命令,编译成功后会显示下面内容。

编译后在目录下生成一个src目录,里面会有编译好的执行文件

[root@localhost ~]# cd redis-3.2.8
[root@localhost redis-3.2.8]# make
[root@localhost redis-3.2.8]# cd src && make all
make[1]: Entering directory `/home/redis/redis-3.2.8/src' Hint: It's a good idea to run 'make test' ;) make[1]: Leaving directory `/home/redis/redis-3.2.8/src'

3、安装redis

Redis的默认安装路径是 /usr/local 目录下,进入src目录下,使用vi编辑Makefile文件,在文件中找到“PRIFIX?=/usr/local”,可以修改为你需要安装的目录,这里使用局对路径。

然后执行make install命令进行安装,安装完毕后会在安装目录下生成一些执行文件。

[root@localhost src]# make install
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
[root@localhost ~]# cd /usr/local/bin/
[redis@localhost bin]$ ls
dump.rdb redis-check-aof redis-cli redis-server
redis-benchmark redis-check-rdb redis-sentinel

4、编辑环境变量

[root@localhost ~]# vim /etc/profile.d/redis.sh 
export REDIS_HOME=/usr/local
export PATH=${REDIS_HOME}:bin:${PATH}
[root@localhost ~]# source /etc/profile

5、修改配置文件

vim /data/apps/conf/redis/redis_6379.conf
bind 0.0.0.0
protected-mode no
port
tcp-backlog
timeout
tcp-keepalive
daemonize yes
supervised no
pidfile "/data/apps/var/redis/redis_6379.pid"
loglevel notice
logfile "/data/apps/log/redis/redis_6379.log"
databases
save
save
save
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/apps/data/redis_6379"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay
repl-disable-tcp-nodelay no
slave-priority
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit
slowlog-log-slower-than
slowlog-max-len
latency-monitor-threshold
notify-keyspace-events ""
hash-max-ziplist-entries
hash-max-ziplist-value
list-max-ziplist-size -
list-compress-depth
set-max-intset-entries
zset-max-ziplist-entries
zset-max-ziplist-value
hll-sparse-max-bytes
activerehashing yes
client-output-buffer-limit normal
client-output-buffer-limit slave 256mb 64mb
client-output-buffer-limit pubsub 32mb 8mb
hz
aof-rewrite-incremental-fsync yes
# Generated by CONFIG REWRITE

6、 配置主从复制

192.168.10.3为master,其他两个为slave,只需修改从库的配置文件

操作主机:192.168.10.4、192.168.10.5


[root@localhost ~]# echo 'slaveof 192.168.10.3 6379' >>/data/apps/conf/redis_6379.conf

7 、启动redis-server

操作主机:所有主机

[root@localhost ~]# redis-server /data/apps/conf/redis/redis_6379.conf

8、检查

[root@localhost ~]# redis-cli -h 192.168.10.3 -p 6379
127.0.0.1:6379> info

# Replication
role:master
connected_slaves:2
slave0:ip=192.168.10.5,port=6379,state=online,offset=14874,lag=1
slave1:ip=192.168.10.4,port=6379,state=online,offset=15160,lag=1
master_repl_offset:15303
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:15302

# 出现上面的结果说明主从复制成功

  • 部署redis-sentinel

操作主机:所有主机,每个主机的配置文件相同

1、配置文件

[root@localhost ~]# vim /data/apps/config/redis/redis-sentinel-.conf
port
daemonize yes
protected-mode no
dir "/data/apps/var/sentinel"
pidfile "/data/apps/var/redis/redis-sentinel.pid"
logfile "/data/apps/log/redis/redis-sentinel.log"
sentinel monitor redis_master 192.168.10.3
sentinel down-after-milliseconds redis_master
sentinel failover-timeout redis_master

2、启动sentinel

[root@localhost ~]# redis-sentinel /data/apps/conf/redis/redis-sentinel-.conf

3、检查

[root@localhost ~]# ss -lnt|grep 26379
[root@localhost ~]# redis-cli -p 26379
127.0.0.1:26379> info

# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=redis_master,status=ok,address=192.168.10.3:6379,slaves=2,sentinels=3

# 出现上面的情况说明配置成功

  • 部署Haproxy

1、安装Haproxy

#下载
wget http://fossies.org/linux/misc/haproxy-1.8.12.tar.gz
#解压
tar -zxvf haproxy-1.8..tar.gz
cd haproxy-1.8.
#安装
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
#参数说明
TARGET=linux26 #内核版本,使用uname -r查看内核,如:2.6.-.el5,此时该参数就为linux26;kernel 大于2..28的用:TARGET=linux2628
ARCH=x86_64 #系统位数
PREFIX=/usr/local/haprpxy #/usr/local/haprpxy为haprpxy安装路径

2、配置Haproxy

vim /usr/local/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# ) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# ) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /usr/local/haproxy
pidfile /usr/local/haproxy/haproxy.pid
maxconn
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
log global
mode tcp
retries
option redispatch
maxconn
timeout connect 600s
timeout client 600s
timeout server 600s
listen stats
bind 0.0.0.0:
mode http
stats uri /haproxy-status
stats auth admin:admin
stats hide-version
stats refresh 30s
frontend redis16379
bind :
default_backend redis_16379_backend
backend redis_16379_backend
option tcp-check
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 INFO\ REPLICATION\r\n
tcp-check expect rstring connected_slaves:[-]
tcp-check send QUIT\r\n
tcp-check expect string +OK
server redis1_6379 192.168.10.3: check inter 1s
server redis2_6379 192.168.10.4: check inter 1s
server redis3_6379 192.168.10.5: check inter 1s

3、检查

[root@localhost ~]# redis-cli -p  set a
OK
[root@localhost ~]# redis-cli -p set get a
OK
  • 总结

上面的内容可以解决redis高可用的问题,但是Haproxy还是单点。如果服务器是物理机,Haproxy可以通过Keepalived解决单点问题,实现高可用;但是服务器是ECS的情况下不能使用Keepalived。

Redis高可用方案----Redis主从+Sentinel+Haproxy的更多相关文章

  1. Windows版本redis高可用方案探究

    目录 Windows版本redis高可用方案探究 前言 搭建redis主从 配置主redis-28380 配置从redis-23381 配置从redis-23382 将redis部署为服务 启动red ...

  2. Redis高可用方案-哨兵与集群

    Redis高可用方案 一.名词解释   二.主从复制 Redis主从复制模式可以将主节点的数据同步给从节点,从而保障当主节点不可达的情况下,从节点可以作为 后备顶上来,并且可以保障数据尽量不丢失(主从 ...

  3. Redis高可用之哨兵模式Sentinel配置与启动(五)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  4. 深入理解Redis高可用方案-Sentinel

    Redis Sentinel是Redis的高可用方案.是Redis 2.8中正式引入的. 在之前的主从复制方案中,如果主节点出现问题,需要手动将一个从节点升级为主节点,然后将其它从节点指向新的主节点, ...

  5. redis高可用、redis集群、redis缓存优化

    今日内容概要 redis高可用 redis集群 redis缓存优化 内容详细 1.redis高可用 # 主从复制存在的问题: 1 主从复制,主节点发生故障,需要做故障转移,可以手动转移:让其中一个sl ...

  6. Redis高可用方案哨兵机制------ 配置文件sentinel.conf详解

    Redis的哨兵机制是官方推荐的一种高可用(HA)方案,我们在使用Redis的主从结构时,如果主节点挂掉,这时是不能自动进行主备切换和通知客户端主节点下线的. Redis-Sentinel机制主要用三 ...

  7. 理解redis高可用方案

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  8. redis高可用之REDIS SENTINEL

    1. Redis主从配置 1.1. 设置主从复制 Master <= Salve 10.24.6.5:6379 <= 10.24.6.7:6379 1.2.   取消主从复制 1.3.   ...

  9. 容器化redis高可用方案

    偶然看到一个GITHUB项目,提供了一套Docker Compose下的redis Sentinel方案. 项目地址https://github.com/AliyunContainerService/ ...

随机推荐

  1. 'telnet' 不是内部或外部命令,也不是可运行的程序

    1.打开控制面板 2. 3. 4.这样就好可,重新打开cmd命令.

  2. 实验九 FBG 团队项目需求改进与系统设计

    任务一 A.<项目需求规格说明书>分析 根据老师的指导以及本周所学的OOA,分析改进上周编写的<项目需求规格说明书>,发现需求项目书UML图例描述不够完善,仅仅是用例图没办法更 ...

  3. 环境搭建之allure的安装配置,及简单使用

    环境准备 首先是要安装好jdk的电脑上,运行java.javac这些命令都没有问题,要不安装allure时会报错 下载allure 如果直接用Jenkins上的插件,并不需要下载安装 allure官网 ...

  4. linux文件 特殊权限的使用

    http://www.iqiyi.com/a_19rrh3tui5.html 1.说明 i属性不能修改 a只能追加在6以后 [root@xuegod63 ~]# chattr +i a.txt [ro ...

  5. RobotFramework自动化测试框架-Selenium Web自动化(-)-Open Browser和Close Browser

    Selenium出来已经有很多年了,从最初的Selenium1到后来的Selenium2,也变得越来越成熟,而且也已经被很多公司广泛使用.Selenium发展的过程中,分了很多模块,这里我们主要介绍W ...

  6. Windows下安装和卸载MangoDB服务 --MangoDB

    1.创建存放的数据文件夹和日志文件 2.安装MangoDB服务:(如数据文件夹路径是:d:/MongoDB/db/,日志文件路径:d:/MongoDB/log.txt) mongod --dbpath ...

  7. 【Mac】Mac中如何将相同后缀的所有文件设置指定软件打开

    操作步骤: 以settings.xml文件为例 1.首先选中该文件,鼠标右键打开功能列表,选则查看文件信息 2.在文件信息中,进行相关设置

  8. Python函数分类及操作

    为什么使用函数? 答:函数的返回值可以确切知道整个函数执行的结果   函数的定义:1.数学意义的函数:两个变量:自变量x和因变量y,二者的关系                      2.Pytho ...

  9. JavaScript中全局变量和局部变量的不同

    今天看到大神写得一片文章,自己对全局变量和局部变量的理解还是不够深刻,因此写到这篇文章,做个总结. 大神代码截图+理解文字如下: 解析:上面代码中,变量i是var命令声明的,在全局范围内都有效,所以全 ...

  10. 下面程序的输出结果是____ A:11,10 B:11,11 C:10,10 D:10,11 int x=10; int y=x++; printf("%d,%d",(x++,y),y++);

    下面程序的输出结果是____ A:11,10 B:11,11 C:10,10 D:10,11 int x=10; int y=x++; printf("%d,%d",(x++,y) ...