In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
First, the principle of redis master-slave replication
For the same reason as MySQL master-slave replication, although Redis reads and writes very fast, it can also cause read pressure. In order to share the read pressure, Redis supports master-slave replication. The master-slave structure of Redis can adopt an one-master-multi-slave or cascade structure. Redis master-slave replication can be divided into full synchronization and incremental synchronization according to whether it is full or not. The following figure shows a cascade structure:
1. Full synchronization
Full Redis replication usually occurs during the Slave initialization phase, when Slave needs to make a copy of all the data on the Master. The specific steps are as follows:
1) connect to the master server from the server and send the SYNC command
2) after receiving the SYNC naming, the master server starts executing the BGSAVE command to generate the RDB file and uses a buffer to record all write commands executed thereafter
3) after the execution of the master server BGSAVE, send snapshot files to all slave servers, and continue to record the write commands executed during the sending period
4) after receiving the snapshot file from the server, discard all the old data and load the received snapshot
5) after the master server snapshot is sent, the write command in the buffer is sent to the slave server.
6) complete the loading of the snapshot from the server, receive command requests, and execute write commands from the autonomous server buffer
After completing the above steps, all the operations initialized from the server data are completed, and read requests from the user can be received from the server at this time.
2. Incremental synchronization
Redis incremental replication refers to the process of write synchronization to slave server that occurs on the master server when Slave initialization begins to work normally.
The main process of incremental replication is that every time the master server executes a write command, it sends the same write command to the slave server, and receives and executes the received write command from the server.
Note: increment is not supported by redis2.8 before, but increment will be supported after 2.8!
3. Redis master-slave synchronization strategy
When the master and slave are just connected, full synchronization is carried out; after the full synchronization is over, incremental synchronization is carried out. Of course, slave can initiate full synchronization at any time if necessary. The redis policy is that, in any case, incremental synchronization will be attempted first, and if unsuccessful, full synchronization from the slave is required.
4. Points for attention
If multiple Slave are disconnected, it is necessary to restart, because as long as the Slave is started, a sync request will be sent to synchronize with the host, which may lead to a sharp increase in Master IO downtime when more than one Master IO occurs at the same time.
II. Redis single-host multi-instance deployment
If you have previously installed a single instance of redis,redis, please refer to: CentOS 7.4.detailed steps for installing redis 4.0[ http://blog.itpub.net/31015730/viewspace-2155307/]
1. Copy two redis configuration files
[root@VM_2_13_centos ~] # cp / etc/redis/redis.conf / etc/redis/redis6311.conf
[root@VM_2_13_centos ~] # cp / etc/redis/redis.conf / etc/redis/redis6322.conf
[root@VM_2_13_centos ~] #
[root@VM_2_13_centos ~] # ll / etc/redis/
Total 192
-rw-r--r-- 1 root root 58976 May 29 20:37 redis6311.conf
-rw-r--r-- 1 root root 58976 May 29 20:37 redis6322.conf
-rw-r--r-- 1 root root 58976 May 29 20:33 redis.conf
2. Modify the configuration files redis6311.conf and redis6322.conf
[root@VM_2_13_centos ~] # vim / etc/redis/redis6311.conf
# listener port number, default is 6379. If you set it to 0, redis will not listen to any client connections on the socket.
Port 6311
# redis does not run as a daemon by default. If you want it to run in the background, you can change it to yes.
Daemonize yes
# when redis runs as a daemon, it writes pid to the / var/run/redis.pid file by default
# but you can make its own file location here.
Pidfile / var/run/redis/redis_6311.pid
# specify the location of the log file, and set different log files for different instances to facilitate problem location
Logfile / var/log/redis/redis_6311.log
# set the file name of dump, and set different db files for different instances to facilitate problem location
Dbfilename dump_6311.rdb
# working directory # for example, the above dbfilename only specifies the file name, but it will be written to this directory. # this configuration item must be a directory, not a file name.
# the default value for this configuration item is ". /". It is best to change the relative path to the absolute path.
# if it is a relative path, where redis is started, the dump.rdb file will be generated in the startup directory, which is why the key value disappears after some people restart redis
Dir / var/lib/redis/6311
# configure password
Requirepass qcloud@2018
3. Start the redis with port 6311
[root@VM_2_13_centos ~] # redis-server / etc/redis/redis6311.conf
[root@VM_2_13_centos ~] #
[root@VM_2_13_centos ~] # ps-ef | grep redis
Root 6938 1 0 21:14? 00:00:00 redis-server 127.0.0.1:6379
Root 7001 1 0 21:15? 00:00:00 redis-server 127.0.0.1:6311
Root 7009 1905 0 21:15 pts/1 00:00:00 grep-color=auto redis
4. Client login
[root@VM_2_13_centos] # redis-cli-p 6311
127.0.0.1purl 6311 >
127.0.0.1 6311 > keys *
(error) NOAUTH Authentication required.
127.0.0.1purl 6311 >
127.0.0.1purl 6311 > auth qcloud@2018
OK
127.0.0.1 6311 > keys *
(empty list or set)
Configure the redis for port 6322 as above, and start
[root@VM_2_13_centos ~] # redis-server / etc/redis/redis6322.conf
[root@VM_2_13_centos ~] # ps-ef | grep redis
Root 6938 1 0 21:14? 00:00:00 redis-server 127.0.0.1:6379
Root 7001 1 0 21:15? 00:00:00 redis-server 127.0.0.1:6311
Root 7264 1 0 21:20? 00:00:00 redis-server 127.0.0.1:6322
Root 7279 1905 0 21:20 pts/1 00:00:00 grep-color=auto redis
Third, the construction of redis master-slave environment
1. Modify the configuration files of 6311 and 6322. The main redis is the redis of port 6379.
[root@VM_2_13_centos ~] # vim / etc/redis/redis6311.conf
Slaveof localhost 6379
# masterauth
Masterauth qcloud@2018
Note: if the master instance is configured with a password, then the slave instance must be configured with masterauth, otherwise the synchronization will not succeed
2. Check whether the configuration is successful
Main library:
127.0.0.1 purl 6379 > info Replication
# Replication
Role:master
Connected_slaves:2
Slave0:ip=127.0.0.1,port=6311,state=online,offset=179,lag=0
Slave1:ip=127.0.0.1,port=6322,state=online,offset=179,lag=0
Master_replid:d2450e24238b6612630368c6408fd4a9b098da16
Master_replid2:0000000000000000000000000000000000000000
Master_repl_offset:179
Second_repl_offset:-1
Repl_backlog_active:1
Repl_backlog_size:1048576
Repl_backlog_first_byte_offset:1
Repl_backlog_histlen:179
From the library:
127.0.0.1purl 6311 > info Replication
# Replication
Role:slave
Master_host:localhost
Master_port:6379
Master_link_status:up
Master_last_io_seconds_ago:7
Master_sync_in_progress:0
Slave_repl_offset:277
Slave_priority:100
Slave_read_only:1
Connected_slaves:0
Master_replid:d2450e24238b6612630368c6408fd4a9b098da16
Master_replid2:0000000000000000000000000000000000000000
Master_repl_offset:277
Second_repl_offset:-1
Repl_backlog_active:1
Repl_backlog_size:1048576
Repl_backlog_first_byte_offset:1
Repl_backlog_histlen:277
127.0.0.1 purl 6322 > info Replication
# Replication
Role:slave
Master_host:localhost
Master_port:6379
Master_link_status:up
Master_last_io_seconds_ago:1
Master_sync_in_progress:0
Slave_repl_offset:319
Slave_priority:100
Slave_read_only:1
Connected_slaves:0
Master_replid:d2450e24238b6612630368c6408fd4a9b098da16
Master_replid2:0000000000000000000000000000000000000000
Master_repl_offset:319
Second_repl_offset:-1
Repl_backlog_active:1
Repl_backlog_size:1048576
Repl_backlog_first_byte_offset:1
Repl_backlog_histlen:319
3. Master-slave synchronization test:
Main library:
127.0.0.1 6379 > keys *
1) "name"
127.0.0.1purl 6379 >
127.0.0.1 6379 > set age 22
OK
From the library:
[root@VM_2_13_centos] # redis-cli-p 6311
127.0.0.1purl 6311 > auth qcloud@2018
OK
127.0.0.1 6311 > keys *
1) "name"
127.0.0.1purl 6311 > get age
"22"
[root@VM_2_13_centos] # redis-cli-p 6322
127.0.0.1 purl 6322 > auth qcloud@2018
OK
127.0.0.1 6322 > keys *
1) "name"
127.0.0.1 purl 6322 > get age
"22"
So far, the master-slave replication environment of redis has been built!
Author: SEian.G (hard practice changes in 72, but it is difficult to laugh at 81)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.