Redis cluster configuration

If our redis is under a lot of pressure, if our concurrency is so high that we have a lot of pressure to read and write data. Then we may need to deploy redis separately and configure it as a "master-slave" state. 

Build the Redis cluster configuration on the server:

1. Switch root user

  su - centos
  enter password ******
  sudo su
  enter password ******

2. Install prerequisite packages

  yum install gcc-c++
  yum install -y ruby
  yum install -y rubygems

3. Download redis4.0.7

  wget http://download.redis.io/releases/redis-4.0.7.tar.gz

4. Move redis to /usr/local/

  mv redis-4.0.7.tar.gz /usr/local/

  cd /usr/local/

5. Unzip the redis installation package

  tar zxf redis-4.0.7.tar.gz

6. Map the redis shortcut folder

  ln -s /usr/local/redis-4.0.7 /usr/local/redis

  cd /usr/local/redis

7. Compile

  make

8. Map the redis bin shortcut folder

  ln -s /usr/local/redis/src /usr/local/redis/bin

9. Backup configuration files

  mkdir /usr/local/redis/conf_bak

  cp -rp /usr/local/redis/*.conf /usr/local/redis/conf_bak/

10. Modify the configuration file redis.conf

  vi /usr/local/redis/redis.conf

Modify the configuration as follows:
  protected-mode yes
##Binding host address
##bind <local ip>
  bind 10.76.64.16
##Redis does not run as a daemon process by default, you can modify it through this configuration item and use yes to enable the daemon Process
  daemonize yes
##Set the IP address and port of the master service when the machine is the slave service. When Redis starts, it will automatically synchronize data from the master
#slaveof <masterip> <masterport>
  slaveof 10.76.64.16 6379 ( The ip port number of the master server)
##When password protection is set for the master service, the password for the slav service to connect to the master #
masterauth <master-password>
  masterauth redis2ac
##Set the Redis connection password. If the connection password is configured, the client is in the When connecting to Redis, you need to provide the password through the AUTH <password> command, which is disabled by default
#requirepass <master-password>
  requirepass redis2ac

11. Modify the sentinel configuration

  vi /usr/local/redis/sentinel.conf

Modify the configuration as follows:

##bind <local ip>
  bind 10.76.64.16
##Redis does not run as a daemon process by default, you can modify it through this configuration item, use yes to enable
  daemonize yes
##sentinel monitor mymaster <host master ip> <host master port> 1
  sentinel monitor mymaster 10.76.64.16 6379 1 (the ip port number of the master server)
##sentinel auth-pass mymaster <host master redis password>
  sentinel auth-pass mymaster redis2ac

12. The redis service starts

  /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf

13. The reids sentinel process starts

  /usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel.conf

 

Redis master-slave replication process:

When the slave is configured, the slave establishes a connection with the master, and then sends the sync command. Whether it is the first connection or reconnection, the master will start a background process to save the database snapshot to the file, and the master master process will start to collect new write commands and cache them. After the background process completes writing the file, the master sends the file to the slave, the slave saves the file to the hard disk, and then loads it into the memory, and then the master forwards the cached command to the slave, and then the master sends the received write command to the slave.

If the master receives synchronous connection commands from multiple slaves at the same time, the master will only start one process to write the database mirror and then send it to all slaves. The master is non-blocking when synchronizing data and can receive read and write requests from users. However, the slave side is in blocking mode, and the slave cannot respond to the client's query when synchronizing the master data.

Data persistence can be disabled on the master, just comment out all save configurations in the master configuration file, and then configure data persistence only on the slave

The benefits of having a master-slave server (slave servers are read-only and can be one master and multiple slaves)

1. When the master server is reading and writing, it will be transferred to the slave reading, reducing the pressure on the server

2. The hot backup master and slave can set a password, or the passwords can be inconsistent

 

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325194520&siteId=291194637