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

Redis master-slave building

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Environment:

Redis_M 172.16.0.137

Redis_S 172.16.0.138

System: centos6.7

1. Build a stand-alone redis in redis_M 172.16.0.137 and redis_S 172.16.0.138

2. Modify the configuration parameter redis.conf

Mainly modify 4 parameters:

Port

Logfile

Slaveof (only modifying from the library)

Pidfile

Daemonize (configured to run as daemon)

-

Modify redis_M 172.16.0.137 redis.conf:

Port 6379

Pidfile / var/run/redis.pid

# slaveof

Logfile "/ var/log/redis/redis.log"

Daemonize yes

Modify redis_S 172.16.0.138 redis.conf:

Port 6380

Pidfile / var/run/redis.pid

Slaveof 172.16.0.137 6379

Logfile "/ var/log/redis/redis.log"

Daemonize yes

-

Set master-slave synchronization

1. Modify the bind field in redis.conf on the redis master server to set the

Bind 127.0.0.1

Modify to

Bind 0.0.0.0

Or comment out the bind field directly.

# bind 127.0.0.1

2. Set the master-slave synchronization password and modify it in the configuration file redis.conf

The master and slave server sets the password:

Requirepass some34QA

Add the password to the master-slave server configuration:

Masterauth some34QA

Enable read-only mode from the server (on by default)

Slave-read-only yes

3. Set master-slave persistence: RDB snapshot persistence modify redis.conf

Mkdir / var/data/redis-p

Save 900 1

Save 300 10

Save 60 10000

Stop-writes-on-bgsave-error yes

Rdbcompression yes (compression)

Rdbchecksum yes

Dbfilename dump.rdb

Dir / var/data/redis

Http://www.voidcn.com/blog/aitangyong/article/p-6114064.html

[1. Redis calls the system function fork () to create a child process. ]

[2. The child process writes the dataset to a temporary RDB file. ]

[3. When the child process finishes writing to the temporary RDB file, redis replaces the original RDB file with the new temporary RDB file and deletes the old RDB file. ]

4. Set master-slave persistence: AOF persistence to modify redis.conf

Appendonly yes

Appendfilename "appendonly.aof"

Appendfsync everysec

No-appendfsync-on-rewrite no

Auto-aof-rewrite-percentage 100

Auto-aof-rewrite-min-size 64mb

Http://www.jianshu.com/p/bedec93e5a7b

Comparison of AOF and RDB:

AOF is more secure and can synchronize data to files in time, but requires more disks. IO,AOF files are larger, and the contents of the files are relatively slow to recover and more complete.

RDB persistence, poor security, it is the normal period of data backup and master-slave data synchronization of the best means, smaller file size, faster recovery.

Maximum memory configuration and memory recovery policy: (specific business needs to be adjusted for installation, this time for adjustment)

Maxmemory 12G (75% of server memory is recommended) when memory reaches the limit, Redis's specific recycling policy is configured through the maxmemory-policy configuration item.

Maxmemory 0 (there is no limit. When the storage data reaches the limit, Redis will choose a different strategy according to the situation, or return errors (which will result in more memory waste), or clear some old data to reclaim memory to add new data)

Maxmemory-policy configuration items:

Noenviction: do not clear the data, just return an error, which results in a waste of more memory, with the exception of most write commands (DEL commands and a few other commands)

Allkeys-lru: select the least recently used data from all data sets (server. DB [I]. Dict) to be eliminated for use by new data.

Volatile-lru: select the least recently used data from the dataset with an expiration time set (server. DB [I]. Obsolete) to be used by the new data.

Allkeys-random: any selection of data from all datasets (server. DB [I]. Dict) is eliminated for use with new data.

Volatile-random: select data to be eliminated from any dataset with an expiration time set (server.db [I] .expires) for use by new data

Volatile-ttl: select expired data from datasets (server. DB [I]. Expires) that are about to expire for use with new data

- -

Redis two-node master-slave switch:

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

Servers

Wechat

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

12
Report