Redis+keepalived Memory DB cluster configuration

Source: Internet
Author: User
Tags memcached install redis

Preface: Redis is an open source use of ANSI C language Write, support network, memory-based and persistent journaling, Key-value Database , and provides APIs in multiple languages.

Redis is a key-value list

Redis is an advanced Key-value database. It is similar to memcached, but the data can be persisted and the supported data types are rich. There are strings, lists, collections, and ordered collections. Supports the addition, intersection and complement (difference) of the compute sets on the server side, and supports a variety of sorting functions. So Redis can also be viewed as a data structure server.

Redis all of the data is stored in memory and then periodically asynchronously saved to disk (this is called "semi-persistent mode"), and each data change can be written to a usr/localend only file (AOF) (this is called "Full persistence mode").


To improve Redis high availability, in addition to backing up Redis dump data, we also need to create a Redis master-slave architecture that can be used from persisting the database (data persistence is simply saving the data to disk, ensuring no loss of data due to power outages, etc.).

Redis It is often necessary to synchronize the in-memory data to disk to ensure persistence. Redis supports two persistence modes, one is snapshotting (snapshot) is the default, and the other is the way Append-only file (abbreviated AOF). )

What is Redis's master-slave replication?

Redis master-slave replication, when the user writes data to the master, sending the data file to Slave,slave via the Redis Sync mechanism also performs the same operation to ensure consistent data, and the master-slave replication of Redis is straightforward. At the same time slave can also open two-level slave, three-level slave from the library, similar to the master and slave MySQL.

To install Redis you can refer to the previous lesson Oh, install slave directly here, just add the following statement in the slave redis.conf configuration file:

slaveof 192.168.33.10 6379 # Slaveofmaster The port of the IP master.

First, install keepalived:

Tar zxf keepalived-1.2.1.tar.gz cd keepalived-1.2.1&&./configure--with-kernel-dir=/usr/src/kernels/2.6.18* &&make&& make install dir=/usr/local/, CP $DIR/ETC/RC.D/INIT.D/KEEPALIVED/ETC/RC.D/INIT.D/CP $DIR/ etc/sysconfig/keepalived/etc/sysconfig/&&mkdir-p/ETC/KEEPALIVEDCP $DIR/sbin/keepalived/usr/sbin/

Second, the configuration keepalived:

Vi/etc/keepalived/keepalied.conf

! Configuration File for Keepalived

Global_defs {    notification_email{       [email  protected]    }    [email protected]     smtp_server127.0.0.1    smtp_connect_timeout30    router_idlvs_ devel } # vip1 vrrp_instance vi_1 {     state  Backup       interface eth0    lvs_sync_daemon_ Inteface eth0     virtual_router_id151     priority  100     advert_int 5     nopreempt      authentication {         auth_typepass          auth_pass2222     }      virtual_ipaddress{         192.168.33.100     } }  virtual_server 192.168.33.100 6379 {     delay_loop 6         lb_algo wrr        lb_ kind dr       persistence_timeout60         protocol TCP              real_server 192.168.33.10 6379 {          weight 100                 notify_down/data/sh/redis.sh         TCP_CHECK {          connect_timeout10          nb_get_retry3         delay_before_retry3          connect_port6379         }      } }

Third, from the keepalived configuration:

Redis from the server configuration keepalived.conf as with master, you only need to modify the Realserver IP to:

Real_server 192.168.33.11; The priority level is changed from 100 to 90.

Vi/etc/keepalived/keepalied.conf

! Configuration File for Keepalived

Global_defs {    notification_email{       [email  protected]    }    [email protected]     smtp_server127.0.0.1    smtp_connect_timeout30    router_idlvs_ devel } # vip1 vrrp_instance vi_1 {     state  Backup       interface eth0    lvs_sync_daemon_ Inteface eth0     virtual_router_id151     priority  90     advert_int 5     nopreempt      authentication {         auth_typepass          auth_pass2222     }      virtual_ipaddress{         192.168.33.100     } }  virtual_server 192.168.33.100 6379 {     delay_loop 6         lb_algo wrr        lb_ kind dr       persistence_timeout60         protocol TCP              real_server 192.168.33.11 6379 {          weight 100                 notify_down/data/sh/redis.sh         TCP_CHECK {          connect_timeout10          nb_get_retry3         delay_before_retry3          connect_port6379         }      } }

Iv. Create a toggle script:

Create a/data/sh/redis.sh script on the master, slave database, with the content:

/etc/init.d/keepalived stop

Then restart the keepalived service on both Redis databases separately.

The final test stops the master MySQL service and will automatically switch to backup.

This article is from the "Wu Guangko-Keio Linux Operations Training" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/1690864

Redis+keepalived Memory DB cluster configuration

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.