Redis + Keepalived memory database cluster configuration

Source: Internet
Author: User
Tags redis cluster install redis

Redis + Keepalived memory database cluster configuration

Redis is an open-source log-type and Key-Value database written in ansi c language that supports Network, memory persistence, and provides APIs in multiple languages.

Redis is a key-value storage system. Similar to Memcached, Memcached supports more storage value types, including string, list, set, and zset) and hash (hash type ).

Redis is an advanced key-value database. It is similar to memcached, but data can be persistent and supports a wide range of data types. There are strings, linked lists, sets, and ordered sets. Allows you to compute, merge, and merge sets (difference) on the server side. It also supports multiple sorting functions. So Redis can also be seen as a data structure server.

All Redis data is stored in the memory and then asynchronously stored to the disk (this is called the "semi-persistent mode "); you can also write every data change to a usr/localend only file (aof) (this is called "Full persistence mode ").

To improve the high availability of redis, in addition to backing up redis dump data, we also need to create a redis master-slave architecture, which can be used to persist the database (data persistence is to save the data to the disk in general, ensure that data is not lost due to factors such as power failure.

Redis often needs to synchronize data in the memory to the disk to ensure persistence. Redis supports two persistence Methods: Snapshotting (snapshot) and Append-only file (aof .)

What is redis master-slave replication?

Redis Master-Slave replication. When a user writes data to the Master, the data file is sent to Slave through the Redis Sync mechanism, and Slave will perform the same operation to ensure data consistency; the implementation of Redis master-slave replication is very simple. At the same time, you can enable Level 2 slave on the slave and Level 3 slave database, which is similar to the master and slave databases of MySQL.

For details about how to install redis, refer to the previous course. Here, you can directly install slave by adding the following statement to the slave redis. conf configuration file:

Slaveof 192.168.33.10 6379 # slaveofmaster ip master port.

1. 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 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/keepalived

Cp $ DIR/sbin/keepalived/usr/sbin/

Ii. Configure Keepalived:

Vi/etc/keepalived/keepalied. conf

! Configuration File for keepalived

Global_defs {

Notification_email {

Wgkgood@139.com

}

Notification_email_fromwgkgood@139.com

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

Priority100

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 1, 100

Notify_down/data/sh/redis. sh

TCP_CHECK {

Connect_timeout10

Nb_get_retry3

Delay_before_retry3

Connect_port6379

}

}

}

3. Configure from Keepalived:

The configuration of keepalived. conf on the Redis slave server is the same as that on the master server. You only need to change the Realserver IP address:

Real_server 192.168.33.11; change the priority from 100 to 90.

Vi/etc/keepalived/keepalied. conf

! Configuration File for keepalived

Global_defs {

Notification_email {

Wgkgood@139.com

}

Notification_email_fromwgkgood@139.com

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 1, 100

Notify_down/data/sh/redis. sh

TCP_CHECK {

Connect_timeout10

Nb_get_retry3

Delay_before_retry3

Connect_port6379

}

}

}

4. Create a switchover script:

Create the/data/sh/redis. sh script on the master and slave databases. The content is:

/Etc/init. d/keepalived stop

Restart the keepalived service on the two Redis databases respectively.

Finally, test whether the master Mysql service will be automatically switched to Backup.

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04

Basic configuration of Redis master-slave Replication

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.