root@ubuntu18-server:~# tar xvf redis7InstallScript.tar.gz root@ubuntu18-server:~# cd redis7InstallScript/ root@ubuntu18-server:~/redis7InstallScript# ls redis-7.2.0_install.sh redis-7.2.0.tar.gz redis.conf root@ubuntu18-server:~/redis7InstallScript# bash redis-7.2.0_install.sh
# 查看集群功能是否开启 root@ubuntu18-server:~# redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 127.0.0.1:6379> info cluster # Cluster cluster_enabled:1
root@ubuntu18-server:~# redis-cli --cluster help Cluster Manager Commands: create host1:port1 ... hostN:portN # 创建集群并执行节点数 --cluster-replicas <arg> # 指定master的副本数量 check <host:port> or <host> <port> - separated by either colon or space --cluster-search-multiple-owners # 检查是否有槽位被分配给了多个节点 info <host:port> or <host> <port> - separated by either colon or space # 查看集群主机信息 fix <host:port> or <host> <port> - separated by either colon or space # 修复集群 --cluster-search-multiple-owners # 修复槽位被同时分配给多个节点的问题 --cluster-fix-with-unreachable-masters # 修复不可达主机 reshard <host:port> or <host> <port> - separated by either colon or space # 手动热迁移集群指定主机的slots数据到新的目的主机 --cluster-from <arg> --cluster-to <arg> --cluster-slots <arg> --cluster-yes --cluster-timeout <arg> --cluster-pipeline <arg> --cluster-replace rebalance <host:port> or <host> <port> - separated by either colon or space # 如果各master的slot槽位差异很大,可以使用rebalance实现自动平衡集群中各主机的slot数量 --cluster-weight <node1=w1...nodeN=wN> --cluster-use-empty-masters --cluster-timeout <arg> --cluster-simulate --cluster-pipeline <arg> --cluster-threshold <arg> --cluster-replace add-node new_host:new_port existing_host:existing_port # 添加节点到集群 --cluster-slave --cluster-master-id <arg> del-node host:port node_id # 从集群删除主机 call host:port command arg arg .. arg # 在集群的所有节点上执行命令 --cluster-only-masters --cluster-only-replicas set-timeout host:port milliseconds # 设置节点的超时时间 import host:port # 将外部redis服务器的数据导入当前集群 --cluster-from <arg> --cluster-from-user <arg> --cluster-from-pass <arg> --cluster-from-askpass --cluster-copy --cluster-replace backup host:port backup_directory # 备份集群数据 help
For check, fix, reshard, del-node, set-timeout, info, rebalance, call, import, backup you can specify the host and port of any working node in the cluster.
Cluster Manager Options: --cluster-yes Automatic yes to cluster commands prompts
root@ubuntu18-server:~# redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # 主从状态信息 127.0.0.1:6379> info replication # Replication role:master connected_slaves:1 slave0:ip=192.168.119.165,port=6379,state=online,offset=714,lag=1 master_failover_state:no-failover master_replid:851739edde74e60519b830540c5299448a589c2d master_replid2:0000000000000000000000000000000000000000 master_repl_offset:728 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:536870912 repl_backlog_first_byte_offset:1 repl_backlog_histlen:728
# 查看每个节点分配了多少key(主从复制,故总共200个) root@ubuntu18-server:~# redis-cli -a 123456 --cluster call 192.168.119.161:6379 DBSIZE Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Calling DBSIZE 192.168.119.161:6379: 32 192.168.119.162:6379: 32 192.168.119.163:6379: 36 192.168.119.166:6379: 32 192.168.119.165:6379: 32 192.168.119.164:6379: 36
# Redis 服务已安装完成 ● redis-server.service - Redis data structure server Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2024-03-13 01:38:08 UTC; 4h 35min ago Docs: https://redis.io/documentation Main PID: 1005 (redis-server) Status: "Ready to accept connections" Tasks: 5 (limit: 4623) CGroup: /system.slice/redis-server.service └─1005 /apps/redis/bin/redis-server 0.0.0.0:6379
Mar 13 01:38:08 ubuntu18-server7 systemd[1]: Starting Redis data structure server... Mar 13 01:38:08 ubuntu18-server7 systemd[1]: Started Redis data structure server.
# 写入一个数据 root@ubuntu18-server7:~# redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 127.0.0.1:6379> set name Jerry OK