Redis 复制搭建

说明:redis安装前两篇文章有介绍,就不再赘述


Redis 复制搭建


1、环境配置

第一:准备3台服务器,一台master ,两台 slave


Redis 复制搭建

第二:每台服务器安装redis版本保持一致

2、Redis主从复制配置

192.168.199.11配置(主)

port 6379

loglevel notice

pidfile /var/run/redis_6379.pid

save 9 1

save 300 10

save 60 10000

daemonize yes

timeout 300

databases 16

logfile "/usr/local/redis/log/redis.log"

rdbcompression yes

dbfilename dump.rdb

dir /usr/local/redis/data

maxclients 50000

maxmemory 4GB

stop-writes-on-bgsave-error yes

appendonly no

#appendfilename "appendonly.aof"

#appendfsync everysec

#appendfsync everysec

activerehashing yes

#vw-enabled yes

#repliaction

masterauth 123456

requirepass 123456


第二:进入 199.12和199.13的服务器的redis配置文件目录下

192.168.199.12和192.168.199.13配置(从)

port 6379

loglevel notice

pidfile /var/run/redis_6379.pid

save 9 1

save 300 10

save 60 10000

daemonize yes

timeout 300

databases 16

logfile "/usr/local/redis/log/redis.log"

rdbcompression yes

dbfilename dump.rdb

dir /usr/local/redis/data

maxclients 50000

maxmemory 4GB

stop-writes-on-bgsave-error yes

appendonly no

#appendfilename "appendonly.aof"

#appendfsync everysec

#appendfsync everysec

activerehashing yes

#vw-enabled yes

#repliaction

masterauth 123456

requirepass 123456

slaveof 192.168.199.11 6379

第三:启动11,12,13的redis

/usr/local/redis-5.0.7/src/redis-server /etc/redis/redis.conf

查看日志,如出现以下则代表成功

63467:S 23 Dec 2019 17:19:15.961 * Ready to accept connections

63467:S 23 Dec 2019 17:19:15.961 * Connecting to MASTER 192.168.199.11:6379

63467:S 23 Dec 2019 17:19:15.961 * MASTER REPLICA sync started

63467:S 23 Dec 2019 17:19:15.962 * Non blocking connect for SYNC fired the event.

63467:S 23 Dec 2019 17:19:15.962 * Master replied to PING, replication can continue...

63467:S 23 Dec 2019 17:19:15.963 * Partial resynchronization not possible (no cached master)

63467:S 23 Dec 2019 17:19:15.965 * Full resync from master: b66a76cfc097379db04a5eb33ef879236487eb47:0

63467:S 23 Dec 2019 17:19:15.997 * MASTER REPLICA sync: receiving 175 bytes from master

63467:S 23 Dec 2019 17:19:15.998 * MASTER REPLICA sync: Flushing old data

63467:S 23 Dec 2019 17:19:15.998 * MASTER REPLICA sync: Loading DB in memory

63467:S 23 Dec 2019 17:19:15.998 * MASTER REPLICA sync: Finished with success

63467:S 23 Dec 2019 17:20:40.944 * 1 changes in 9 seconds. Saving...

63467:S 23 Dec 2019 17:20:40.944 * Background saving started by pid 63499

63499:C 23 Dec 2019 17:20:40.948 * DB saved on disk

63499:C 23 Dec 2019 17:20:40.949 * RDB: 0 MB of memory used by copy-on-write

63467:S 23 Dec 2019 17:20:41.045 * Background saving terminated with success

查看同步数据

192.168.199.11


Redis 复制搭建

192.168.199.12


Redis 复制搭建

192.168.199.13


Redis 复制搭建


分享到:


相關文章: