redis的四种模式部署应用

这里写目录标题

  • redis应用
      • redis单机部署
      • redis主从
      • redis哨兵
      • Cluster模式

redis应用

redis单机部署

关闭防火墙[root@zyq ~]#: yum -y install wget make gcc gcc-c++
......
[root@zyq ~]#: wget https://download.redis.io/redis-stable.tar.gz
--2024-01-01 19:41:14--  https://download.redis.io/redis-stable.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3477620 (3.3M) [application/octet-stream]
Saving to: ‘redis-stable.tar.gz’redis-stable.tar.gz         100%[===========================================>]   3.32M  3.61MB/s    in 0.9s    2024-01-01 19:41:15 (3.61 MB/s) - ‘redis-stable.tar.gz’ saved [3477620/3477620]
[root@zyq ~]#: ls
anaconda-ks.cfg  redis-stable.tar.gz
[root@zyq ~]#: tar xf redis-stable.tar.gz 
[root@zyq ~]#: ls
anaconda-ks.cfg  redis-stable  redis-stable.tar.gz
[root@zyq ~]#: cd redis-stable/
[root@zyq redis-stable]#: ls
00-RELEASENOTES     CONTRIBUTING.md  INSTALL    README.md   runtest-cluster    SECURITY.md    tests
BUGS                COPYING          Makefile   redis.conf  runtest-moduleapi  sentinel.conf  TLS.md
CODE_OF_CONDUCT.md  deps             MANIFESTO  runtest     runtest-sentinel   src            utils[root@zyq redis-stable]#: make
[root@zyq redis-stable]#: make install
cd src && make install
make[1]: Entering directory '/root/redis-stable/src'CC Makefile.depHint: It's a good idea to run 'make test' ;)INSTALL redis-serverINSTALL redis-benchmarkINSTALL redis-cli
make[1]: Leaving directory '/root/redis-stable/src'[root@zyq redis-stable]#: mkdir /etc/redis
[root@zyq redis-stable]#: cp redis.conf /etc/redis/
[root@zyq redis-stable]#: echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
[root@zyq redis-stable]#: cat /etc/sysctl.conf 
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.overcommit_memory = 1
[root@zyq redis-stable]#: echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@zyq redis-stable]#: cd[root@zyq ~]#: redis-server /etc/redis/redis.conf 
7862:C 01 Jan 2024 19:57:38.943 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7862:C 01 Jan 2024 19:57:38.943 * Redis version=7.2.3, bits=64, commit=00000000, modified=0, pid=7862, just started
7862:C 01 Jan 2024 19:57:38.943 * Configuration loaded
7862:M 01 Jan 2024 19:57:38.944 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7862:M 01 Jan 2024 19:57:38.944 * monotonic clock: POSIX clock_gettime_._                                                  _.-``__ ''-._                                             _.-``    `.  `_.  ''-._           Redis 7.2.3 (00000000/0) 64 bit.-`` .-```.  ```\/    _.,_ ''-._                                  (    '      ,       .-`  | `,    )     Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379|    `-._   `._    /     _.-'    |     PID: 7862`-._    `-._  `-./  _.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |           https://redis.io       `-._    `-._`-.__.-'_.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |                                  `-._    `-._`-.__.-'_.-'    _.-'                                   `-._    `-.__.-'    _.-'                                       `-._        _.-'                                           `-.__.-'                                               7862:M 01 Jan 2024 19:57:38.945 * Server initialized
7862:M 01 Jan 2024 19:57:38.945 * Ready to accept connections tcp[root@zyq ~]#: ss -antl
State       Recv-Q       Send-Q             Local Address:Port             Peer Address:Port      Process      
LISTEN      0            128                      0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0            511                    127.0.0.1:6379                  0.0.0.0:*                      
LISTEN      0            128                         [::]:22                       [::]:*                      
LISTEN      0            511                        [::1]:6379                     [::]:*                      
[root@zyq ~]#: redis-cli 
127.0.0.1:6379> 

使redis在后台运行需要修改配置文件/etc/redis/redis.conf,将daemonize值设为yes
默认情况下,redis连接是不需要经过认证的,而redis承载了企业大部分的请求流量,如果不经过认证很有可能在互联网上遭受攻击,所以需要在配置文件中为redis设置密码认证,且密码最好随机生成,保证没有规律可言。

[root@zyq ~]#: vim /etc/redis/redis.conf 
更改一下配置
bind 192.168.227.153 将127.0.0.1改为本机ip
daemonize yes  no改为yes
# requirepass foobared  取消这行注释
requirepass hhh123   或者添加自定义密码再重新启动
[root@zyq ~]#: redis-server /etc/redis/redis.conf 
[root@zyq ~]#: ss -antl
State       Recv-Q      Send-Q              Local Address:Port             Peer Address:Port      Process      
LISTEN      0           128                       0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           511               192.168.227.153:6379                  0.0.0.0:*                      
LISTEN      0           128                          [::]:22                       [::]:*                      
[root@zyq ~]#: redis-cli -h 192.168.227.153
192.168.227.153:6379> key *
(error) ERR unknown command 'key', with args beginning with: '*' 
192.168.227.153:6379> auth hhh123
OK

redis主从

[root@zyq ~]#: cd /etc/redis/
[root@zyq redis]#: ls
redis.conf
[root@zyq redis]#: mv redis.conf 6379.conf
[root@zyq redis]#: cp 6379.conf 6380.conf更改端口号port 6380
pidfile /var/run/redis_6380.pid
logfile "/var/log/redis6380.log"
replicaof 192.168.227.153 6379  在从上认主(由于使用一台虚拟机来配置,所以要修改端口号)
masterauth hhh123  设置密码[root@zyq redis]#: redis-server /etc/redis/6379.conf 
[root@zyq redis]#: redis-server /etc/redis/6380.conf 
[root@zyq redis]#: ss -antl
State       Recv-Q      Send-Q              Local Address:Port             Peer Address:Port      Process      
LISTEN      0           128                       0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           511               192.168.227.153:6379                  0.0.0.0:*                      
LISTEN      0           511               192.168.227.153:6380                  0.0.0.0:*                      
LISTEN      0           128                          [::]:22                       [::]:*                      
[root@zyq redis]#: ps -ef | grep redis
root        7967       1  0 20:14 ?        00:00:01 redis-server 192.168.227.153:6379
root        7978    1467  0 20:16 pts/0    00:00:00 vim /etc/redis/redis.conf
root        8012       1  0 20:30 ?        00:00:00 redis-server 192.168.227.153:6380
root        8030    7881  0 20:31 pts/1    00:00:00 grep --color=auto redis测试登录从库
[root@zyq ~]#: redis-cli -h 192.168.227.153 -p 6380
192.168.227.153:6380> auth hhh123
OK
192.168.227.153:6380> keys *
(empty array)
192.168.227.153:6380> 登录主库
[root@zyq redis]#: redis-cli -h 192.168.227.153 -p 6379
192.168.227.153:6379> auth hhh123
OK
192.168.227.153:6379> keys *
(empty array)
192.168.227.153:6379> 
在主库上添加
192.168.227.153:6379> set age 20
OK
192.168.227.153:6379> keys *
1) "age"在从库上给查看
192.168.227.153:6380> keys *
1) "age"查看从库信息
192.168.227.153:6380> info replication
# Replication
role:slave
master_host:192.168.227.153
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_read_repl_offset:571
slave_repl_offset:571
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:23aecbcf1431e181f485ef5cea33a424fc0c39d2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:571
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:557查看主库信息
192.168.227.153:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.227.153,port=6380,state=online,offset=655,lag=1
master_failover_state:no-failover
master_replid:23aecbcf1431e181f485ef5cea33a424fc0c39d2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:655
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:655

redis哨兵

在这里插入图片描述

删除上面配置的只从环境
[root@zyq redis]#: ls
6379.conf  6380.conf  dump.rdb
[root@zyq redis]#: rm -rf dump.rdb 
[root@zyq redis]#: rm -rf 6380.conf
[root@zyq redis]#: cd
[root@zyq ~]#: ls
anaconda-ks.cfg  dump.rdb  redis-stable  redis-stable.tar.gz
[root@zyq ~]#: rm -rf dump.rdb 配置三个主
[root@zyq redis]#: ls
6379.conf
[root@zyq redis]#: cp 6379.conf 6381.conf
[root@zyq redis]#: cp 6379.conf 6380.conf
[root@zyq redis]#: ls
6379.conf  6380.conf  6381.conf
[root@zyq redis]#: vim 6380.conf  638
2 files to edit
更改以下参数
port 6380
pidfile /var/run/redis_6380.pid
logfile "/var/log/redis6380.log"[root@zyq redis]#: vim 6381.conf
更改以下参数
port 6381
pidfile /var/run/redis_6381.pid
logfile "/var/log/redis6381.log"配置三个从
[root@zyq redis]#: cp 6379.conf 6389.conf
[root@zyq redis]#: cp 6380.conf 6390.conf
[root@zyq redis]#: cp 6381.conf 6391.conf[root@zyq redis]#: vim 6389.conf
pidfile /var/run/redis_6389.pid
logfile "/var/log/redis6389.log"
replicaof 192.168.227.153 6379  在从上认主(由于使用一台虚拟机来配置,所以要修改端口号)
masterauth hhh123  设置密码[root@zyq redis]#: vim 6390.conf
pidfile /var/run/redis_6390.pid
logfile "/var/log/redis6390.log"
replicaof 192.168.227.153 6380 [root@zyq redis]#: vim 6391.conf
pidfile /var/run/redis_6390.pid
logfile "/var/log/redis6390.log"
replicaof 192.168.227.153 6381配置哨兵
[root@zyq ~]#: cd redis-stable/
[root@zyq redis-stable]#: ls
00-RELEASENOTES     CONTRIBUTING.md  INSTALL    README.md   runtest-cluster    SECURITY.md    tests
BUGS                COPYING          Makefile   redis.conf  runtest-moduleapi  sentinel.conf  TLS.md
CODE_OF_CONDUCT.md  deps             MANIFESTO  runtest     runtest-sentinel   src            utils
[root@zyq redis-stable]#: cp sentinel.conf /etc/redis/
[root@zyq redis-stable]#: cd /etc/redis/
[root@zyq redis]#: ls
6379.conf  6380.conf  6381.conf  6389.conf  6390.conf  6391.conf  sentinel.conf
[root@zyq redis]#: vi /etc/redis/sentinel.conf
添加以下配置
sentinel monitor mymaster 192.168.227.153 6379 2
sentinel monitor mymaster 192.168.227.153 6380 2
sentinel monitor mymaster 192.168.227.153 6381 2sentinel monitor myslave 192.168.227.153 6389 2
sentinel monitor myslave 192.168.227.153 6390 2
sentinel monitor myslave 192.168.227.153 6391 2sentinel auth-pass mymaster1 hhh123
sentinel auth-pass mymaster2 hhh123
sentinel auth-pass mymaster3 hhh123sentinel auth-pass myslave1 hhh123
sentinel auth-pass myslave2 hhh123
sentinel auth-pass myslave3 hhh123配置3个哨兵配置文件
更改名字好区分
[root@zyq redis]#: ls
6379.conf  6380.conf  6381.conf  6389.conf  6390.conf  6391.conf  sentinel.conf
[root@zyq redis]#: mv sentinel.conf 26380.conf
修改添加
port 26380
.....
pidfile /var/run/redis-sentinel2.pid
......
sentinel down-after-milliseconds mymaster1 30000
sentinel down-after-milliseconds mymaster2 30000
sentinel down-after-milliseconds mymaster3 30000sentinel down-after-milliseconds myslave1 30000
sentinel down-after-milliseconds myslave2 30000
sentinel down-after-milliseconds myslave3 30000
......
sentinel parallel-syncs mymaster1 1
sentinel parallel-syncs mymaster2 1
sentinel parallel-syncs mymaster3 1sentinel parallel-syncs myslave1 1
sentinel parallel-syncs myslave2 1
sentinel parallel-syncs myslave3 1
......
sentinel failover-timeout mymaster1 180000
sentinel failover-timeout mymaster2 180000
sentinel failover-timeout mymaster3 180000sentinel failover-timeout myslave1 180000
sentinel failover-timeout myslave2 180000
sentinel failover-timeout myslave3 180000
......
SENTINEL master-reboot-down-after-period mymaster1 0
SENTINEL master-reboot-down-after-period mymaster2 0
SENTINEL master-reboot-down-after-period mymaster3 0SENTINEL master-reboot-down-after-period myslave1 0
SENTINEL master-reboot-down-after-period myslave2 0
SENTINEL master-reboot-down-after-period myslave3 0[root@zyq redis]#: cp 26380.conf  26379.conf
[root@zyq redis]#: vim 26379.conf
port 26379
.....
pidfile /var/run/redis-sentinel1.pid
.....[root@zyq redis]#: cp 26380.conf  26381.conf
[root@zyq redis]#: vim 26381.conf
port 26381
.....
pidfile /var/run/redis-sentinel3.pid
......启动并查看哨兵
[root@zyq redis]#: redis-sentinel  26379.conf
[root@zyq redis]#: redis-sentinel  26380.conf 
[root@zyq redis]#: redis-sentinel  26381.conf 
[root@zyq redis]#: ps -ef|grep redis
root        8115    1467  0 21:23 pts/0    00:00:00 /usr/bin/vim /etc/redis/sentinel.conf
root        8141       1  0 21:43 ?        00:00:00 redis-sentinel *:26379 [sentinel]
root        8150       1  0 21:43 ?        00:00:00 redis-sentinel *:26380 [sentinel]
root        8156       1  0 21:43 ?        00:00:00 redis-sentinel *:26381 [sentinel]
root        8162    7881  0 21:43 pts/1    00:00:00 grep --color=auto redis启动主从
[root@zyq redis]#: redis-server 6379.conf
[root@zyq redis]#: redis-server 6380.conf
[root@zyq redis]#: redis-server 6381.conf
[root@zyq redis]#: redis-server 6389.conf
[root@zyq redis]#: redis-server 6390.conf
[root@zyq redis]#: redis-server 6391.conf
[root@zyq redis]#: ps -ef|grep redis
root        8115    1467  0 21:23 pts/0    00:00:00 /usr/bin/vim /etc/redis/sentinel.conf
root        8141       1  0 21:43 ?        00:00:00 redis-sentinel *:26379 [sentinel]
root        8150       1  0 21:43 ?        00:00:00 redis-sentinel *:26380 [sentinel]
root        8156       1  0 21:43 ?        00:00:00 redis-sentinel *:26381 [sentinel]
root        8202       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6379
root        8211       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6380
root        8217       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6381
root        8223       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6389
root        8229       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6390
root        8237       1  0 21:47 ?        00:00:00 redis-server 192.168.227.153:6391
root        8246    7881  0 21:47 pts/1    00:00:00 grep --color=auto redis这时是3个哨兵监控3个主和从

在sentinel集群环境下需要多个sentinel互相沟通来确认某个master是否真的死了,quorum这个参数是进行客观下线的一个依据,意思是至少有quorum个sentinel认为这个master有故障,才会对这个master进行下线以及故障转移。因为有的时候,某个sentinel节点可能因为自身网络原因,导致无法连接master,而此时master并没有出现故障,所以,这就需要多个sentinel都一致认为该master有问题,才可以进行下一步操作,这就保证了公平性和高可用。

Cluster模式

主从模式或哨兵模式每个节点存储的数据都是全量的数据,数据量过大时,就需要对存储的数据进行分片后存储到多个redis实例上。此时就要用到Redis Sharding技术。

redis在3.0上加入了 Cluster 集群模式,实现了 Redis 的分布式存储,也就是说每台 Redis 节点上存储不同的数据。cluster模式为了解决单机Redis容量有限的问题,将数据按一定的规则分配到多台机器,内存/QPS不受限于单机,可受益于分布式集群高扩展性。

Redis Cluster是一种服务器Sharding技术(分片和路由都是在服务端实现),采用多主多从,每一个分区都是由一个Redis主机和多个从机组成,片区和片区之间是相互平行的。Redis Cluster集群采用了P2P的模式,完全去中心化

[root@zyq ~]#: ss -antl
State       Recv-Q      Send-Q             Local Address:Port             Peer Address:Port      Process      
LISTEN      0           128                      0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           128                         [::]:22                       [::]:*  
[root@zyq ~]#: cd /etc/redis/
[root@zyq redis]#: ls
6379.conf  6380.conf  6381.conf  6389.conf  6390.conf  6391.conf [root@zyq redis]#: vim /usr/bin/redis-daemon
[root@zyq redis]#: cat /usr/bin/redis-daemon 
#!/bin/bash/usr/local/bin/redis-server /etc/redis/6379.conf
/usr/local/bin/redis-server /etc/redis/6380.conf
/usr/local/bin/redis-server /etc/redis/6381.conf
/usr/local/bin/redis-server /etc/redis/6389.conf
/usr/local/bin/redis-server /etc/redis/6390.conf
/usr/local/bin/redis-server /etc/redis/6391.conf
[root@zyq redis]#: chmod +x /usr/bin/redis-daemon
[root@zyq redis]#: ll /usr/bin/redis-daemon 
-rwxr-xr-x 1 root root 307 Jan  2 15:35 /usr/bin/redis-daemon[root@zyq redis]#: ss -antl
State       Recv-Q      Send-Q             Local Address:Port             Peer Address:Port      Process      
LISTEN      0           511              192.168.227.153:6379                  0.0.0.0:*                      
LISTEN      0           511              192.168.227.153:6380                  0.0.0.0:*                      
LISTEN      0           511              192.168.227.153:6381                  0.0.0.0:*                      
LISTEN      0           511              192.168.227.153:6389                  0.0.0.0:*                      
LISTEN      0           511              192.168.227.153:6390                  0.0.0.0:*                      
LISTEN      0           128                      0.0.0.0:22                    0.0.0.0:*                      
LISTEN      0           511              192.168.227.153:6391                  0.0.0.0:*                      
LISTEN      0           128                         [::]:22                       [::]:*                      
设置开机自启
[root@zyq redis]#: cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/redis.service
[root@zyq redis]#: vim /usr/lib/systemd/system/redis.service
[root@zyq redis]#: cat  /usr/lib/systemd/system/redis.service
[Unit]
Description=redis replication server daemon
After=network.target [Service]
Type=forking
ExecStart=/usr/bin/redis-daemon
ExecStop=/usr/bin/pkill redis 
ExecReload=/bin/kill -HUP $MAINPID[Install]
WantedBy=multi-user.target
[root@zyq redis]#: systemctl daemon-reload 
[root@zyq redis]#: systemctl enable --now redis.service 
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.[root@zyq ~]#: cd redis-stable
[root@zyq redis-stable]#: ls
00-RELEASENOTES     CONTRIBUTING.md  INSTALL    README.md   runtest-cluster    SECURITY.md    tests
BUGS                COPYING          Makefile   redis.conf  runtest-moduleapi  sentinel.conf  TLS.md
CODE_OF_CONDUCT.md  deps             MANIFESTO  runtest     runtest-sentinel   src            utils
[root@zyq redis-stable]#: cp redis.conf /etc/redis/
[root@zyq redis]#: mv redis.conf 6379.修改配置文件
[root@zyq redis]#: vim 6379.conf 
取消注释
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes  no改为yes
daemonize yes  no改为yes
logfile "/var/log/redis6379.log"[root@zyq redis]#: cp 6379.conf 6380.conf
[root@zyq redis]#: cp 6379.conf 6381.conf
[root@zyq redis]#: cp 6379.conf 6389.conf
[root@zyq redis]#: cp 6379.conf 6390.conf
[root@zyq redis]#: cp 6379.conf 6391.conf[root@zyq redis]#: sed -i 's/6379/6380/g' 6380.conf 
[root@zyq redis]#: sed -i 's/6379/6381/g' 6381.conf 
[root@zyq redis]#: sed -i 's/6379/6389/g' 6389.conf 
[root@zyq redis]#: sed -i 's/6379/6390/g' 6390.conf 
[root@zyq redis]#: sed -i 's/6379/6391/g' 6391.conf重启redis服务
[root@zyq redis]#: systemctl daemon-reload 
[root@zyq redis]#: systemctl restart redis.service 启动cluster模式
[root@zyq redis-stable]#: redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6389 127.0.0.1:6390 127.0.0.1:6391 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:6390 to 127.0.0.1:6379
Adding replica 127.0.0.1:6391 to 127.0.0.1:6380
Adding replica 127.0.0.1:6389 to 127.0.0.1:6381
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 80daef8a00d8d95d123d807f8ea21ccb9f188cb7 127.0.0.1:6379slots:[0-5460] (5461 slots) master
M: 3ec104631e7087b99b25311d40935deb6a9c163a 127.0.0.1:6380slots:[5461-10922] (5462 slots) master
M: 96a64c539a0b801746cb1f8f6426c085786e5485 127.0.0.1:6381slots:[10923-16383] (5461 slots) master
S: a4f77673a5f853a393272af74f3408dccca626e2 127.0.0.1:6389replicates 96a64c539a0b801746cb1f8f6426c085786e5485
S: de7f8a76c211788fbe5f4f1c44e3d4fb83c742dd 127.0.0.1:6390replicates 80daef8a00d8d95d123d807f8ea21ccb9f188cb7
S: c1cef4cdee9cd641825793b39ede45d33faa3f22 127.0.0.1:6391replicates 3ec104631e7087b99b25311d40935deb6a9c163a
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: 80daef8a00d8d95d123d807f8ea21ccb9f188cb7 127.0.0.1:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: de7f8a76c211788fbe5f4f1c44e3d4fb83c742dd 127.0.0.1:6390slots: (0 slots) slavereplicates 80daef8a00d8d95d123d807f8ea21ccb9f188cb7
S: c1cef4cdee9cd641825793b39ede45d33faa3f22 127.0.0.1:6391slots: (0 slots) slavereplicates 3ec104631e7087b99b25311d40935deb6a9c163a
M: 96a64c539a0b801746cb1f8f6426c085786e5485 127.0.0.1:6381slots:[10923-16383] (5461 slots) master1 additional replica(s)
M: 3ec104631e7087b99b25311d40935deb6a9c163a 127.0.0.1:6380slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: a4f77673a5f853a393272af74f3408dccca626e2 127.0.0.1:6389slots: (0 slots) slavereplicates 96a64c539a0b801746cb1f8f6426c085786e5485
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.测试主从效果
[root@zyq ~]#: redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set age 20
OK[root@zyq ~]#: redis-cli -h 127.0.0.1 -p 6390
127.0.0.1:6390> keys *
1) "age"[root@zyq ~]#: yum -y install ruby
[root@zyq ~]#: vim example.rb 
[root@zyq ~]#: cat example.rb 
require './cluster'if ARGV.length != 2startup_nodes = [{:host => "127.0.0.1", :port => 6379},{:host => "127.0.0.1", :port => 6380}]elsestartup_nodes = [{:host => ARGV[0], :port => ARGV[1].to_i}]endrc = RedisCluster.new(startup_nodes,32,:timeout => 0.1)last = falsewhile not lastbeginlast = rc.get("__last__")last = 0 if !lastrescue => eputs "error #{e.to_s}"sleep 1endend((last.to_i+1)..1000000000).each{|x|beginrc.set("foo#{x}",x)puts rc.get("foo#{x}")rc.set("__last__",x)rescue => eputs "error #{e.to_s}"endsleep 0.1}测试集群模式效果(要加上‘-c’)可修改不同节点的事务且不会重复
[root@zyq ~]#: redis-cli -h 127.0.0.1 -p 6379 -c
127.0.0.1:6379> keys *
1) "age"[root@zyq ~]#: redis-cli -h 127.0.0.1 -p 6380 -c
127.0.0.1:6380> get age
-> Redirected to slot [741] located at 127.0.0.1:6379
"20"

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/27626.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

TypeScript 进阶,深入理解并运用索引访问类型提升代码质量

欢迎回来继续我们的“TypeScript进阶技巧”系列。上次我们深入探讨了如何使用Extract和Exclude实用类型来优化TypeScript的类型处理( 《如何利用 TypeScript 的 Extract 提升类型定义与代码清晰度》和 《如何利用 TypeScript 的 Exclude 提升状态管理与代码健壮性》…

论文阅读笔记:Cross-Image Relational Knowledge Distillation for Semantic Segmentation

论文阅读笔记:Cross-Image Relational Knowledge Distillation for Semantic Segmentation 1 背景2 创新点3 方法4 模块4.1 预备知识4.2 跨图像关系知识蒸馏4.3 Memory-based像素到像素蒸馏4.4 Memory-based像素到区域蒸馏4.5 整体框架 5 效果 论文:http…

Redis和Docker

Redis 和 Docker 是两种不同的技术,它们各自解决不同的问题,但有时会一起使用以提供更高效和灵活的解决方案。 Redis 是一个开源的内存数据结构存储系统,可以用作数据库、缓存和消息代理。它设计为解决MySQL等关系型数据库在处理大量读写访问…

MySQL数据操作与查询-T5 MySQL函数

一、数学函数和控制流函数 1、数学函数 (1)abs(x) 计算x的绝对值。 1 select abs(‐5.5),abs(10) (2)pow(x,y) 计算x的y次方的值。 1 select pow(2,8),pow(8,2) (3)round(x) 和 round(x,y) 对数字x进…

php遇到的问题

1、 underfined at line 3 in xxx.php , 错误提示,注释这行代码 // error_reporting(DEBUG ? E_ALL : 0); 目录:config/config.php

Ubuntu20.04部署Qwen2.openvino流程

下载代码 里面包含依赖 git clone https://github.com/OpenVINO-dev-contest/Qwen2.openvino.gitpython环境配置 创建虚拟环境 conda create -name qwen2openvino python3.10 conda activate qwen2openvino安装依赖 pip install wheel setuptools pip install -r requirem…

CCAA质量管理【学习笔记】​​ 备考知识点笔记(二)

第三节 GB/T19001-2016 标准正文 本节为ISO9001:2015 标准条款的正文内容,各条款中的术语参照上节内容理解时,会很轻松。本节不再一一对各条款讲解。 引 言 0.1 总 则 采用质量管理体系是组织的一项战略决策,能够帮助其提高整体绩效…

这个网站有点意思,可做SPRINGBOOT的启动图

在 SpringBoot 项目的 resources 目录下新建一个 banner.txt 文本文件,然后将启动 Banner 粘贴到此文本文件中,启动项目,即可在控制台展示对应的内容信息。 下面这个工具很好用,收藏精哦

PFA 反应罐内衬特氟龙 润滑绝缘行业加工 匠心工艺

PFA反应罐别名也叫反应瓶,储样罐,清洗罐等。可作为样品前处理实验中消解样品和中低压溶样的反应容器,广泛应用于半导体分析、新材料、新能源、同位素分析等。 PFA反应罐规格参考:250ml、300ml、350ml、500ml、1L等。 产品特点&…

官网首屏:太漂亮了,真是着了它的魔,上了它的道。

大气的企业官网致力于提供用户友好的界面和优质的用户体验。网页经过精心设计和开发,旨在展示客户的品牌形象和产品信息,并为用户提供便捷的服务和沟通渠道。 官网设计追求简洁、美观、易用的原则,以吸引用户的注意力并提供清晰的导航和信息…

手机丢失不惊慌,华为手机已升级至楼层级设备查找!

出门总是丢三落四,手机丢了怎么办?不要怕,只要你的华为手机升级至云空间新版本,就可以进行楼层级设备查找,现在可以查看到具体的楼层了! 之前有手机丢失过的朋友,肯定有相似的经历&#xff0c…

【会议征稿,ACM出版】2024年云计算与大数据国际学术会议(ICCBD 2024,7月26-28)

2024年云计算与大数据国际学术会议(ICCBD 2024)将于2024年7月26-28日在中国大理召开。ICCBD 2024将围绕“云计算与大数据”的最新研究领域, 旨在为从事研究的专家、学者、工程师和技术人员提供一个国际平台,分享科研成果和尖端技术,了解学术发展趋势&…

Windows安装配置CUDA12.5

搞大模型往往都需要GPU加速,本次在家里的PC上安装CUDA来实现GPU加速。 一、环境准备 操作系统:Windows11 23H2 GPU:RTX 4070 Ti Super 显卡驱动:555.99 (NVIDIA GeForce 驱动程序 - N 卡驱动 | NVIDIA) …

基于JSP技术的定西扶贫惠农推介系统

开头语:你好呀,我是计算机学长猫哥!如果有相关需求,文末可以找到我的联系方式。 开发语言:JSP 数据库:MySQL 技术:B/S架构、JSP技术 工具:Eclipse、MySQL、Tomcat 系统展示 首…

【python】OpenCV—Background Estimation(15)

文章目录 中值滤波中值滤波得到图像背景移动侦测 学习来自 OpenCV基础(14)OpenCV在视频中的简单背景估计 中值滤波 中值滤波是一种非线性平滑技术,主要用于数字信号处理,特别是在图像处理中去除噪声。 一、定义与原理 定义&am…

大模型日报2024-06-14

大模型日报 2024-06-14 大模型资讯 Meta发布Llama 3并专注大规模语言模型研发 摘要: Meta于2024年4月发布了开源的大规模语言模型Llama 3,并详细解释了他们在训练这些模型时关注的重点和方法。Meta目前正专注于大规模语言模型的进一步发展。 微软研究人员推出VALL-E…

log4j漏洞学习

log4j漏洞学习 总结基础知识属性占位符之Interpolator(插值器)模式布局日志级别 Jndi RCE CVE-2021-44228环境搭建漏洞复现代码分析日志记录/触发点消息格式化 Lookup 处理JNDI 查询触发条件敏感数据带外漏洞修复MessagePatternConverter类JndiManager#l…

论文阅读笔记:DepGraph: Towards Any Structural Pruning

论文阅读笔记:DepGraph: Towards Any Structural Pruning 1 背景2 创新点3 方法4 模块4.1 分组4.2 依赖图4.3 网络分解4.4 依赖建模4.4 组级剪枝 5 效果 论文:https://arxiv.org/pdf/2301.12900 代码:https://github.com/VainF/Torch-Prunin…

LDR6020显示器应用:革新连接体验,引领未来显示技术

一、引言 随着科技的飞速发展,显示器作为信息展示的重要载体,其性能和应用场景不断得到拓展。特别是在办公、娱乐以及物联网等领域,用户对显示器的需求越来越多样化。在这一背景下,LDR6020显示器的出现,以其卓越的性能…

opencv_GUI

图像入门 import numpy as np import cv2 as cv # 用灰度模式加载图像 img cv.imread(C:/Users/HP/Downloads/basketball.png, 0)# 即使图像路径错误,它也不会抛出任何错误,但是打印 img会给你Nonecv.imshow(image, img) cv.waitKey(5000) # 一个键盘绑…