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 Learning 6Murray-Master-Slave Environment configuration

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

Share

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

1. Compile and install

Process omission

2. Master-slave configuration

Vi / data/usr/redis-4.0.11/conf/redis.conf

Master:

Bind 127.0.0.1 192.168.121.121

Daemonize yes

Logfile "/ data/usr/redis-4.0.11/logs/redis.log"

Pidfile / data/usr/redis-4.0.11/run/redis_6379.pid

Dir / data/usr/redis-4.0.11/data

Requirepass Redis2019!

Slave:

Bind 127.0.0.1 192.168.121.122

Daemonize yes

Logfile "/ data/usr/redis-4.0.11/logs/redis.log"

Pidfile / data/usr/redis-4.0.11/run/redis_6379.pid

Dir / data/usr/redis-4.0.11/data

Requirepass Redis2019!

Masterauth Redis2019!

Slaveof 192.168.121.121 6379

3. Check the master-slave status

Master:

Redis-cli-a Redis2019!

Warning: Using a password with'- a 'option on the command line interface may not be safe.

127.0.0.1 purl 6379 > INFO reolication

127.0.0.1 purl 6379 > INFo replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.121.122,port=6379,state=online,offset=24486,lag=1

Master_replid:7ad1fd1b943f347c73970ccf1e50a51f9e17ad2d

Master_replid2:0000000000000000000000000000000000000000

Master_repl_offset:24486

Second_repl_offset:-1

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:1

Repl_backlog_histlen:24486

Slave:

Redis-cli-h 192.168.121.122-p 6379-a Redis2019!

Warning: Using a password with'- a 'option on the command line interface may not be safe.

192.168.121.122 6379 > INFO replication

# Replication

Role:slave

Master_host:192.168.121.121

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:7

Master_sync_in_progress:0

Slave_repl_offset:24570

Slave_priority:100

Slave_read_only:1

Connected_slaves:0

Master_replid:7ad1fd1b943f347c73970ccf1e50a51f9e17ad2d

Master_replid2:0000000000000000000000000000000000000000

Master_repl_offset:24570

Second_repl_offset:-1

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:1

Repl_backlog_histlen:24570

4. Master-slave mode and persistence

The master-slave mode of redis is asynchronous mode, the slave node copies data asynchronously from the master node, the master node provides read and write, and the slave node provides only read services. This is the default configuration. You can modify the slave-read-only parameters of the configuration file and change the yes to no, that is, to turn on the read-only limit of the slave node, and the master node can have multiple slave nodes.

Snapshot persistence, or RDB file persistence, is the default persistence method. Periodically save the data to disk according to a certain policy, and the resulting data file is dump.rdb, which is saved in the directory where the service is started by default. With the help of the copy on write mechanism of the fork command, redis fork a child process of the current process when generating a snapshot, and then the child process circulates all the commands and writes the data, which is called the RDB file. Client can use the save or dbsave command to tell redis to do a snapshot persistence. Save operations hold snapshots in the main thread, and since redis uses a main thread to process all client requests, this method blocks all client requests, so save operations are not recommended. In addition, each snapshot persistence is a complete write of memory data to the disk, not incremental. If the amount of data to be synchronized is large, and there are many write operations, it will inevitably result in a large number of io operations on the disk, which may seriously affect the disk performance.

Master-slave synchronization based on snapshot files:

Slave sends a synchronization request to master for the first time, and master first dump the rdb file.

Default settings for persistence:

Save 9001 # 900s after at least 1 key has changed save

Save 30010 # 300s after at least 10 key changes save

Save 60 10000 # 60 seconds after at least 10000 key changes save

Stop-writes-on-bgsave-error yes # error handling, by default, if redis fails to generate a snapshot in the background, it will stop receiving data to let the user know that the data has not been persisted successfully.

For rdbcompression yes # data compression, LZF is used by default to compress the data. If you want to save CPU performance, you can disable the compression feature, but the dataset will be larger than that without compression.

Rdbchecksum yes # data check, a CRC64 check is placed at the end of the file to ensure the integrity of the file, but some performance is lost when saving and loading the file (about 10%)

Dbfilename dump.rdb # persistence file

The dir. / # file saves the directory and saves the file wherever the startup command is executed

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