| Service Name | IP Addres | Description |
|---|---|---|
| proxy-server-01 | 10.32.161.130 | Twemproxy (nutcracker) instance |
| redis-node-01 | 10.32.161.131 | Redis cluster node |
| redis-node-02 | 10.32.161.132 | Redis cluster node |
| redis-node-03 | 10.32.161.133 | Redis cluster node |
| redis-node-04 | 10.32.161.134 | Redis cluster node |
| redis-node-05 | 10.32.161.135 | Redis cluster node |
| redis-node-06 | 10.32.161.136 | Redis cluster node |
Redis Installation and Cluster Formasion
Follow the Redis installation guide and cluster ceration steps as outlined in the reference documentation.
Reference: https://www.cnblogs.com/a120608yby/p/17167566.html
Twemproxy Installation and Configuration
# Download the package
wget https://github.com/twitter/twemproxy/releases/download/0.5.0/twemproxy-0.5.0.tar.gz -P /opt/downloads
# Build and install
cd /opt/downloads
tar xf twemproxy-0.5.0.tar.gz
cd twemproxy-0.5.0
./configure --prefix=/usr/local/twemproxy
make && make install
# Copy service startup script
cp scripts/nutcracker.init /etc/init.d/proxy-service
chmod +x /etc/init.d/proxy-service
# Configure environment variables
# vim /etc/profile.d/proxy.sh
export PATH=$PATH:/usr/local/twemproxy/sbin
# source /etc/profile.d/proxy.sh
# Modify configuration file
# mkdir /etc/proxy /usr/local/twemproxy/conf -p
# cat /usr/local/twemproxy/conf/proxy-config.yml
cluster-alpha:
listen: 10.32.161.130:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
redis: true
redis_auth: securePass123
server_retry_timeout: 2000
server_failure_limit: 1
servers:
- 10.32.161.131:6379:1
- 10.32.161.132:6379:1
- 10.32.161.133:6379:1
- 10.32.161.134:6379:1
- 10.32.161.135:6379:1
- 10.32.161.136:6379:1
# ln -sv /usr/local/twemproxy/conf/proxy-config.yml /etc/proxy/proxy-config.yml
# chown -R nobody. /etc/proxy /usr/local/twemproxy/
# Start the service
chkconfig proxy-service on
/etc/init.d/proxy-service start
Verification
# redis-cli -c -h 10.32.161.130 -p 22121 -a securePass123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.32.161.130:22121> set data1 111
OK
10.32.161.130:22121> set data2 222
-> Redirected to slot [4998] located at 10.32.161.130:6379
OK
10.32.161.130:6379> set data3 333
OK
10.32.161.130:6379> set data4 444
-> Redirected to slot [13120] located at 10.32.161.132:6379
OK
10.32.161.132:6379> set data5 555
-> Redirected to slot [9057] located at 10.32.161.131:6379
OK
10.32.161.131:6379> set data6 666
-> Redirected to slot [4866] located at 10.32.161.130:6379
OK
10.32.161.130:6379> get data3
"333"
10.32.161.130:6379> get data6
"666"
10.32.161.130:6379> get data1
-> Redirected to slot [9189] located at 10.32.161.131:6379
"111"
10.32.161.131:6379> get data2
-> Redirected to slot [4998] located at 10.32.161.130:6379
"222"
10.32.161.130:6379> get data5
-> Redirected to slot [9057] located at 10.32.161.131:6379
"555"
10.32.161.131:6379> get data4
-> Redirected to slot [13120] located at 10.32.161.132:6379
"444"