本实践是在两台虚拟机中部署了伪集群进行试验,最后才在生产环境中进行同步,同步完成之后记得做数据一致性验证。
集群 |
地址 |
集群一 |
101.200.196 |
集群二 |
119.3.223.138 |
redis-shark
的使用:
https://github.com/alibaba/RedisShake
1. 集群一插入1w条数据
[redis@hayden redis-cluster]$ cat import.sh
#!/bin/bash
for ((i=0;i<10000;i++))
do
echo -en "helloworld" | /home/redis/redis-cluster/6379/redis-cli -a master123 -h 101.200.196.6 -p 6379 -x set name$i >>redis.log
done
[redis@hayden redis-cluster]$ sh import.sh
[redis@hayden redis-cluster]$ /home/redis/redis-cluster/6379/redis-cli -a master123 -h 101.200.196.6 -p 6379 info Keyspace
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Keyspace
db0:keys=10000,expires=0,avg_ttl=0
[redis@hayden redis-cluster]$
2. 集群二无数据
[redis@huawei 6379]$ ./redis-cli -a master123 -h 119.3.223.138 -p 6379 info Keyspace
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Keyspace
[redis@huawei 6379]$
3. 集群二同步集群一中的数据
3.1 安装redis-shake
[root@huawei redis]$ cd software/
[root@huawei software]$ ll
total 38156
-rw-r--r-- 1 redis redis 1729973 Apr 29 2018 redis-4.0.8.tar.gz
-rw-r--r-- 1 redis redis 1985757 Aug 12 11:45 redis-5.0.8.tar.gz
-rw-r--r-- 1 redis redis 5322335 Aug 12 09:51 redis-full-check-1.4.8.tar.gz
-rw-r--r-- 1 redis redis 20624591 Aug 12 12:20 redis-shake-v2.0.3.tar.gz
-rw-r--r-- 1 redis redis 9398130 Aug 12 13:55 tcl8.6.5-src.tar.gz
[root@huawei software]$ cd
[root@huawei ~]$ cd /home/redis/software/
[root@huawei software]$ tar xf redis-shake-v2.0.3.tar.gz -C ../
[root@huawei software]$ cd ..
[root@huawei redis]$ ll
total 16
drwxr-xr-x 7 redis redis 4096 Aug 12 14:57 redis-cluster
drwxr-xr-x 6 redis redis 4096 Aug 12 14:57 redis-sentinel
drwxr-xr-x 2 502 games 4096 Jul 27 18:40 redis-shake-v2.0.3
drwxr-xr-x 2 redis redis 4096 Aug 12 13:58 software
[root@huawei redis]$
3.2 修改配置文件
- 主要修改以下几项,其他的为默认,太多就没有粘贴出来
[root@huawei redis-shake-v2.0.3]$ egrep -v "^#|^$" redis-shake.conf
log.file = /home/redis/redis-shake-v2.0.3/redis-shake.log
pid_path = /home/redis/redis-shake-v2.0.3/redis-shake.pid
source.type = sentinel
source.address = mymaster:master@101.200.196.6:6379;101.200.196.6:26379
source.password_raw = master123
target.type = sentinel
target.address = mymaster:master@119.3.223.138:6379;119.3.223.138:26379
target.password_raw = master123
key_exists = rewrite
[redis@huawei redis-shake-v2.0.3]$
3.3 开始同步
[redis@huawei redis-shake-v2.0.3]$ ./redis-shake.linux -conf=redis-shake.conf -type=sync &
[redis@huawei redis-shake-v2.0.3]$ tail -f redis-shake.log
3.4 查看集群二数据
[redis@huawei ~]$ /home/redis/redis-cluster/6379/redis-cli -a master123 -h 119.3.223.138 -p 6379 info Keyspace
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Keyspace
db0:keys=10000,expires=0,avg_ttl=0
[redis@huawei ~]$