Redis安装,主从,主备切换

二次信任 提交于 2020-03-05 07:58:19
网络环境:
     
主:10.187.120.5
从:10.187.69.58
从:10.187.69.59

一.安装
mv redis-2.8.19.tar.gz /export/servers/
cd /export/servers/
tar zxf redis-2.8.19.tar.gz
cd redis-2.8.19
make && make install
二,主从环境搭建
 
 主:10.187.120.5
conf/redis_6379.conf
(src/redis-server conf/redis_6379.conf)
重要参数备注:
loglevel notice
# 指定日志记录级别
# Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
# debug 记录很多信息,用于开发和测试
# varbose 有用的信息,不像debug会记录那么多
# notice 普通的verbose,常用于生产环境
# warning 只有非常重要或者严重的信息会记录到日志
timeout 300
# 设置客户端连接时的超时时间,单位为秒。当客户端在这段时间内没有发出任何指令,那么关闭该连接;0是关闭此设置
databases 16
#可用数据库
rdbcompression yes
# 存储至本地数据库时(持久化到rdb文件)是否压缩数据,默认为yes
slave-serve-stale-data yes
# 当 slaves 和 master 失去联系或者 复制数据工作仍然在进行,yes的时候 slave 会反馈 客户端的请求,no的时候不会
slave-read-only yes
#yes意味着客户端没法给slave 节点写入数据
repl-disable-tcp-nodelay no
#在slave和master同步后(发送psync/sync),后续的同步是否设置成TCP_NODELAY。no代表不设置为TCP_NODELAY, redis master会立即发送同步数据,没有延迟;yes会有延迟
repl-backlog-size 128mb
#设置复制的backlog值,缓冲区的值;当从服务器断开连接之后,主服务器将更新的数据放置在这个缓冲区中,因为当从服务重新连接上来时候不是所有的数据都需要同步,因此从这个缓冲区中取数据就可以同步到和主服务器一样的状态
daemonize yes
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-command keys jkeys

 

 

从:10.187.69.58
conf/redis_6379.conf
(src/redis-server conf/redis_6379.conf)
daemonize yes
slaveof  10.187.120.5 6379
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-command keys jkeys
 
 
从:10.187.69.59
conf/redis_6379.conf
(src/redis-server conf/redis_6379.conf)
daemonize yes
slaveof  10.187.120.5 6379
pidfile /export/Data/redis_pid/redis_6379.pid
port 6379
# tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile /export/Logs/redis/redis_6379.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename 6379.rdb
dir /export/Data/redis_data/6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
repl-backlog-size 128mb
maxmemory 2g
appendonly no
appendfilename 6379.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 1024
# notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
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 512mb 256mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
rename-command keys jkeys

三.主备切换

主:10.187.120.5
conf/sentinel_26379.conf
(src/redis-sentinel conf/sentinel_26379.conf)
port 26379
daemonize yes
sentinel monitor mymaster 10.187.120.5 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 900000
#sentinel can-failover mymaster yes
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
dir "/export/servers/redis-2.8.19"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.187.69.59 6379
sentinel known-slave mymaster 10.187.69.58 6379
#sentinel known-sentinel mymaster 10.187.69.59 26379 84ac24684dc485bc0c4bcf84a03d7cdb12d32ac9
#sentinel known-sentinel mymaster 10.187.69.58 26379 68da3e5c7d7da1ac1dfb542741bd89181fdda580
sentinel current-epoch 0

 

从:10.187.69.58
sentinel_26379.conf
(src/redis-sentinel conf/sentinel_26379.conf)
daemonize yes
port 26379
sentinel monitor mymaster 10.187.120.5 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 900000
#sentinel can-failover mymaster yes
sentinel config-epoch mymaster 0
#Generated by CONFIG REWRITE
dir "/export/servers/redis-2.8.19"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.187.69.58 6379
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 10.187.69.59 6379
sentinel current-epoch 0

 

从:10.187.69.59
sentinel_26379.conf
(src/redis-sentinel conf/sentinel_26379.conf)
daemonize yes
port 26379
sentinel monitor mymaster 10.187.120.5 6379 2
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 900000
#sentinel can-failover mymaster yes
sentinel config-epoch mymaster 0
#Generated by CONFIG REWRITE
dir "/export/servers/redis-2.8.19"
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 10.187.69.58 6379
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 10.187.69.58 6379
sentinel known-slave mymaster 10.187.69.59 6379
sentinel current-epoch 0

 


 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!