Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ About redis in Replication     - How to remove the files inside the privacy of data on Linux (Linux)

- Linux (Debian) install software, missing dynamic link libraries .so (Linux)

- Spring Data JPA call a stored procedure examples (Programming)

- CentOS yum install LAMP (Server)

- Log4Net (Linux)

- MySQL replication master and slave structure built (Database)

- You may not know the Linux command-line network monitoring tool (Linux)

- Command-line based tools for better alternatives (Linux)

- Compiling source code Nginx module installation subs_filter (Server)

- Several start-up mode of Tomcat (Server)

- Using shell users or virtual users to login to pureftpd (Linux)

- Ubuntu program using the Sound Recorder (Linux)

- Oracle 11g new features of the collection of multi-column statistics (Database)

- How to protect the Apache website under Linux system (Linux)

- To compile install and test Swift under Linux (Linux)

- Customize own small private Linux system (Linux)

- Oracle Database asynchronous IO cause slow query response (Database)

- Apache Spark1.1.0 deployment and development environment to build (Server)

- Linux operating system must know the security command (Linux)

- Linux Samba server-side structures and the use of the client (Server)

 
         
  About redis in Replication
     
  Add Date : 2018-11-21      
         
         
         
  I. Introduction

Redis replication mechanism allows the slave master from there to complete backup copy transmitted over the network. It has the following characteristics:

Asynchronous replication
You can configure a master multi-slave
You can configure the server can be cascaded from the server, both M-> S-> S
M is (during replication, M is still able to handle the client's request) non-blocking when replication
Also non-blocking S during replication (also accept requests from clients, but it is used before the old data) can be configured to determine the response time of the S whether during replication with the old data request from the client, if the configuration is no, then the slave will return an error message to the client. But when the new data after receiving complete, you must replace the old data with new data, old data is deleted within this time window replacement data, slave will reject the request and the client's connection
Can be avoided by replication master will persist when the entire data set persistence to disk each time. Simply master configured not to perform save operations, and then connect to a slave, the slave were configured to save the operation from time to time. But note that in this use case, you must ensure that master does not start automatically
Two, Master Replication feature is off persistent security

When there is a need to use replication mechanism, generally it will strongly recommend the persistent master switch open. In order to avoid even the delayed impact of the persistence brought about, not the persistent switch is open, it should also be configured as the master does not start automatically

To better understand when a persistent master not allowed to start automatically if the risk posed. This failure can take a look at the following scenario:

Suppose we have a redis node A, is set to master, and turn off the persistence function, the other two nodes B and C is its slave, and the data from the A replication.

If node A crash led to all the data is lost, it will have to restart the system to restart the process. However, due to the persistence feature is turned off, so even if it is restarted, its data set is empty. The B and C will still copy the data from A through replication mechanism, B and C, where A is copied from an empty to a data set, and with this data set will empty itself of non-empty dataset replaced. So it is equivalent to the loss of all the data
HA even use some tools, such as sentinel to monitor the master-slaves cluster, the situation described above also occur because of the rapid recovery after the master may crash. Too fast and lead to a sentinel undetectable failure occurs
Data security is very important, persistent switch is closed and there is time replication occurs, it should be banned from the start of the instance
Three, M / S replication works

When the master and slave start, regardless of whether this is the first slave connection Master, it will send a SYNC command to the master copy of data request
After receiving master SYNC command, data persistence, persistence period, will continue to receive master client's request in the background, it will modify the data sets which may request cached in memory. When persistence were completed, master data set will be sent to this slave, slave received data will persist, and then loaded into memory. Then, master before it is sent to the slave and then cached in memory commands
When the connection between master and slave is disconnected for some reason, slave automatically reconnect Master, if a plurality of slave master received concurrent connection requests, it will only be a persistent, then then this is a lasting of the data sent to the slave multiple concurrent connections
When the master and slave to disconnect and reconnect, usually for the entire data replication. But redis2.8 version, supports fractional replication
Data replication section

From version 2.8 start, slave and master can be only part of the data network connection copied to disconnect and reconnect.

master creates a copy of the stream waiting queue in its memory, and all its slave master maintains the replicated data under landmarks and master of the process id, and therefore, when the network connection is disconnected, slave master will continue to request not complete copy, from the recorded data index began. If the process id changes, or index data is not available, it will be a copy of all data. Supports partial data replication command PSYNC

Replication without the participation of the hard disk

Under normal circumstances, one copy needs to be written to the hard disk of the data in memory, then the data is read from disk into memory, then sent to the slave. For the slower hard drive, this operation will bring master performance loss. Redis2.8 version, experimentally added no hard copy function. This function can send data directly from memory to the slave, without going through a hard disk storage. However, this feature is currently in the experimental stage, has not yet officially released

Fourth, the Configuration M / S

 slaveof

you need to configure the slave instance, point to the master (ip, port)

masterauth

If the master instance to enable password protection, the setting item denotes compulsory master boot password; if the master password is not enabled, the configuration items need to comment

slave-serve-stale-data

Specifies the slave and master operation interrupted the connection. The default is yes, meaning that slave will continue to respond to the request from the client, but these data may have expired (because the connection interrupt causes can not be synchronized from master)

When configured as a no, then the slave in addition to normal response "INFO" and "SLAVEOF" command, the rest of the request command from the client will get the "SYNC with master in progress" response,

Until the slave and the master of the slave or the connection is successfully re-promoted to master.

 

slave-read-only

Specifies slave is read-only, the default is yes. If configured to no, which means that slave is write, but write content in the master-slave synchronization is completed will be deleted

repl-ping-slave-period

After the deployment of Redis Replication mode, slave will be a predetermined period (default 10s) send PING packet to master, the configuration can change this default period

repl-timeout

There are two cases of overtime by the configuration specified: 1) Bulk transfer I / O timeout; 2) master data or ping response timeout

Special attention is needed: If modify the default value, the value entered by the user must be greater than the configured value repl-ping-slave-period, otherwise when the main link delay from the high frequent timeout

repl-disable-tcp-nodelay

Specifies that synchronization data to the slave when the NO_DELAY whether to disable socket option.

When configured as a yes, then disable NO_DELAY, the TCP protocol stack will be merged unified packet sent, thus reducing the number of packets from the master nodes and save bandwidth, but will increase the data synchronization time to slave

When configured as a no, indicate enabled NO_DELAY, the TCP protocol stack will not delay the timing of packet transmission, and data synchronization delays will be reduced, but require more bandwidth

Under normal circumstances, should be configured to reduce the no synchronization delay, but in the main from the inter-node network load is already high in the case, you can configure yes

NOTE: socket of NO_DELAY options related to TCP protocol stack congestion control algorithm -Nagle's Algorithm

slave-priority

Specifies the slave priority. In the presence of more than one slave deployment environment, when the master is down, Redis Sentinel priority will be upgraded to the smallest value of slave master

Note that, if the configuration item is 0, the corresponding slave will never be automatically promoted to master Redis Sentinel


replication-related configuration is relatively simple, just put the following line added to the slave configuration file

slaveof 192.168.1.1 6379

You can also send commands to the slave SLAVEOF by the client. Without the hard copy function can be repl-diskless-sync to configure, another configuration item repl-diskless-sync-delay to set when the first request, wait up a plurality of slave interval between requests

1, and start two Redis server, you can start to consider two Redis server on the same machine, each monitor a different port, such as 6379 and 6380

2, the configuration file for the 6379.conf 6380.conf

3. Start and configure

./src/redis-server 6380.conf

./src/redis-server 6379.conf

4, the test

[Root @ localhost redis] # ./src/redis-cli -p 6379

127.0.0.1:6379> flushdb

OK

127.0.0.1:6379> set aa 1

OK

127.0.0.1:6379> set bb 2

OK

127.0.0.1:6379> set cc 3

OK

127.0.0.1:6379> exit

[Root @ localhost redis] # ./src/redis-cli -p 6380

127.0.0.1:6380> keys *

1) "bb"

2) "aa"

3) "cc"

127.0.0.1:6380> get aa

"1"

127.0.0.1:6380> get bb

"2"

Five, only read slave

Redis2.6 version from the start, slave supports read-only mode, and is the default. Can be configured via the configuration item slave-read-only, and supports client uses CONFIG SET command to dynamically modify the configuration

Read-only slave rejects all write requests, read-only slave not to prevent untrusted clients, after all, some administrative commands such as CONFIG and DEBUG in read-only mode or can use. If you really want to ensure the security, you can rename some of the commands in the configuration file. Maybe you will feel very strange, why can a slave will restore the read-only mode can write it, although to write, but as long as a slave to synchronize master data, you will lose those written in the slave data. However, there are some legitimate scenarios need to store transient data will use this feature. However, after the repeal might consider out of this feature. Setting a slave to authenticate to a master

If the master configuration item by requirepass set a password, each slave synchronization is required to verify the password, you can add the following configuration entry in the slave configuration file:

masterauth

You can also send the following commands at run time by the client:

config set masterauth

Six, at least N slave master is allowed to write data

Redis2.8 version from the start, can be configured as a master only when there are at least N current master slave connected when it is receiving write requests for data; since the redis replication is asynchronous, so it does not receive a written guarantee slave request, so there is always a time window of data loss exists

This mechanism works as follows:

slave sending heartbeats per ping to master, asked how much the current replication data
Under master will record it received last time a slave is when the ping heartbeat
Users can configure a time to specify ping heartbeat transmission should not exceed a timeout
If there is at least N master slave, and ping heartbeat timeout is not more than M seconds, then it receives the write request. You might think that this situation is like a weaker version of the CAP theory C (consistency), because the write request does not guarantee data consistency, but to do so, at least data loss is limited to the limited time that M seconds

If N and M of the conditions can not be achieved, then the master will return an error message. Write request will not be processed

There are two configuration items to configure the above-mentioned N and M:

min-slaves-to-write

min-slaves-max-lag
     
         
         
         
  More:      
 
- Nginx server load balancing dual-system availability (Server)
- Zookeeper cluster deployment (Server)
- Repair Chrome for Linux is (Linux)
- Oracle archive log size than the size of the online journal of the much smaller (Database)
- Install Kali Linux via PXE network (Linux)
- Configure the Linux kernel and use iptables to do port mapping (Linux)
- MySQL Tutorial: About checkpoint mechanism (Database)
- installation of Piwik under Ubuntu (Programming)
- Android Send HTTP POST requests (Programming)
- Service manager OpenBSD on rccl (Server)
- JavaScript is implemented without new keywords constructor (Programming)
- PHP security Programming Advice (Programming)
- Linux system boot process ARM platforms (Linux)
- MyCAT read and write separation of MySQL (Database)
- Ubuntu 14.10 installation GNOME 3.14 (Linux)
- Static member variable modified (Programming)
- MySQL + Heartbeat + DRBD deployment architecture (Server)
- Cobbler Add custom YUM source (Linux)
- Build RubyMine + Ruby On Rails + MySQL development environment under Windows (Server)
- Tmux create the perfect terminal management tool under CentOS (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.