Apsaradb for Redis high availability cluster solution and emergency maintenance skills

Source: Internet
Author: User
Tags http 200 haproxy install redis

Premise: the master-slave structure is in place, and the master database is not configured with persistence. Configure AOF from the slave database. (The master database is used for backup and write services, and the slave database is used to provide read services)

Scenario: What should I do if the master database suddenly goes down?

Method: connect to the slave database and perform the save operation. The latest dump. rdb file of the slave database will be saved in the data directory of the slave database. Copy the dump. rdb file to the data directory of the master database. Restart the master database.

This is because I thought of the cluster solution, but redis does not officially have a master-

Master mode ~ In this case, we can only find a solution for ourselves ~

Implementation principle ~

When both the Master and Slave work normally, the Master is responsible for reading and the Slave is responsible for synchronization;

When the Master node fails and the Slave is normal, the Slave takes over the service and disables the Master/Slave replication function;

And then cyclically.

In this way, if either of the two redis servers fails, the other server will continue to provide services without any noticeable impact on the website or data loss.

You can also enable the Master node to resume data synchronization from the Slave, disable Master-Slave replication after data synchronization, and restore the Master identity. After the Master node completes data synchronization, restore the Slave identity.

High Availability

If you want to separate the read/write operations, you can point to a vip ~ The two masters use keepalived and scripts for judgment.

If read, try to use haproxy for shunting. In this way, even if one is down, haproxy will automatically remove it ~

Install redis ~

  1. Wget http://redis.googlecode.com/files/redis-2.2.13.tar.gz
  2. Tar-zxf redis-2.2.13.tar.gz
  3. Cd redis-2.2.13
  4. Make
  5. Make install

Install keepalived ~

  1. Tar-xzvf keepalived-1.1.20.tar.gz
  2. Cd keepalived-1.1.20
  3. ./Configure -- prefix =/usr/local/webserver/keepalived
  4. Make
  5. Make install
  6. Cp/usr/local/webserver/keepalived/sbin/keepalived/usr/sbin
  7. Cp/usr/local/webserver/keepalived/etc/sysconfig
  8. Cp/usr/local/webserver/keepalived/etc/rc. d/init. d/keepalived/etc/init. d
  9. Mkdir/etc/keepalived
  10. Cp/usr/local/webserver/keepalived/etc/keepalived. conf/etc/keepalived

 

After the installation, let's talk about the high availability section. below is the configuration file of the master's keepalived. conf ~

Killall-0 redis-server is used to determine the survival of the process ~

You can also use the checkredis. sh script ~

[Simple for everyone ~] This method is a program that comes with redis to judge service survival.

  1. #! /Bin/bash
  2. REDIS_HOME = "/home/redis"
  3. REDIS_COMMANDS = "/home/redis/src" # The location of the redis binary
  4. REDIS_MASTER_IP = "172.16.0.180" # Redis MASTER ip
  5. REDIS_MASTER_PORT = "6379" # Redis MASTER port
  6. ERROR_MSG = '$ {REDIS_COMMANDS}/redis-cli ping'
  7. #
  8. # Check the output for PONG.
  9. #
  10. If ["$ ERROR_MSG "! = "PONG"]
  11. Then
  12. # Redis is down and return http 503
  13. /Bin/echo-e "HTTP/1.1 503 Service Unavailable \ r \ n"
  14. /Bin/echo-e "Content-Type: text/plain \ r \ n"
  15. /Bin/echo-e "\ r \ n"
  16. /Bin/echo-e "Redis is * down *. \ r \ n"
  17. /Bin/echo-e "\ r \ n"
  18. Exit 1
  19. Else
  20. # Redis is fine, return http 200
  21. /Bin/echo-e "HTTP/1.1 200 OK \ r \ n"
  22. /Bin/echo-e "Content-Type: text/plain \ r \ n"
  23. /Bin/echo-e "\ r \ n"
  24. /Bin/echo-e "Redis is running. \ r \ n"
  25. /Bin/echo-e "\ r \ n"
  26. Exit 0
  27. Fi
  • 1
  • 2
  • 3
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.