ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Redis主从备份&哨兵设置

2019-07-11 13:52:18  阅读:260  来源: 互联网

标签:Redis 备份 redis bak sentinel yes soft 主从 172.31


Redis 主从备份,哨兵设置

环境 Centos 7,redis 4.0.6

三个centos 7实例
节点 IP 端口
redis-master 172.31.193.221 6379
redis-slave 172.31.193.222 6379
redis-LBS 172.31.193.224 6379
redis-sentinel-master 172.31.193.221 26379
redis-sentinel-slave 172.31.193.222 26379
redis-sentinel-LBS 172.31.193.224 26379
1.将redis解压到目录(/bak/soft/)

tar -zxvf 压缩包名 解压目录

2.创建日志和数据恢复目录
mkdir -p /bak/soft/logs/redis
mkdir -p /bak/soft/cdata/redis
mkdir -p /bak/soft/logs/redis-sentinel
mkdir -p /bak/soft/cdata/redis-sentinel
3.配置redis-master.conf
bind 127.0.0.1 172.31.193.221
daemonize yes
masterauth "ADMINadmin123"
requirepass "ADMINadmin123"
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"

#下面不用复制,作为参考,实际部署中根据需要配置
bind 127.0.0.1 172.31.193.221
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/bak/soft/cdata/redis"
masterauth "rdhkdcX5xCoHNg86MV0Y"
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
requirepass "rdhkdcX5xCoHNg86MV0Y"
appendonly no
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
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events "xE"
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
# Generated by CONFIG REWRITE
4.配置redis-slave.conf
bind 127.0.0.1 172.31.193.222
daemonize yes
masterauth "ADMINadmin123"
requirepass "ADMINadmin123"
dbfilename "dump.rdb"
dir "/bak/soft/cdata/redis"
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"
slaveof 172.31.193.221 6379


#下面不用复制,作为参考,实际部署中根据需要配置
bind 127.0.0.1 172.31.193.221
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/bak/soft/cdata/redis"
masterauth "rdhkdcX5xCoHNg86MV0Y"
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
requirepass "rdhkdcX5xCoHNg86MV0Y"
appendonly no
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
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events "xE"
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
# Generated by CONFIG REWRITE
slaveof 172.31.193.221 6379
5.配置redis-LBS.conf
bind 127.0.0.1 172.31.193.224
daemonize yes
masterauth "ADMINadmin123"
requirepass "ADMINadmin123"
dbfilename "dump.rdb"
dir "/bak/soft/cdata/redis"
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"
slaveof 172.31.193.221 6379

#下面不用复制,作为参考,实际部署中根据需要配置
bind 127.0.0.1 172.31.193.224
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile "/bak/soft/logs/redis/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/bak/soft/cdata/redis"
masterauth "rdhkdcX5xCoHNg86MV0Y"
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
requirepass "rdhkdcX5xCoHNg86MV0Y"
appendonly no
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
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events "xE"
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
# Generated by CONFIG REWRITE

slaveof 172.31.193.221 6379
6.配置sentinel.conf文件master&slave&LBS配置可以一样
protected-mode no
port 26379
daemonize yes
sentinel monitor mymaster 172.31.193.221 6379 2
logfile "/bak/soft/logs/redis/sentinel.log"
dir "/bak/soft/cdata/redis-sentinel"
sentinel auth-pass mymaster ADMINadmin123


#下面不用复制,myid为自动生成,slave节点也是自动添加
protected-mode no
port 26379
daemonize yes
sentinel myid f7564fc40667bb5e336c6566acc28654d0c40d39
sentinel monitor mymaster 172.31.193.221 6379 2
logfile "/bak/soft/logs/redis/sentinel.log"
dir "/bak/soft/cdata/redis-sentinel"
sentinel auth-pass mymaster ADMINadmin123
sentinel config-epoch mymaster 4
sentinel leader-epoch mymaster 4
sentinel known-slave mymaster 172.31.193.222 6379
sentinel known-slave mymaster 172.31.193.224 6379
sentinel known-sentinel mymaster 172.31.193.222 26379 96d7940391c5f9f386dedc1eb7a5b221e458428a
sentinel known-sentinel mymaster 172.31.193.224 26379 d5202361f59b4695ebe8a7cefd26c61466637554
sentinel current-epoch 4
7.配置redis.properties连接信息master&slave&LBS可以一样
redis.address=172.31.193.221:26379;172.31.193.222:26379;172.31.193.224:26379
redis.pool.testOnBorrow=true
redis.pool.testOnReturn=false
redis.pool.testWhileIdle=false
redis.pool.maxIdle=300
redis.pool.minIdle=15
redis.pool.maxActive=1000
redis.pool.maxWait=10000
redis.pool.timeout=10000
redis.pool.numTestsPerEvictionRun=0
redis.pool.timeBetweenEvictionRunsMillis=0
redis.pool.minEvictableIdleTimeMillis=0
redis.password=ADMINadmin123
redis.type=sentinel
redis.master.name=mymaster
8.修改防火墙规则,开放端口
#查看防火墙状态
service iptables status

#测试端口是否开放
telnet ip 端口

#修改防火墙规则
vim /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 6379 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 26379 -j ACCEPT

service iptables restart

#若已经启动redis,kill进程重启服务
ps aux |grep redis
kill -9 进程号
9.启动redis顺序,master—>slave&LBS—>三个哨兵
/bak/soft/redis-4.0.6/redis-server /etc/redis.conf
/bak/soft/redis-4.0.6/redis-sentinel /etc/sentinel.conf

#查看日志
tail 100 /bak/soft/logs/redis/redis.log

#查看日志
tail 100 /bak/soft/logs/redis/redis.log

image

10.测试停止master节点,slave或LBS节点将被选举为master节点

image

再重启master自动变成slave

image

标签:Redis,备份,redis,bak,sentinel,yes,soft,主从,172.31
来源: https://www.cnblogs.com/binjz/p/11169492.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有