ARM架构下Tendis单实例和集群源码安装
信息介绍
环境需求
gcc >= 11 (Tendisplus >= 2.7.0,2.7.0之前使用gcc 5.5.0进行编译)
cmake >= 3.13.0
git
安装环境
操作系统:openEuler release 22.03 (LTS-SP4)
Tendis版本:2.8.0-rocksdb-v8.5.3
Gcc版本:14.1.0
解决依赖
[root@localhost ~]# yum install libxslt autoconf automake libtool cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc libatomic -y
源码安装gcc
编译安装gcc14.1.0
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
[root@localhost ~]# tar -zxvf gcc-14.1.0.tar.gz
[root@localhost ~]# cd gcc-14.1.0
[root@localhost gcc-14.1.0]# contrib/download_prerequisites
2025-05-13 06:48:12 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gettext-0.22.tar.gz [26105696/26105696] -> "gettext-0.22.tar.gz" [1]
2025-05-13 06:48:18 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 [2493916/2493916] -> "gmp-6.2.1.tar.bz2" [1]
2025-05-13 06:49:08 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 [1747243/1747243] -> "mpfr-4.1.0.tar.bz2" [1]
2025-05-13 06:49:11 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz [838731/838731] -> "mpc-1.2.1.tar.gz" [1]
2025-05-13 06:50:21 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2 [2261594/2261594] -> "isl-0.24.tar.bz2" [1]
gettext-0.22.tar.gz: OK
gmp-6.2.1.tar.bz2: OK
mpfr-4.1.0.tar.bz2: OK
mpc-1.2.1.tar.gz: OK
isl-0.24.tar.bz2: OK
All prerequisites downloaded successfully.
[root@localhost gcc-14.1.0]# cd ..
[root@localhost ~]# chown -R root.root gcc-14.1.0
[root@localhost ~]# cd gcc-14.1.0
[root@localhost ~]# mkdir build
[root@localhost ~]# cd build
[root@localhost ~]# ../configure --prefix=/usr/local/gcc-14.1.0 --enable-languages=c,c++ --disable-shared --disable-multilib --enable-threads=posix --enable-bootstrap --enable-checking=release --enable-default-pie --enable-default-ssp CFLAGS='-fPIC -fPIE -static' CXXFLAGS='-fPIC -fPIE -static'
[root@localhost ~]# make -j16
[root@localhost ~]# make install
修改gcc环境变量
在/etc/profile文件里面追加下面内容,然后 source /etc/profile
export PATH=/usr/local/gcc-14.1.0/bin:${PATH}
export CC=/usr/local/gcc-14.1.0/bin/gcc
export CXX=/usr/local/gcc-14.1.0/bin/g++
源码编译安装tendis
通过git下载tendis和第三方依赖
需要自行解决访问githup的问题
[root@localhost ~]# git clone https://github.com/Tencent/Tendis.git --recursive
Cloning into 'Tendis'...
remote: Enumerating objects: 24165, done.
remote: Counting objects: 100% (2378/2378), done.
remote: Compressing objects: 100% (971/971), done.
remote: Total 24165 (delta 1476), reused 1415 (delta 1407), pack-reused 21787 (from 3)
Receiving objects: 100% (24165/24165), 85.34 MiB | 735.00 KiB/s, done.
Resolving deltas: 100% (16123/16123), done.
Submodule 'src/thirdparty/asio' (https://github.com/chriskohlhoff/asio.git) registered for path 'src/thirdparty/asio'
Submodule 'src/thirdparty/gflag' (https://github.com/gflags/gflags.git) registered for path 'src/thirdparty/gflag'
Submodule 'src/thirdparty/glog' (https://github.com/google/glog.git) registered for path 'src/thirdparty/glog'
Submodule 'src/thirdparty/googletest' (https://github.com/google/googletest.git) registered for path 'src/thirdparty/googletest'
Submodule 'src/thirdparty/jemalloc' (https://github.com/jemalloc/jemalloc.git) registered for path 'src/thirdparty/jemalloc'
Submodule 'src/thirdparty/lz4' (https://github.com/lz4/lz4.git) registered for path 'src/thirdparty/lz4'
Submodule 'src/thirdparty/rapidjson' (https://github.com/Tencent/rapidjson.git) registered for path 'src/thirdparty/rapidjson'
Submodule 'src/thirdparty/rocksdb/rocksdb' (https://github.com/facebook/rocksdb.git) registered for path 'src/thirdparty/rocksdb/rocksdb'
Submodule 'src/thirdparty/snappy' (https://github.com/google/snappy.git) registered for path 'src/thirdparty/snappy'
Cloning into '/root/tmp/Tendis/src/thirdparty/asio'...
remote: Enumerating objects: 71328, done.
remote: Counting objects: 100% (302/302), done.
remote: Compressing objects: 100% (179/179), done.
remote: Total 71328 (delta 164), reused 123 (delta 123), pack-reused 71026 (from 2)
Receiving objects: 100% (71328/71328), 29.48 MiB | 913.00 KiB/s, done.
Resolving deltas: 100% (53118/53118), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/gflag'...
remote: Enumerating objects: 2518, done.
remote: Counting objects: 100% (88/88), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 2518 (delta 47), reused 51 (delta 35), pack-reused 2430 (from 3)
Receiving objects: 100% (2518/2518), 1.57 MiB | 1.49 MiB/s, done.
Resolving deltas: 100% (1458/1458), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/glog'...
remote: Enumerating objects: 5693, done.
remote: Counting objects: 100% (196/196), done.
remote: Compressing objects: 100% (77/77), done.
remote: Total 5693 (delta 168), reused 119 (delta 119), pack-reused 5497 (from 2)
Receiving objects: 100% (5693/5693), 5.11 MiB | 1.42 MiB/s, done.
Resolving deltas: 100% (3909/3909), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/googletest'...
remote: Enumerating objects: 28045, done.
remote: Counting objects: 100% (272/272), done.
remote: Compressing objects: 100% (176/176), done.
remote: Total 28045 (delta 178), reused 97 (delta 96), pack-reused 27773 (from 3)
Receiving objects: 100% (28045/28045), 13.55 MiB | 739.00 KiB/s, done.
Resolving deltas: 100% (20785/20785), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/jemalloc'...
remote: Enumerating objects: 30406, done.
remote: Counting objects: 100% (623/623), done.
remote: Compressing objects: 100% (333/333), done.
remote: Total 30406 (delta 478), reused 290 (delta 290), pack-reused 29783 (from 3)
Receiving objects: 100% (30406/30406), 12.67 MiB | 684.00 KiB/s, done.
Resolving deltas: 100% (22239/22239), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/lz4'...
remote: Enumerating objects: 17235, done.
remote: Counting objects: 100% (464/464), done.
remote: Compressing objects: 100% (249/249), done.
remote: Total 17235 (delta 292), reused 215 (delta 215), pack-reused 16771 (from 4)
Receiving objects: 100% (17235/17235), 7.07 MiB | 1.22 MiB/s, done.
Resolving deltas: 100% (11811/11811), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/rapidjson'...
remote: Enumerating objects: 25114, done.
remote: Counting objects: 100% (49/49), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 25114 (delta 27), reused 17 (delta 17), pack-reused 25065 (from 2)
Receiving objects: 100% (25114/25114), 29.77 MiB | 748.00 KiB/s, done.
Resolving deltas: 100% (19208/19208), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/rocksdb/rocksdb'...
remote: Enumerating objects: 138459, done.
remote: Counting objects: 100% (99/99), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 138459 (delta 50), reused 25 (delta 24), pack-reused 138360 (from 3)
Receiving objects: 100% (138459/138459), 222.54 MiB | 742.00 KiB/s, done.
Resolving deltas: 100% (106202/106202), done.
Cloning into '/root/tmp/Tendis/src/thirdparty/snappy'...
remote: Enumerating objects: 1532, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 1532 (delta 19), reused 20 (delta 14), pack-reused 1494 (from 2)
Receiving objects: 100% (1532/1532), 2.79 MiB | 1023.00 KiB/s, done.
Resolving deltas: 100% (1026/1026), done.
Submodule path 'src/thirdparty/asio': checked out '22afb86087a77037cd296d27134756c9b0d2cb75'
Submodule path 'src/thirdparty/gflag': checked out 'e171aa2d15ed9eb17054558e0b3a6a413bb01067'
Submodule 'doc' (https://github.com/gflags/gflags.git) registered for path 'src/thirdparty/gflag/doc'
Cloning into '/root/tmp/Tendis/src/thirdparty/gflag/doc'...
remote: Enumerating objects: 2518, done.
remote: Counting objects: 100% (95/95), done.
remote: Compressing objects: 100% (59/59), done.
remote: Total 2518 (delta 47), reused 47 (delta 30), pack-reused 2423 (from 3)
Receiving objects: 100% (2518/2518), 1.57 MiB | 1.11 MiB/s, done.
Resolving deltas: 100% (1457/1457), done.
Submodule path 'src/thirdparty/gflag/doc': checked out '8411df715cf522606e3b1aca386ddfc0b63d34b4'
Submodule path 'src/thirdparty/glog': checked out '96a2f23dca4cc7180821ca5f32e526314395d26a'
Submodule path 'src/thirdparty/googletest': checked out '15460959cbbfa20e66ef0b5ab497367e47fc0a04'
Submodule path 'src/thirdparty/jemalloc': checked out '54eaed1d8b56b1aa528be3bdd1877e59c56fa90c'
Submodule path 'src/thirdparty/lz4': checked out 'fdf2ef5809ca875c454510610764d9125ef2ebbd'
Submodule path 'src/thirdparty/rapidjson': checked out '0ccdbf364c577803e2a751f5aededce935314313'
Submodule 'thirdparty/gtest' (https://github.com/google/googletest.git) registered for path 'src/thirdparty/rapidjson/thirdparty/gtest'
Cloning into '/root/tmp/Tendis/src/thirdparty/rapidjson/thirdparty/gtest'...
remote: Enumerating objects: 28045, done.
remote: Counting objects: 100% (276/276), done.
remote: Compressing objects: 100% (176/176), done.
remote: Total 28045 (delta 182), reused 101 (delta 100), pack-reused 27769 (from 3)
Receiving objects: 100% (28045/28045), 13.56 MiB | 823.00 KiB/s, done.
Resolving deltas: 100% (20778/20778), done.
Submodule path 'src/thirdparty/rapidjson/thirdparty/gtest': checked out 'ba96d0b1161f540656efdaed035b3c062b60e006'
Submodule path 'src/thirdparty/rocksdb/rocksdb': checked out 'f32521662acf3352397d438b732144c7813bbbec'
Submodule path 'src/thirdparty/snappy': checked out '537f4ad6240e586970fe554614542e9717df7902'
[root@localhost ~]#
如果上述安装第三方依赖失败
[root@localhost ~]# cd Tendis/
[root@localhost Tendis]# git submodule update --init --recursive
本地配置githup的邮箱和用户名
[root@localhost Tendis]# git config --global user.email "hesheng@yusys.com.cn"
[root@localhost Tendis]# git config --global user.name "hesheng"
如官方不配置邮箱和用户名,在编译的时候会出下列错误
/root/Tendis/src/tendisplus/server/server_params.cpp:23:10: fatal error: rocksdb/tendis_extension.h: No such file or directory
23 | #include "rocksdb/tendis_extension.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [src/tendisplus/server/CMakeFiles/server_params.dir/build.make:76: src/tendisplus/server/CMakeFiles/server_params.dir/server_params.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2511: src/tendisplus/server/CMakeFiles/server_params.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
预处理
[root@localhost Tendis]# mkdir build
[root@localhost Tendis]# cd build
[root@localhost build]# cmake ..
如果存在以下错误日志,需要添加预处理参数 USE_JEMALLOC=no
error: patch failed: src/prof.c:23
error: src/prof.c: patch does not apply
编译Tendis
[root@localhost build]# make -j16
启动Tendis
Tendis目录下有一个配置文件模版(tendisplus.conf),可以通过该配置模版直接启动,当然也可以配置与实际环境相关的信息
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf
[root@localhost log]# tail -100f tendisplus.WARNING
Log file created at: 2025/05/13 06:03:11
Running on machine: localhost
Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg
W0513 06:03:11.534560 493735 index_manager.cpp:342] index manager running...
W0513 06:03:11.534597 493477 server_entry.cpp:850] ready to accept connections at 127.0.0.1:51002 :51002
^C
[root@localhost log]# pwd
/root/Tendis/home/log
[root@localhost log]#
[root@localhost log]# netstat -lpn|grep 51002
tcp 0 0 127.0.0.1:51002 0.0.0.0:* LISTEN 493477/./build/bin/
[root@localhost log]#
安装redis客户端
[root@localhost bin]# ls
checkdts compare_instances memtier_benchmark predixy README.md redis-benchmark redis-cli redis-server redis-sync
[root@localhost bin]#这个下面的命令都是X86架构下预编译出来的,在ARM架构下,无法使用命令:
[root@localhost bin]# ./redis-cli --help
-bash: ./redis-cli: cannot execute binary file: Exec format error
[root@localhost bin]#需要手动编译redis
编译安装redis5.0.14
[root@localhost ~]# tar -xvf redis-5.0.14.tar.gz
[root@localhost ~]# cd redis-5.0.14
[root@localhost redis-5.0.14]# make
通过redis连接Tendis
[root@localhost src]# pwd
/root/redis-5.0.14/src
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 51002
127.0.0.1:51002> keys *
1) "a"
127.0.0.1:51002> set b 123
OK
127.0.0.1:51002> get b
"123"
127.0.0.1:51002>
集群安装
创建目录
[root@localhost Tendis]# mkdir -p home{1..5}/db
创建配置文件
[root@localhost Tendis]# cp tendisplus.conf tendisplus.conf_3001
[root@localhost Tendis]# cp tendisplus.conf tendisplus.conf_3002
[root@localhost Tendis]# cp tendisplus.conf tendisplus.conf_3003
[root@localhost Tendis]# cp tendisplus.conf tendisplus.conf_3004
[root@localhost Tendis]# cp tendisplus.conf tendisplus.conf_3005
修改配置文件
[root@localhost Tendis]# more tendisplus.conf
# tendisplus configuration for testing
cluster-enabled yes
port 3000
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home/log
dumpdir ./home/dump
dir ./home/db
pidfile ./home/tendisplus.pid
slowlog ./home/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
[root@localhost Tendis]# more tendisplus.conf_3001
# tendisplus configuration for testing
cluster-enabled yes
port 3001
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home1/log
dumpdir ./home1/dump
dir ./home1/db
pidfile ./home1/tendisplus.pid
slowlog ./home1/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
[root@localhost Tendis]# more tendisplus.conf_3002
# tendisplus configuration for testing
cluster-enabled yes
port 3002
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home2/log
dumpdir ./home2/dump
dir ./home2/db
pidfile ./home2/tendisplus.pid
slowlog ./home2/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
[root@localhost Tendis]# more tendisplus.conf_3003
# tendisplus configuration for testing
cluster-enabled yes
port 3003
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home3/log
dumpdir ./home3/dump
dir ./home3/db
pidfile ./home3/tendisplus.pid
slowlog ./home3/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
[root@localhost Tendis]# more tendisplus.conf_3004
# tendisplus configuration for testing
cluster-enabled yes
port 3004
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home4/log
dumpdir ./home4/dump
dir ./home4/db
pidfile ./home4/tendisplus.pid
slowlog ./home4/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
[root@localhost Tendis]# more tendisplus.conf_3005
# tendisplus configuration for testing
cluster-enabled yes
port 3005
bind 10.150.5.19
daemon on
loglevel notice
logdir ./home5/log
dumpdir ./home5/dump
dir ./home5/db
pidfile ./home5/tendisplus.pid
slowlog ./home5/log/slowlog
rocks.blockcachemb 4096
executorThreadNum 48
[root@localhost Tendis]#
启动tendis实例
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf_3001
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf_3002
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf_3003
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf_3004
[root@localhost Tendis]# ./build/bin/tendisplus tendisplus.conf_3005
查看实例启动
[root@localhost Tendis]# ps -ef|grep tendis
root 557225 1 4 09:16 ? 00:01:01 ./build/bin/tendisplus tendisplus.conf
root 557281 1 0 09:16 ? 00:00:11 ./build/bin/tendisplus tendisplus.conf_3001
root 557322 1 4 09:16 ? 00:01:02 ./build/bin/tendisplus tendisplus.conf_3002
root 557378 1 0 09:16 ? 00:00:11 ./build/bin/tendisplus tendisplus.conf_3003
root 557449 1 4 09:16 ? 00:01:00 ./build/bin/tendisplus tendisplus.conf_3004
root 557504 1 0 09:16 ? 00:00:11 ./build/bin/tendisplus tendisplus.conf_3005
root 560835 91584 0 09:40 pts/0 00:00:00 grep --color=auto tendis
[root@localhost Tendis]#
[root@localhost Tendis]# netstat -lpn|grep 300
tcp 0 0 10.150.5.19:13003 0.0.0.0:* LISTEN 557378/./build/bin/
tcp 0 0 10.150.5.19:13004 0.0.0.0:* LISTEN 557449/./build/bin/
tcp 0 0 10.150.5.19:13005 0.0.0.0:* LISTEN 557504/./build/bin/
tcp 0 0 10.150.5.19:3000 0.0.0.0:* LISTEN 557225/./build/bin/
tcp 0 0 10.150.5.19:3001 0.0.0.0:* LISTEN 557281/./build/bin/
tcp 0 0 10.150.5.19:3002 0.0.0.0:* LISTEN 557322/./build/bin/
tcp 0 0 10.150.5.19:3003 0.0.0.0:* LISTEN 557378/./build/bin/
tcp 0 0 10.150.5.19:3004 0.0.0.0:* LISTEN 557449/./build/bin/
tcp 0 0 10.150.5.19:3005 0.0.0.0:* LISTEN 557504/./build/bin/
tcp 0 0 10.150.5.19:13000 0.0.0.0:* LISTEN 557225/./build/bin/
tcp 0 0 10.150.5.19:13001 0.0.0.0:* LISTEN 557281/./build/bin/
tcp 0 0 10.150.5.19:13002 0.0.0.0:* LISTEN 557322/./build/bin/
[root@localhost Tendis]#
不能使用原生的redis-cli创建集群
tendis不支持redis原生的redis-cli创建集群,报错如下:
[root@localhost src]# ./redis-cli --cluster create 10.150.5.19:3000 10.150.5.19:3001 10.150.5.19:3002 10.150.5.19:3003 10.150.5.19:3004 10.150.5.19:3005 --cluster-replicas 1
[ERR] Node 10.150.5.19:3000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
[root@localhost src]#
节点加入集群
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3000
10.150.5.19:3000> cluster meet 10.150.5.19 3001
OK
10.150.5.19:3000> cluster meet 10.150.5.19 3002
OK
10.150.5.19:3000> cluster meet 10.150.5.19 3003
OK
10.150.5.19:3000> cluster meet 10.150.5.19 3004
OK
10.150.5.19:3000> cluster meet 10.150.5.19 3005
OK
10.150.5.19:3000> exit
[root@localhost src]#
分配slot槽位
默认情况下,
Tendis存储版
跟Redis
一样,将所有的数据映射到16384个slot中,每个key都会对应一个槽。只有把slot分配给了Tendis节点,Tendis节点才能响应与slot相关的命令,否则就会返回move错误。分配slots可使用
cluster addslots
指令
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3000 cluster addslots {0..5461}
OK
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3002 cluster addslots {5462..10922}
OK
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3004 cluster addslots {10923..16383}
OK
[root@localhost src]#
上面的命令将16384个slots平均的分配给3个节点。 等待若干秒后,可以通过
cluster info
指令查看集群状态。
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3000 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:1
cluster_stats_messages_ping_sent:78
cluster_stats_messages_pong_sent:81
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:164
cluster_stats_messages_ping_received:81
cluster_stats_messages_pong_received:83
cluster_stats_messages_received:164
cluster_disk_check_sucess:1
cluster_disk_check_time_ms_ago:219
[root@localhost src]#
主从复制
这里将3个实例分配了slots,剩余三个实例可以作为他们的slave,使用
cluster replicate masterNodeName
命令,其中masterNodeName
可以通过cluster nodes
命令来获取
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3000 cluster nodes
f10091eeec94edeb9eb1ce0829ce75b8444a1f19 10.150.5.19:3005@13005 master - 0 1747127957000 0 connected
6b8f37bdebc282993590cd1e23d351b6419eb242 10.150.5.19:3004@13004 master - 0 1747127959000 4 connected 10923-16383
37635ad0d847b010fb273832b2eb9ce0ffad549b 10.150.5.19:3003@13003 master - 0 1747127959832 3 connected
95a6a6c7a9389489efb126ffa36bb5a79c8570ea 10.150.5.19:3002@13002 master - 0 1747127958831 5 connected 5462-10922
8b24860e8a32ff44a4e0ad434e4848c284bbd4d2 10.150.5.19:3001@13001 master - 0 1747127957830 2 connected
4bd32c6e9adf85f0c586429b1670dd3e5cfb9d14 10.150.5.19:3000@13000 myself,master - 0 1747127958000 1 connected 0-5461
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3001 cluster replicate 4bd32c6e9adf85f0c586429b1670dd3e5cfb9d14
OK
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3003 cluster replicate 95a6a6c7a9389489efb126ffa36bb5a79c8570ea
OK
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3005 cluster replicate 6b8f37bdebc282993590cd1e23d351b6419eb242
OK
查看集群节点信息
三主三从的集群,可以通过
cluster nodes
查看slot归属以及主从同步情况
[root@localhost src]# ./redis-cli -h 10.150.5.19 -p 3000 cluster nodes
f10091eeec94edeb9eb1ce0829ce75b8444a1f19 10.150.5.19:3005@13005 slave 6b8f37bdebc282993590cd1e23d351b6419eb242 0 1747128037916 4 connected
6b8f37bdebc282993590cd1e23d351b6419eb242 10.150.5.19:3004@13004 master - 0 1747128038917 4 connected 10923-16383
37635ad0d847b010fb273832b2eb9ce0ffad549b 10.150.5.19:3003@13003 slave 95a6a6c7a9389489efb126ffa36bb5a79c8570ea 0 1747128037000 5 connected
95a6a6c7a9389489efb126ffa36bb5a79c8570ea 10.150.5.19:3002@13002 master - 0 1747128037000 5 connected 5462-10922
8b24860e8a32ff44a4e0ad434e4848c284bbd4d2 10.150.5.19:3001@13001 slave 4bd32c6e9adf85f0c586429b1670dd3e5cfb9d14 0 1747128037000 2 connected
4bd32c6e9adf85f0c586429
测试集群写入查询
[root@localhost src]# ./redis-cli -c -h 10.150.5.19 -p 3001
10.150.5.19:3001> set abc 123
-> Redirected to slot [7638] located at 10.150.5.19:3002
OK
10.150.5.19:3002> get abc
"123"
10.150.5.19:3002>