Redis哨兵模式(sentinel)部署记录(主从复制、读写分离、主从切换)

部署环境: CentOS7.5 

192.168.94.11 (master)

192.168.94.22 (slave0)

192.168.94.33 (slave1)

192.168.94.44 (slave2)

所有节点都需要安装redis+sentinel

[[email protected] ~]# tar xf redis-4.0.11.tar.gz -C  /usr/local/src/
[[email protected] ~]# cd /usr/local/src/redis-4.0.11/
[[email protected] redis-4.0.11]# make && make PREFIX=/usr/local/redis install
[[email protected] redis-4.0.11]# cd /usr/local/redis/
[[email protected] redis]# mkdir run conf log dir
[[email protected] redis]# ln -s /usr/local/redis/bin/* /usr/local/bin/

所有节点修改redis和sentinel配置文件

[[email protected] redis]# cp /usr/local/src/redis-4.0.11/redis.conf conf/
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /usr/local/redis/run/redis_6379.pid
loglevel notice
logfile "/usr/local/redis/log/redis_6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/dir
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# slave上要添加一条: slaveof 192.168.94.11 6379

[[email protected] redis]# cp /usr/local/src/redis-4.0.11/sentinel.conf conf/
[[email protected] ~]# grep -Ev "^#|^$" /usr/local/redis/conf/sentinel.conf
port 26379
pidfile "/usr/local/redis/run/redis-sentinel.pid"
dir "/usr/local/redis/dir/"
daemonize yes
protected-mode no
logfile "/usr/local/redis/log/redis-sentinel.log"
sentinel monitor mymaster 192.168.94.11 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 60000 

添加redis到系统服务

[[email protected] redis]# cp /usr/local/src/redis-4.0.11/utils/redis_init_script /etc/init.d/redis
[[email protected] ~]# vim /etc/init.d/redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/usr/local/redis/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/conf/redis.conf"
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

[[email protected] redis]# chkconfig --add redis
[[email protected] redis]# systemctl daemon-reload

所有节点启动redis、sentinel服务器

[[email protected] redis]# systemctl start redis
[[email protected] redis]# systemctl status redis
● redis.service - LSB: Redis data structure server
   Loaded: loaded (/etc/rc.d/init.d/redis; bad; vendor preset: disabled)
   Active: active (running) since 三 2018-09-05 17:31:43 CST; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5933 ExecStart=/etc/rc.d/init.d/redis start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/redis.service
           └─5935 /usr/local/bin/redis-server 0.0.0.0:6379

9月 05 17:31:43 master systemd[1]: Starting LSB: Redis data structure server...
9月 05 17:31:43 master redis[5933]: Starting Redis server...
9月 05 17:31:43 master systemd[1]: Started LSB: Redis data structure server.

[[email protected] redis]# redis-sentinel /usr/local/redis/conf/sentinel.conf
[[email protected] redis]# netstat -antup|grep 26379
tcp        0      0 0.0.0.0:26379           0.0.0.0:*               LISTEN      23409/redis-sentine
tcp6       0      0 :::26379                :::*                    LISTEN      23409/redis-sentine 

查看redis和sentinel信息

# 查看节点redis的主从关系
[[email protected] redis]# redis-cli -h 192.168.94.11 -p 6379 info|grep role
role:master
[[email protected] redis]# redis-cli -h 192.168.94.22 -p 6379 info|grep role
role:slave
[[email protected] redis]# redis-cli -h 192.168.94.33 -p 6379 info|grep role
role:slave
[[email protected] redis]# redis-cli -h 192.168.94.44 -p 6379 info|grep role
role:slave

# 查看master节点信息
[[email protected] redis]# redis-cli -h 192.168.94.11 -p 6379 info Replication
# Replication
role:master
connected_slaves:3
slave0:ip=192.168.94.33,port=6379,state=online,offset=23362,lag=1
slave1:ip=192.168.94.44,port=6379,state=online,offset=23362,lag=1
slave2:ip=192.168.94.22,port=6379,state=online,offset=23362,lag=1
master_replid:bf73c242b680e63743aa9d46b510ad1aee56105e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:23503
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:23503

# 查看master的sentinel配置文件 , 末尾被写入如下内容
[[email protected] redis]# grep -Ev ‘^#|^$‘ /usr/local/redis/conf/sentinel.conf
port 26379
dir "/usr/local/redis/dir"
sentinel myid 2b92a48338bcd05968782fb3e4af432ad388e1c6
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.94.11 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 60000
pidfile "/usr/local/redis/run/redis_sentinel.pid"
logfile "/usr/local/redis/log/redis_sentinel.log"
daemonize yes
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.94.33 6379
sentinel known-slave mymaster 192.168.94.22 6379
sentinel known-slave mymaster 192.168.94.44 6379
sentinel known-sentinel mymaster 192.168.94.33 26379 cd7c8822acb184eb1af4f96710fc93f5073cfc65
sentinel known-sentinel mymaster 192.168.94.44 26379 be0477f4855b523160d2e487172b94dc1a4c6181
sentinel known-sentinel mymaster 192.168.94.22 26379 f464afa0fb23eb3561e2a448b10a01cdee130d06
sentinel current-epoch 0

# 查看slave0的节点信息
[[email protected] ~]# redis-cli -h 192.168.94.33 -p 6379 info Replication
# Replication
role:slave
master_host:192.168.94.11
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:142968
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:bf73c242b680e63743aa9d46b510ad1aee56105e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:142968
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:142968

# 查看slave的sentinel配置文件 , 在末尾处被写入如下内容
[[email protected] ~]# grep -Ev ‘^#|^$‘ /usr/local/redis/conf/sentinel.conf
port 26379
dir "/usr/local/redis/dir"
sentinel myid cd7c8822acb184eb1af4f96710fc93f5073cfc65
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.94.11 6379 3
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 60000
pidfile "/usr/local/redis/run/redis_sentinel.pid"
logfile "/usr/local/redis/log/redis_sentinel.log"
daemonize yes
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.94.22 6379
sentinel known-slave mymaster 192.168.94.33 6379
sentinel known-slave mymaster 192.168.94.44 6379
sentinel known-sentinel mymaster 192.168.94.22 26379 f464afa0fb23eb3561e2a448b10a01cdee130d06
sentinel known-sentinel mymaster 192.168.94.11 26379 2b92a48338bcd05968782fb3e4af432ad388e1c6
sentinel known-sentinel mymaster 192.168.94.44 26379 be0477f4855b523160d2e487172b94dc1a4c6181
sentinel current-epoch 0
# 其他slave节点也是一样的

测试客户端写入数据

[[email protected] redis]# redis-cli -h 192.168.94.11 -p 6379
192.168.94.11:6379> set mywife limingming
OK
192.168.94.11:6379> get mywife
"limingming"
192.168.94.11:6379> exit
# 客户端连接任意slave节点get上面的数据
[[email protected] redis]# redis-cli -h 192.168.94.22 -p 6379
192.168.94.22:6379> get mywife
"limingming"
192.168.94.22:6379> set limingming xiaoxiannv
(error) READONLY You can‘t write against a read only slave.

# 测试可见 , master节点可以写入 , slave节点默认是只读 ,不能写入
到这就已经实现主从复制 , 读写分离了 

通过sentinel实现主从切换 , sentinel需要做高可用防止单点

# 关闭任意slave节点 , 查看状态
[[email protected] redis]# redis-cli -h 192.168.94.22 -p 6379
192.168.94.22:6379> get mywife
"limingming"
192.168.94.22:6379> SHUTDOWN
not connected> exit

# 查看剩余节点信息
[[email protected] redis]# redis-cli -h 192.168.94.11 -p 6379 info replication
# Replication
role:master
connected_slaves:2     # 由3变成2了 , 减少了一台slave
slave0:ip=192.168.94.33,port=6379,state=online,offset=410139,lag=1
slave1:ip=192.168.94.44,port=6379,state=online,offset=410280,lag=0
master_replid:bf73c242b680e63743aa9d46b510ad1aee56105e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:410280
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:410280

# 在任意节点查看sentinel日志 ,  发现slave已经是sdown状态
[[email protected] redis]# tailf /usr/local/redis/log/redis_sentinel.log
23409:X 05 Sep 19:02:26.759 * +sentinel sentinel f464afa0fb23eb3561e2a448b10a01cdee130d06 192.168.94.22 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:27.287 * +sentinel sentinel be0477f4855b523160d2e487172b94dc1a4c6181 192.168.94.44 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:27.551 * +sentinel sentinel cd7c8822acb184eb1af4f96710fc93f5073cfc65 192.168.94.33 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:35.097 * +slave slave 192.168.94.33:6379 192.168.94.33 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:35.098 * +slave slave 192.168.94.44:6379 192.168.94.44 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:36.796 # +sdown sentinel f464afa0fb23eb3561e2a448b10a01cdee130d06 192.168.94.22 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:37.327 # +sdown sentinel be0477f4855b523160d2e487172b94dc1a4c6181 192.168.94.44 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:37.560 # +sdown sentinel cd7c8822acb184eb1af4f96710fc93f5073cfc65 192.168.94.33 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:45.100 * +slave slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:24:46.255 # +sdown slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379

# 然后重启上面被关闭的节点 ,  所有节点的sentinel都可以检测到slave已处于可用状态,此时再来查看节点的主从信息
[[email protected] redis]# redis-cli -h 192.168.94.11 -p 6379 info replication
# Replication
role:master
connected_slaves:3
slave0:ip=192.168.94.33,port=6379,state=online,offset=5900717,lag=1
slave1:ip=192.168.94.44,port=6379,state=online,offset=5900858,lag=1
slave2:ip=192.168.94.22,port=6379,state=online,offset=5900858,lag=1
master_replid:bf73c242b680e63743aa9d46b510ad1aee56105e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:5900858
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:4852283
repl_backlog_histlen:1048576

# 日志已经显示slave进入-sdown状态
[[email protected] redis]# tailf /usr/local/redis/log/redis_sentinel.log
23409:X 05 Sep 19:02:26.759 * +sentinel sentinel f464afa0fb23eb3561e2a448b10a01cdee130d06 192.168.94.22 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:27.287 * +sentinel sentinel be0477f4855b523160d2e487172b94dc1a4c6181 192.168.94.44 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:27.551 * +sentinel sentinel cd7c8822acb184eb1af4f96710fc93f5073cfc65 192.168.94.33 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:35.097 * +slave slave 192.168.94.33:6379 192.168.94.33 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:35.098 * +slave slave 192.168.94.44:6379 192.168.94.44 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:36.796 # +sdown sentinel f464afa0fb23eb3561e2a448b10a01cdee130d06 192.168.94.22 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:37.327 # +sdown sentinel be0477f4855b523160d2e487172b94dc1a4c6181 192.168.94.44 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:37.560 # +sdown sentinel cd7c8822acb184eb1af4f96710fc93f5073cfc65 192.168.94.33 26379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:02:45.100 * +slave slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
23409:X 05 Sep 19:24:46.255 # +sdown slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
23409:X 06 Sep 00:53:01.203 * +reboot slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
23409:X 06 Sep 00:53:01.261 # -sdown slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379

关掉master节点 , 观察slave节点

[[email protected] ~]# redis-cli -h 192.168.94.11 -p 6379
192.168.94.11:6379> SHUTDOWN

# 在任意节点查看sentinel日志 , 发现master已经是+sdown的状态
[[email protected] ~]# tailf /usr/local/redis/log/redis_sentinel.log
1279:X 06 Sep 11:06:30.806 * +slave-reconf-done slave 192.168.94.33:6379 192.168.94.33 6379 @ mymaster 192.168.94.11 6379
1279:X 06 Sep 11:06:30.869 * +slave-reconf-sent slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
1279:X 06 Sep 11:06:31.821 * +slave-reconf-inprog slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
1279:X 06 Sep 11:06:31.821 * +slave-reconf-done slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.11 6379
1279:X 06 Sep 11:06:31.910 # +failover-end master mymaster 192.168.94.11 6379
1279:X 06 Sep 11:06:31.911 # +switch-master mymaster 192.168.94.11 6379 192.168.94.44 6379
1279:X 06 Sep 11:06:31.911 * +slave slave 192.168.94.33:6379 192.168.94.33 6379 @ mymaster 192.168.94.44 6379
1279:X 06 Sep 11:06:31.911 * +slave slave 192.168.94.22:6379 192.168.94.22 6379 @ mymaster 192.168.94.44 6379
1279:X 06 Sep 11:06:31.911 * +slave slave 192.168.94.11:6379 192.168.94.11 6379 @ mymaster 192.168.94.44 6379
1279:X 06 Sep 11:06:41.995 # +sdown slave 192.168.94.11:6379 192.168.94.11 6379 @ mymaster 192.168.94.44 6379

[[email protected] ~]# redis-cli -h 192.168.94.22 -p 6379 info |grep role
role:slave
[[email protected] ~]# redis-cli -h 192.168.94.33 -p 6379 info |grep role
role:slave
[[email protected] ~]# redis-cli -h 192.168.94.44 -p 6379 info |grep role
role:master

[[email protected] ~]# redis-cli -h 192.168.94.44 -p 6379 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.94.33,port=6379,state=online,offset=224153,lag=0
slave1:ip=192.168.94.22,port=6379,state=online,offset=223730,lag=1
master_replid:6b197e5e8a9f6b146558a21552e7eb9f30926289
master_replid2:086f725685de634b2b3efd546d150a370e461d07
master_repl_offset:224153
second_repl_offset:62861
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:224153

# 可以看出 , 当master节点(192.168.94.11)的redis关闭后 , slave节点(192.168.94.44)变成了新的master

# 在这个新的master上进行写的操作是可以执行的
[[email protected] ~]# redis-cli -h 192.168.94.44 -p 6379
192.168.94.44:6379> set mywife limingming
OK
192.168.94.44:6379> get mywife
"limingming"

# 重启192.168.94.11节点的redis , 等待所有节点的sentinel都检测到后 ,查看所有节点的主从信息 , 现有的master节点是不会被强占去的 , 而原来192.168.94.11节点的角色由master变成了slave
[[email protected] ~]# redis-cli -h 192.168.94.44 -p 6379 info | grep role
role:master
[[email protected] ~]# redis-cli -h 192.168.94.22 -p 6379 info | grep role
role:slave
[[email protected] ~]# redis-cli -h 192.168.94.33 -p 6379 info | grep role
role:slave
[[email protected] ~]# redis-cli -h 192.168.94.11 -p 6379 info | grep role
role:slave

[[email protected] ~]# redis-cli -h 192.168.94.44 -p 6379 info replication
# Replication
role:master
connected_slaves:3
slave0:ip=192.168.94.33,port=6379,state=online,offset=406595,lag=0
slave1:ip=192.168.94.22,port=6379,state=online,offset=406595,lag=0
slave2:ip=192.168.94.11,port=6379,state=online,offset=406595,lag=0
master_replid:6b197e5e8a9f6b146558a21552e7eb9f30926289
master_replid2:086f725685de634b2b3efd546d150a370e461d07
master_repl_offset:406595
second_repl_offset:62861
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:406595
# 所有slave将同步新的master上的信息 主从故障切换已经实现了

原文地址:https://www.cnblogs.com/bigdevilking/p/9595557.html

时间: 2024-07-28 14:24:52

Redis哨兵模式(sentinel)部署记录(主从复制、读写分离、主从切换)的相关文章

Redis哨兵模式(Sentinel)的搭建

一.Redis的哨兵模式 Sentinel是Redis官方提供的一种高可用方案(除了Sentinel,Redis Cluster是另一种方案),它可以自动监控Redis master/slave的运行状态,如果发现master无法访问了,就会启动failover把其中一台可以访问的slave切换为master,并且通过pub/sub事件通知Redis客户端新的master的ip地址. 支持Sentinel的Redis客户端(例如java的Jedis)会在连接Redis服务器的时候向Sentine

Redis哨兵模式集群部署

上次搭测试环境的时候写了一个redis哨兵模式搭建的博客,不幸的是我的博客网站挂掉了,这次搭生产环境再将redis哨兵模式集群模式搭建记录一次.(博客园不会丢掉我的数据吧..) 本次部署包含三个节点,一个主节点,两个从节点,从节点上面有两个哨兵(sentinel). 一.将需要安装redis压缩包上传到其中一台服务器的/usr/local目录下. cd /usr/local //进入文件夹tar -xvf redis-5.0.4.tar.gz //解压cd redis-5.0.4 //进入目录m

Redis哨兵(Sentinel)模式

Redis哨兵(Sentinel)模式 主从切换技术的方法是:当主服务器宕机后,需要手动把一台从服务器切换为主服务器,这就需要人工干预,费事费力,还会造成一段时间内服务不可用.这不是一种推荐的方式,更多时候,我们优先考虑哨兵模式. 一.哨兵模式概述 哨兵模式是一种特殊的模式,首先Redis提供了哨兵的命令,哨兵是一个独立的进程,作为进程,它会独立运行.其原理是哨兵通过发送命令,等待Redis服务器响应,从而监控运行的多个Redis实例. Redis哨兵 这里的哨兵有两个作用 通过发送命令,让Re

Redis 哨兵模式与Redis集群

第1章 Redis哨兵模式: 1.1 sentinel的功能: 1.      监控,sentinel会不断的检查你的主服务器和从服务器是否运行正常 2.      提醒.当被监控的某个redis服务器出现问题时,sentinel可以通过API向管理员或者其他应用程序发送通知 3.      自动故障迁移 1.2 服务器连接: 1.2.1 sentinel通过用户配置的配置文件来发现主服务器 sentinel会与被监视的主服务器创建两个网络连接: 1.      命令连接用于向主服务器发送命令

Spring 集成Redis哨兵模式

Spring 集成Redis哨兵模式 1.pom文件添加以下jar <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.7.2.RELEASE</version> </dependency> <!-- redis客户端jar -->

Redis哨兵模式的配置

绪论 现有三台设备,192.168.137.11.192.168.137.12和192.168.137.13,要求在三台设备上实现redis哨兵模式,其中192.168.137.11为master,其他两台为slave. 1.在Master上配置redis.conf文件 配置文件内容如下: protected-mode no (关闭保护模式) port 6379 daemonize yes (设置redis在后台启动) pidfile /var/run/redis_6379.pid logfil

Springboot2.x集成Redis哨兵模式

Springboot2.x集成Redis哨兵模式 说明 Redis哨兵模式是Redis高可用方案的一种实现方式,通过哨兵来自动实现故障转移,从而保证高可用. 准备条件 pom.xml中引入相关jar <!-- 集成Redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</arti

【实战】Amoeba 代理 MySQL 主从复制 + 读写分离 【提供源码包】

目录简介: 1· Amoeba 的介绍2· MySQL 主从复制原理3· MySQL 读写分离原理4· 实战案例5· 总结归纳 Amoeba 的介绍 1)Amoeba 是什么: 1·Amoeba 的中文名是:变形虫.它是一个以MySQL为底层数据存储,并对应用提供MySQL协议接口的proxy.它集中地响应应用的请求,依据用户事先设置的规则,将SQL请求发送到特定的数据库上执行.基于此可以实现负载均衡.读写分离.高可用性等需求. 2·Amoeba相当于一个SQL请求的路由器,目的是为负载均衡.读

Mysql的主从复制读写分离--简单篇

Mysql基础拓扑图: Mysql环境准备: 一台mysql主服务器(安装mysql) 两台mysql从服务器(安装mysql) 一台mysql代理(安装amoeba和java) 一台mysql客户端(mysql客户端) 部署前先关闭所有的iptables,selinux Mysql的主从复制读写分离所需安装包: cmake-2.8.6.tar.gz mysql-5.5.22.tar.gz amoeba-mysql-binary-2.2.0.tar.gz jdk-7u65-linux-x64.t