Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Replication of Redis

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment: master:192.168.11.31

Slave: 192.168.11.20 purl 6379 and 6380

Simulate two slave to copy one master at the same time.

Mater configuration:

Daemonize yes

Pidfile / var/run/redis.pid

Port 6379

Tcp-backlog 511

Timeout 0

Tcp-keepalive 0

Loglevel notice

Logfile ""

Databases 16

Repl-diskless-sync no

Repl-diskless-sync-delay 5

Repl-disable-tcp-nodelay no

Lua-time-limit 5000

Slowlog-log-slower-than 10000

Slowlog-max-len 128

Latency-monitor-threshold 0

Requirepass Passw0rd

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 256mb 64mb 60

Client-output-buffer-limit pubsub 32mb 8mb 60

Hz 10

Slave configuration, enable rdb and aof on slave

Configuration of slave 6379:

Daemonize yes

Pidfile / var/run/redis_6379.pid

Port 6379

Dbfilename redis.db

Dir / home/redis/6379

Save 900 1

Save 300 10

Save 60 3000

Rdbcompression yes

Rdbchecksum yes

Stop-writes-on-bgsave-error yes

Appendonly yes

Appendfilename appendonly.aof

# slave settings

Slave-read-only yes

Slaveof 192.168.11.31 6379

Slave 6380 configuration:

Daemonize yes

Pidfile / var/run/redis_6380.pid

Port 6380

Dbfilename redis6380.db

Dir / home/redis/6380

Save 900 1

Save 300 10

Save 60 3000

Rdbcompression yes

Rdbchecksum yes

Stop-writes-on-bgsave-error yes

Appendonly yes

Appendfilename appendonly6380.aof

# slave settings

Slave-read-only yes

Slaveof 192.168.11.31 6379

Start master:

[root@localhost redis] # redis-server redis.conf

Start slave:

[root@hdtest20 redis] # redis-server / etc/redis/6380.conf

[root@hdtest20 redis] # redis-server / etc/redis/6339.conf

After logging in to mater, enter the following command:

127.0.0.1 purl 6379 > auth Passw0rd

OK

127.0.0.1 purl 6379 > INFO replication

# Replication

Role:master

Connected_slaves:2

Slave0:ip=192.168.11.20,port=6380,state=online,offset=71,lag=1

Slave1:ip=192.168.11.20,port=6379,state=online,offset=71,lag=1

Master_repl_offset:71

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:70

Basically, you can see that the copy has been completed. Type two key to test it:

127.0.0.1 purl 6379 > set testsite test.com

OK

Log in to slave port 6380:

127.0.0.1 6380 > keys *

1) "testsite"

127.0.0.1 6380 > get testsite

"test.com"

Note: since rdb and aof are not enabled in master, master cannot be enabled immediately after master failure repair, otherwise both slave will lose all data. Therefore, you should also enable aof and rdb of redis master, and set repl-diskless-sync to yes at the same time.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report