Introduction to Redis Clusters:
A Redis cluster is an advanced version of Redis that implements distributed and allows single points of failure.
Redis cluster does not have the most important or central node, this version of the main goal is to design a linear scalability (can be arbitrarily added and deleted nodes?). ) function.
Redis clusters may sacrifice some of the functionality that allows single points of failure for data consistency, so the system tries to ensure consistency and effectiveness when network failures and node failures occur. (Here we think node failure is a special case of network failure.)
In order to solve the problem of single point of failure, we also need masters and slaves. Even if the primary node (master) and Slave nodes (slave) are functionally consistent, even if they are deployed on the same server, the slave node is only used to replace the failed master node. In fact, it should be said that the slave node only accepts read-only operations if there is no need to read-after-write (write and immediately read the data to prevent data from being fetched during data synchronization).
Twemproxy Introduction:
Twemproxy, also known as Nutcraker. is a twtter open source Redis and Memcache proxy server. As an efficient cache server, Redis is of great application value. But when used more often, you want to be able to manage it in some way. Avoid the looseness of each client management connection for each application. At the same time, it becomes controllable to some extent. Search for a lot of open source agent projects, the implementation of the Python shard client. Node's proxy middle tier, as well as a variety of restfull open source proxies.
Server System: CentOS 6.5 x86_64
Server architecture:
10.57.1.127 twemproxy master,redis master10.57.1.197 twemproxy slave,redis slave10.57.1.111 keepalived
Service version:
redis:2.4.10keepalived:1.2.8autoconf:2.69twemproxy:0.4.0
First, Redis
1. Installing Redis on Redis master and Redis Slave hosts
Install the Epel source first
Yum-y localinstall http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmyum-y Install Redis
Modify/etc/redis.conf on Redis master to the following:
Port 6379bind 0.0.0.0
Modify/etc/redis.conf the following on Redis slave:
Port 6379bind 0.0.0.0slaveof 10.57.1.127 6379
2. Start Redis Service
/etc/init.d/redis restart
3. Verifying Redis Service
Log on to the Redis master server and Execute
Redis-cli-h 10.57.1.127-p 6379 info|grep role
If the display
Role:master
Log on to the Redis slave server and Execute
Redis-cli-h 10.57.1.197-p 6379 info|grep role
If the display
Role:slave
Note that Redis Master/slave has been configured
Second, Twemproxy
1. Install Twemproxy on the Redis master and Redis Slave hosts
First download the latest Twemproxy and find the latest version on GitHub
git clone https://github.com/twitter/twemproxy.git cd twemproxy/cflags= "-ggdb3-o0" Autoreconf-fvi &&. Configure--prefix=/usr/local/twemproxy--enable-debug=log make make install/usr/local/twemproxy/bin/nutcracker-t nutcracker:configuration file ' conf/nutcracker.yml ' syntax is OKCP conf/nutcracker.yml/usr/local/twemproxy
2. Configuring Twemproxy Master
vim/usr/local/twemproxy/nutcracker.ymlredis1:listen:0.0.0.0:22122 hash:fnv1a_64 Hash_tag: "{}" Distribution:ketam A auto_eject_hosts:true timeout:400 redis:true servers:-10.57.1.127:6379:1 Server1 # Redis instance IP, port, weight-10.57. 1.197:6379:1 Server2
3, configuration Twemproxy slave
vim/usr/local/twemproxy/nutcracker.ymlredis2:listen:0.0.0.0:22122 hash:fnv1a_64 Hash_tag: "{}" Distribution:k Etama auto_eject_hosts:true timeout:400 redis:true servers:-10.57.1.127:6379:1 Server1 # Redis instance IP, port, weight -10.57.1.197:6379:1 Server2
4. Use Twemproxy startup script to start Twemproxy master, Twemproxy Slave
vim /etc/init.d/redis-twemproxy#!/bin/bashsource /etc/profile; Function stop () {/usr/bin/pkill nutcracker}function start () {/usr/local/twemproxy/sbin/nutcracker -d -c /usr/local/twemproxy/nutcracker.yml}case $1 in stop) stop ;; start) Start ;; *) echo "usage: ' basename $0 ' {stop|start}" ;; Esac
5. Redis Testing Service
Perform
Redis-cli-h 10.57.1.127-p 22122redis-cli-h 10.57.1.197-p 22122
If there is no error, it means success!
Third, keepalived
1. Install keepalived and Ipvsadm on the keepalived host
Yum-y Install keepalived Ipvsadm
2, Configuration keepalived
Vim /etc/keepalived/keepalived.conf ! configuration file for keepalivedglobal_ defs { notification_email { [email protected] } notification_email_from [email protected] smtp_ Server smtp.yeah.net smtp_connect_timeout 30 router_id redis_ twemproxy}vrrp_instance vip_1 { interface eth0 state master virtual_router_id 55 priority 100 virtual_ipaddress { 10.57.1.101 }} virtual_server 10.57.1.101 6379 { delay_loop 3 lb_algo wrr lb_kind DR protocol TCP sorry_server 127.0.0.1 22122 real_server 10.57.1.127 22122 { tcp_check { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 10.57.1.197 22122 { tcp_check { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }}
3. Start keepalived
/etc/init.d/keepalived start
4. Verification keepalived
Ipvsadm-lnip Virtual Server version 1.2.1 (size=4096) Prot localaddress:port Scheduler Flags-Remoteaddress:port Forward Weight activeconn inactconntcp 10.57.1.101:6379 WRR-10.57.1.127:22122 Route 1 0 0-10.57.1.197:22122 Route 1 0 0
Description Keepalived Configuration Succeeded
5, test the 10.57.1.101 6379 port is unblocked
Nc-nvz-w 5 10.57.1.101 6379Connection to 10.57.1.101 6379 port [tcp/*] succeeded!
Show succeeded indicates success
The Redis cluster has been successfully configured.
This article from the "Past with the Wind" blog, declined reprint!
Redis+twemproxy+keepalive Cluster Construction