Redis Cluster Scenario Redis-twemproxy-keepalived

Source: Internet
Author: User
Tags install openssl openssl redis redis cluster

The current version of Redis does not support distributed, which is added in version 3.0. Redis currently only supports "Master and Slave Synchronization" and "from Sync", so you need to apply your own to meet your needs.


TP------192.168.10.15

TP1------192.168.10.18

TP TP1 Virtual vip:192.168.10.243

V1------192.168.10.224

V2------192.168.10.14

V1 v2 Virtual vip:192.168.10.241

V3------192.168.10.16

V4------192.168.10.17

V3 v4 Virtual vip:192.168.10.242

1. Make Redis hot standby Node 2 group first

R1 and R2 as the first set of nodes

V1 (192.168.10.224) V2 (192.168.10.14) through keepalived

Master (Master): V1

Back Up (Backup): V2

Virtual IP 192.168.10.241

build steps: Master and prepare the same

1. Installing Redis

    

wget http://redis.googlecode.com/files/redis-2.0.0-rc4.tar.gz

Tar zxvf redis-2.0.0-rc4.tar.gz

CD REDIS-2.0.0-RC4

Make

CP redis.conf/etc/This file is a Redis-initiated configuration file

CP Redis-benchmark REDIS-CLI redis-server/usr/bin/

Redis-server/etc/redis.conf

Redis-cli

Note Modify the configuration: daemonize Yes

2. Install the highly available software keepalived

 

wget http://www.keepalived.org/software/keepalived-1.1.20.tar.gz

Tar zxvf keepalived-1.1.20.tar.gz

CD keepalived-1.1.20

./configure--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-x86_64/

Make && make install

cp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/

cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/

Mkdir/etc/keepalived

cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/

Cp/usr/local/sbin/keepalived/usr/sbin

/etc/init.d/keepalived start

Error:

!!! OpenSSL is not a properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!

Solve

Yum Install Openssl-devel

Error

Configure:error:Popt Libraries is required

Solve

Yum Install Popt-devel

configuration file Modification Note the hardware name of the monitored network card

V1 configuration file

Keepalived:

State MASTER

virtual_ipaddress {

192.168.10.241 # # #VIP

}

Redis_backup.sh:

Slaveof 192.168.10.14 6379

Redis_master.sh:

Slaveof 192.168.10.14 6379

V2 configuration file

Keepalived:

State BACKUP

virtual_ipaddress {

192.168.10.241 # # #VIP

}

Redis_backup.sh:

Slaveof 192.168.10.224 6379

Redis_master.sh:

Slaveof 192.168.10.224 6379

Test this interop node:

 

1. Start Redis on Master

Redis-server/etc/redis.conf

2. Start Redis on the slave

Redis-server/etc/redis.conf

3. Start the keepalived on master

/etc/init.d/keepalived start

4. Start the keepalived on the slave

/etc/init.d/keepalived start

5. Try to connect Redis via VIP:

Redis-cli-h 192.168.10.241 INFO

The connection was successful and slave was connected.

Role:master

6. Try inserting some data:

Redis-cli-h 192.168.10.241 SET Hellor1 Redis

Ok

Read data from VIP

Redis-cli-h 192.168.10.241 GET Hellor1

"Redis"

reading data from Master

Redis-cli-h 192.168.10.224 GET Hellor1

"Redis"

reading data from slave

Redis-cli-h 192.168.10.14 GET Hellor1

"Redis"

below, a simulated failure occurs:

 

Kill the Redis process on master:

Killall-9 Redis-server

View the keepalived log on Master

Tailf/var/log/keepalived-redis-state.log

[Fault]

Mon Dec 2013 10:06:13 CST

At the same time the log on slave shows:

Tailf/var/log/keepalived-redis-state.log

[Master]

Mon Dec 2013 10:06:17 CST

Being master ....

Run slaveof cmd ...

Ok

Run slaveof NO One cmd ...

Ok

Then we can see that slave has taken over the service and assumed the role of master.

Redis-cli-h 192.168.10.241 INFO

Redis-cli-h 192.168.10.14 INFO

Role:master

Then we restore the master Redis process

Redis-server/etc/redis.conf

View the keepalived log on Master

Tailf/var/log/keepalived-redis-state.log

[Master]

Mon Dec 2013 10:10:13 CST

Being master ....

Run slaveof cmd ...

Ok

Run slaveof NO One cmd ...

Ok

At the same time the log on slave shows:

Tailf/var/log/keepalived-redis-state.log

[Backup]

Mon Dec 2013 10:10:12 CST

Being slave ....

Run slaveof cmd ...

Ok

You can see that the current master has resumed the master role, failover, and self-

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.