Redis 集群安装-Centos

news2024/11/21 1:47:37

Redis 集群安装-Centos

Redis3.0以后的版本虽然有了集群功能,提供了比之前版本的哨兵模式更高的性能与可用性,但是集群的水平扩展却比较麻烦,今天就来带大家看看redis高可用集群如何做水平扩展,原始集群(见下图)由6个节点组成,6个节点分布在三台机器上,采用三主三从的模式

Redis Cluster要求至少需要3个master才能组成一个集群,同时每个master至少需要有一个slave节点。各个节点之间保持TCP通信。当master发生了宕机, Redis Cluster自动会将对应的slave节点提拔为master,来重新对外提供服务。
Redis Cluster 功能 : 负载均衡,故障切换,主从复制。

依然使用一台机器演示部署

下载安装Redis

$ wget http://download.redis.io/releases/redis-5.0.4.tar.gz
$ tar -xzvf redis-5.0.4.tar.gz -C /usr/local  
$ cd redis-5.0.4
# 官网示例是使用 `make`,它会将其安装到当前目录的src目录下。
# 将`make`替换成`make install PREFIX=/usr/local/redis`,将其安装到指定目录,记得将配置文件进行拷贝过去
$ make install PREFIX=/usr/local/redis

因为Redis是使用C语言编写的,所以需要提前安装gcc:yum install gcc -y

创建目录

因为在一台机器上,所以创建6个文件夹来做隔离。
master:8001,8002,8003
slave:8004,8005,8006

$ mkdir -p /usr/local/redis-cluster/8001 /usr/local/redis-cluster/8002 /usr/local/redis-cluster/8003 /usr/local/redis-cluster/8004 /usr/local/redis-cluster/8005 /usr/local/redis-cluster/8006

创建配置文件

8001

$ vim /usr/local/redis-cluster/8001/redis.conf

配置文件内容如下:

port 8001
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8001/redis.pid
logfile /usr/local/redis-cluster/8001/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8001
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8001.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8002

$ vim /usr/local/redis-cluster/8002/redis.conf

配置文件内容如下:

port 8002
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8002/redis.pid
logfile /usr/local/redis-cluster/8002/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8002
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8002.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8003

$ vim /usr/local/redis-cluster/8003/redis.conf

配置文件内容如下:

port 8003
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8003/redis.pid
logfile /usr/local/redis-cluster/8003/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8003
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8003.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8004

$ vim /usr/local/redis-cluster/8004/redis.conf

配置文件内容如下:

port 8004
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8004/redis.pid
logfile /usr/local/redis-cluster/8004/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8004
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8004.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8005

$ vim /usr/local/redis-cluster/8005/redis.conf

配置文件内容如下:

port 8005
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8005/redis.pid
logfile /usr/local/redis-cluster/8005/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8005
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8005.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8006

$ vim /usr/local/redis-cluster/8006/redis.conf

配置文件内容如下:

port 8006
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8006/redis.pid
logfile /usr/local/redis-cluster/8006/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8006
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8006.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

创建集群

如果是多台机器上运行,请关闭防火墙。

  1. 启动redis实例
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8001/redis.conf 
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8002/redis.conf 
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8003/redis.conf 
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8004/redis.conf 
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8005/redis.conf 
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8006/redis.conf 
  1. 查看启动状态:
$ ps -ef | grep redis
root       7769      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8001 [cluster]
root       8052      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8002 [cluster]
root       8803      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8003 [cluster]
root       9045      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8004 [cluster]
root       9626      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8005 [cluster]
root       9970      1  0 02:15 ?        00:00:00 /usr/local/redis/bin/redis-server *:8006 [cluster]
  1. 创建Redis集群:

    --cluster-replicas 1 指定集群中从节点个数为1,后面紧跟所有节点。

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster create --cluster-replicas 1 192.168.0.138:8001 192.168.0.138:8002 192.168.0.138:8003 192.168.0.138:8004 192.168.0.138:8005 192.168.0.138:8006
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.0.138:8005 to 192.168.0.138:8001
Adding replica 192.168.0.138:8006 to 192.168.0.138:8002
Adding replica 192.168.0.138:8004 to 192.168.0.138:8003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[0-5460] (5461 slots) master
M: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots:[5461-10922] (5462 slots) master
M: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots:[10923-16383] (5461 slots) master
S: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   replicates 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1
S: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   replicates bab2c897f42a3e05af40d9f4d8abd0ae65beb34d
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
# 是否使用上述进行配置
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 192.168.0.138:8001)
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   slots: (0 slots) slave
   replicates bab2c897f42a3e05af40d9f4d8abd0ae65beb34d
S: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   slots: (0 slots) slave
   replicates 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   slots: (0 slots) slave
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
M: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

根据上面的信息,我们可以看到8001、8002、8003分别是8006、8004、8005的主节点。3个主节点平分了slot(2^14=16384)

  1. 查看集群信息
$ /usr/local/redis/bin/redis-cli -c -p 8001 -a soft01
127.0.0.1:8001> cluster info
cluster_state:ok                      # 集群状态正常
cluster_slots_assigned:16384          # 已分配16384 slots
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6                 # 集群的节点数
cluster_size:3                        # 集群主节点数
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:379
cluster_stats_messages_pong_sent:388
cluster_stats_messages_sent:767
cluster_stats_messages_ping_received:383
cluster_stats_messages_pong_received:379
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:767
127.0.0.1:8001> cluster nodes
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 master - 0 1666258121038 2 connected 5461-10922                             # 8002主节点     
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 slave bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 0 1666258120000 5 connected  # 8005是8003的从节点
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 slave 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 0 1666258119000 4 connected  # 8004是8002的从节点
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666258120000 6 connected  # 8006是8001的从节点
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666258119000 1 connected 0-5460                          # 8001主节点
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 master - 0 1666258120028 3 connected 10923-16383                            # 8003主节点

关闭集群

关闭集群需要一个一个关闭

/usr/local/redis/bin/redis-cli -c -p 8001 -a soft01 shutdown

如果关闭一个master节点后,集群內部会将它的从节点提升成主节点。当该节点再启动时,会自动变为从节点。

新增节点

向上面搭建好的集群添加节点

创建8007、8008目录

$ mkdir -p /usr/local/redis-cluster/8007 /usr/local/redis-cluster/8008

8007

编辑8007的配置文件

$ vim /usr/local/redis-cluster/8007/redis.conf

配置文件内容如下:

port 8007
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8007/redis.pid
logfile /usr/local/redis-cluster/8007/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8007
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8007.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

8008

编辑8008的配置文件

$ vim /usr/local/redis-cluster/8008/redis.conf

配置文件内容如下:

port 8008
daemonize yes
protected-mode no
pidfile /usr/local/redis-cluster/8008/redis.pid
logfile /usr/local/redis-cluster/8008/redis.log
requirepass soft01
masterauth soft01
databases 16
timeout 300

# rdb aof
save 900 1
save 300 10
save 60 10000
dir /usr/local/redis-cluster/8008
dbfilename dump.rdb
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
auto-AOF-rewrite-percentage 100
auto-AOF-rewrite-min-size 64mb
aof-use-rdb-preamble yes

# cluster
# 启动集群
cluster-enabled yes
# 生成的集群节点配置文件名
cluster-config-file nodes-8008.conf
# 集群节点回应最长时间,超过该时间被认为下线
cluster-node-timeout 10000

启动8007,8008

启动8007、8008节点

$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8007/redis.conf
$ /usr/local/redis/bin/redis-server /usr/local/redis-cluster/8008/redis.conf

查看节点运行情况

$ ps -ef | grep redis
root       8052      1  0 10月20 ?      00:02:41 /usr/local/redis/bin/redis-server *:8002 [cluster]
root       8803      1  0 10月20 ?      00:02:42 /usr/local/redis/bin/redis-server *:8003 [cluster]
root       9045      1  0 10月20 ?      00:02:42 /usr/local/redis/bin/redis-server *:8004 [cluster]
root       9626      1  0 10月20 ?      00:02:44 /usr/local/redis/bin/redis-server *:8005 [cluster]
root       9970      1  0 10月20 ?      00:02:43 /usr/local/redis/bin/redis-server *:8006 [cluster]
root      91738      1  0 00:32 ?        00:00:00 /usr/local/redis/bin/redis-server *:8007 [cluster]
root      92180      1  0 00:32 ?        00:00:00 /usr/local/redis/bin/redis-server *:8008 [cluster]
root     103952      1  0 10月20 ?      00:02:42 /usr/local/redis/bin/redis-server *:8001 [cluster]

将8007,8008添加到集群

cluster 帮助文档

$ /usr/local/redis/bin/redis-cli --cluster help
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN # 创建集群
                 --cluster-replicas <arg>	 #从节点个数
  check          host:port #检查集群
                 --cluster-search-multiple-owners #检查是否有槽同时被分配给了多个节点
  info           host:port #查看集群状态
  fix            host:port #修复集群
                 --cluster-search-multiple-owners #修复槽的重复分配问题
  reshard        host:port #指定集群的任意一节点进行迁移slot,重新分
                 --cluster-from <arg> #需要从哪些源节点上迁移slot,可从多个源节点完成迁移,以逗号隔开,传递的是节点的node id,还可以直接传递--from all,这样源节点就是集群的所有节点,不传递该参数的话,则会在迁移过程中提示用户输入
                 --cluster-to <arg> #slot需要迁移的目的节点的node id,目的节点只能填写一个,不传递该参数的话,则会在迁移过程中提示用户输入
                 --cluster-slots <arg>  #需要迁移的slot数量,不传递该参数的话,则会在迁移过程中提示用户输入。
                 --cluster-yes #指定迁移时的确认输入
                 --cluster-timeout <arg> #设置migrate命令的超时时间
                 --cluster-pipeline <arg> #定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10
                 --cluster-replace  #是否直接replace到目标节点
  rebalance      host:port #指定集群的任意一节点进行平衡集群节点slot数量
                 --cluster-weight <node1=w1...nodeN=wN> #指定集群节点的权重
                 --cluster-use-empty-masters #设置可以让没有分配slot的主节点参与,默认不允许
                 --cluster-timeout <arg> #设置migrate命令的超时时间
                 --cluster-simulate  #模拟rebalance操作,不会真正执行迁移操作
                 --cluster-pipeline <arg>  #定义cluster getkeysinslot命令一次取出的key数量,默认值为10
                 --cluster-threshold <arg>  #迁移的slot阈值超过threshold,执行rebalance操作
                 --cluster-replace  #是否直接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 #在集群的所有节点执行相关命令
  set-timeout    host:port milliseconds  #设置cluster-node-timeout
  import         host:port #将外部redis数据导入集群
                 --cluster-from <arg> #将指定实例的数据导入到集群
                 --cluster-copy #migrate时指定copy
                 --cluster-replace #migrate时指定replace
  help           

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

create:创建一个集群环境host1:port1 … hostN:portN
add-node:将一个节点添加到集群里,第一个参数为新节点的ip:port,第二个参数为集群中任意一个已经存在的节点的ip:port
del-node:移除一个节点
reshard:重新分片
check:检查集群状态

8007加入集群(Master)

192.168.0.138:8007为本次添加的节点,192.168.0.138:8001 为集群中正在运行的节点

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster add-node 192.168.0.138:8007 192.168.0.138:8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.0.138:8007 to cluster 192.168.0.138:8001
>>> Performing Cluster Check (using node 192.168.0.138:8001)
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots: (0 slots) slave
   replicates 44e2ec56944a0d9760b7180d7aebbc97b1fb495f
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   slots: (0 slots) slave
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
M: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots: (0 slots) slave
   replicates 5aaf267e75753a20b9b5a43273e68accb10571f5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.0.138:8007 to make it join the cluster.
[OK] New node added correctly.

查看集群状态:

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666338116089 9 connected 5461-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666338118126 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666338117111 10 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666338116000 10 connected 0-5460
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666338117000 8 connected 10923-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666338116000 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666338115000 0 connected

注意:当添加节点成功以后,新增的节点不会有任何数据,因为它还没有分配任何的slot(hash槽),我们需要为新节点手工分配hash槽

给8007分配Hash槽

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster reshard 192.168.0.138:8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.0.138:8001)
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots: (0 slots) slave
   replicates 44e2ec56944a0d9760b7180d7aebbc97b1fb495f
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   slots: (0 slots) slave
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
M: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots: (0 slots) slave
   replicates 5aaf267e75753a20b9b5a43273e68accb10571f5
M: c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007
   slots: (0 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# 需要多少个槽移动到新的节点上,自己设置,比如600个hash槽
How many slots do you want to move (from 1 to 16384)? 600
# 把这600个hash槽移动到哪个节点上去,需要指定节点id(8007对应的id)
What is the receiving node ID? c80becfa75dd146eefdca89fa3c2a83d1a885b23
Please enter all the source node IDs.
  # 输入'all'以使用所有节点作为散列槽的源节点。
  Type 'all' to use all the nodes as source nodes for the hash slots.
  # 输入所有源节点id,输入“done”。
  Type 'done' once you entered all the source nodes IDs.
# 输入all为从所有主节点(8001,8002,8003)中分别抽取相应的槽数指定到新节点中,抽取的总槽数为600个  
Source node #1: all

# 输入yes 开始重新分片
Do you want to proceed with the proposed reshard plan (yes/no)? yes

查看集群状态:

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666338849283 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666338850293 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666338851307 10 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666338849000 10 connected 199-5460
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666338849000 8 connected 11122-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666338848000 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666338850000 11 connected 0-198 5461-5661 10923-11121

现在我们的8007已经有hash槽了,也就是说可以在8007上进行读写数据啦!到此为止我们的8007已经加入到集群中,并且是主节点(Master)

将8008添加到集群(Slave)

这一步和8007是差不多的。

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster add-node 192.168.0.138:8008 192.168.0.138:8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.0.138:8008 to cluster 192.168.0.138:8001
>>> Performing Cluster Check (using node 192.168.0.138:8001)
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[199-5460] (5262 slots) master
   1 additional replica(s)
M: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   slots:[5662-10922] (5261 slots) master
   1 additional replica(s)
S: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots: (0 slots) slave
   replicates 44e2ec56944a0d9760b7180d7aebbc97b1fb495f
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   slots: (0 slots) slave
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
M: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   slots:[11122-16383] (5262 slots) master
   1 additional replica(s)
S: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots: (0 slots) slave
   replicates 5aaf267e75753a20b9b5a43273e68accb10571f5
M: c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007
   slots:[0-198],[5461-5661],[10923-11121] (599 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.0.138:8008 to make it join the cluster.
[OK] New node added correctly.
[root@192 ~]# 

查看集群状态:

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666339203015 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666339203000 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666339204059 10 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666339202000 10 connected 199-5460
9993aa805467a740fe40c76467f24e40cc84be4a 192.168.0.138:8008@18008 master - 0 1666339202000 0 connected
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666339202000 8 connected 11122-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666339202000 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666339205096 11 connected 0-198 5461-5661 10923-11121

注意:此时的8008也是master节点,我们后面需要将其修改成从节点

我们需要执行replicate命令来指定当前节点(从节点)的主节点id为哪个,首先需要连接新加的8008节点的客户端,然后使用集群命令进行操作,把当前的8008(slave)节点指定到一个主节点下(这里使用之前创建的8007主节点)

$ /usr/local/redis/bin/redis-cli -a soft01 -c -p 8008
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# 8007的id是c80becfa75dd146eefdca89fa3c2a83d1a885b23
127.0.0.1:8008> cluster replicate c80becfa75dd146eefdca89fa3c2a83d1a885b23
OK
127.0.0.1:8008> cluster nodes
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666339377426 10 connected
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666339376000 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666339378434 11 connected 0-198 5461-5661 10923-11121
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666339376011 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666339376000 9 connected
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666339379444 8 connected 11122-16383
9993aa805467a740fe40c76467f24e40cc84be4a 192.168.0.138:8008@18008 myself,slave c80becfa75dd146eefdca89fa3c2a83d1a885b23 0 1666339375000 0 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 master - 0 1666339377000 10 connected 199-5460

可以看到,8008变成了从节点,它的master节点是8007

删除节点

删除从节点

del-node删除从节点8008

192.168.0.138:8008 被删除的节点 ip:port

9993aa805467a740fe40c76467f24e40cc84be4a 被删除节点的id

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster del-node 192.168.0.138:8008 9993aa805467a740fe40c76467f24e40cc84be4a
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 9993aa805467a740fe40c76467f24e40cc84be4a from cluster 192.168.0.138:8008
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

再次查看集群状态,如下所示,8008这个slave节点已经移除,并且该节点的redis服务也已被停止

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666340569144 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666340567000 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666340568136 10 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666340567000 10 connected 199-5460
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666340567000 8 connected 11122-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666340567128 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666340567128 11 connected 0-198 5461-5661 10923-11121

$ [root@192 ~]# ps -ef | grep redis
root       8052      1  0 10月20 ?      00:02:48 /usr/local/redis/bin/redis-server *:8002 [cluster]
root       8803      1  0 10月20 ?      00:02:49 /usr/local/redis/bin/redis-server *:8003 [cluster]
root       9045      1  0 10月20 ?      00:02:49 /usr/local/redis/bin/redis-server *:8004 [cluster]
root       9626      1  0 10月20 ?      00:02:51 /usr/local/redis/bin/redis-server *:8005 [cluster]
root       9970      1  0 10月20 ?      00:02:50 /usr/local/redis/bin/redis-server *:8006 [cluster]
root      91738      1  0 00:32 ?        00:00:07 /usr/local/redis/bin/redis-server *:8007 [cluster]
root     103952      1  0 10月20 ?      00:02:50 /usr/local/redis/bin/redis-server *:8001 [cluster]

删除主节点

最后,我们尝试删除之前加入的主节点8007,这个步骤相对比较麻烦一些,因为主节点的里面是有分配了hash槽的,所以我们这里必须 先把8007里的hash槽放入到其他的可用主节点中去,然后再进行移除节点操作,不然会出现数据丢失问题(目前只能把master的数据迁移 到一个节点上,暂时做不了平均分配功能),执行命令如下:

[root@192 ~]# /usr/local/redis/bin/redis-cli -a soft01 --cluster reshard 192.168.0.138:8007
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.0.138:8007)
M: c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007
   slots:[0-198],[5461-5661],[10923-11121] (599 slots) master
S: a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006
   slots: (0 slots) slave
   replicates 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
S: bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003
   slots: (0 slots) slave
   replicates 5aaf267e75753a20b9b5a43273e68accb10571f5
M: 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001
   slots:[199-5460] (5262 slots) master
   1 additional replica(s)
M: 5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005
   slots:[11122-16383] (5262 slots) master
   1 additional replica(s)
M: 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004
   slots:[5662-10922] (5261 slots) master
   1 additional replica(s)
S: 1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002
   slots: (0 slots) slave
   replicates 44e2ec56944a0d9760b7180d7aebbc97b1fb495f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# 
How many slots do you want to move (from 1 to 16384)? 600             
# 这里是需要把数据移动到哪?8001的主节点id
What is the receiving node ID? 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
# 准备移动的数据源?这里是8007的节点id  
Source node #1: c80becfa75dd146eefdca89fa3c2a83d1a885b23
# 结束指定数据源
Source node #2: done
# 指定计划
Do you want to proceed with the proposed reshard plan (yes/no)? yes

至此,我们已经成功的把8007主节点的数据迁移到8001上去了,我们可以看一下现在的集群状态如下图,你会发现8007下面已经没有任 何hash槽了,证明迁移成功!

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666341387270 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666341388000 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666341389305 12 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666341385000 12 connected 0-5661 10923-11121
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666341388000 8 connected 11122-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666341388281 8 connected
c80becfa75dd146eefdca89fa3c2a83d1a885b23 192.168.0.138:8007@18007 master - 0 1666341388080 11 connected

最后我们直接使用del-node命令删除8007主节点即可

$ /usr/local/redis/bin/redis-cli -a soft01 --cluster del-node 192.168.0.138:8007 c80becfa75dd146eefdca89fa3c2a83d1a885b23
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node c80becfa75dd146eefdca89fa3c2a83d1a885b23 from cluster 192.168.0.138:8007
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

# 查看集群状态,一切还原为最初始状态啦!大功告成!

$ /usr/local/redis/bin/redis-cli -a soft01 -p 8001
127.0.0.1:8001> cluster nodes
44e2ec56944a0d9760b7180d7aebbc97b1fb495f 192.168.0.138:8004@18004 master - 0 1666341540418 9 connected 5662-10922
1c6e6e3986840a30cb3ec9a3137b9fe82e8fc2e1 192.168.0.138:8002@18002 slave 44e2ec56944a0d9760b7180d7aebbc97b1fb495f 0 1666341538000 9 connected
a90d542f240e9fd9bb0ca3861463163fac475b3a 192.168.0.138:8006@18006 slave 3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 0 1666341538000 12 connected
3754fe578c29b147b0aaf4b6ed64ce97fdb3ab52 192.168.0.138:8001@18001 myself,master - 0 1666341539000 12 connected 0-5661 10923-11121
5aaf267e75753a20b9b5a43273e68accb10571f5 192.168.0.138:8005@18005 master - 0 1666341540000 8 connected 11122-16383
bab2c897f42a3e05af40d9f4d8abd0ae65beb34d 192.168.0.138:8003@18003 slave 5aaf267e75753a20b9b5a43273e68accb10571f5 0 1666341539407 8 connected

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

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

相关文章

【图灵MySQL】MySQL索引优化实战(上)

【图灵MySQL】MySQL索引优化实战&#xff08;上&#xff09; 数据准备-SQL CREATE TABLE employees (id int(11) NOT NULL AUTO_INCREMENT,name varchar(24) NOT NULL DEFAULT COMMENT 姓名,age int(11) NOT NULL DEFAULT 0 COMMENT 年龄,position varchar(20) NOT NULL DEF…

1024程序员节带你玩转图片Exif信息获取之JavaScript

目录 一、前言 二、背景 三、Exif.js 1、Exif.js 简介 2、Exif.js 引入 四、多场景展示数据获取 1、原始图片直接获取 2、base64 编码文件加载 3、文件上传的方式加载 五、总结 一、前言 1024是2的十次方&#xff0c;二进制计数的基本计量单位之一。1G1024M&#xff0c;而…

git工具基本操作命令

初始化 首先在某个文件下新建一个项目。然后使用git初始化命令开始正式管理写好的代码。 首先新建一个项目&#xff1a; 然后在上述文件夹中右键选择git&#xff0c;或者直接在该文件路径下打开cmd进行操作&#xff1a; 上述操作出现了.git文件夹&#xff0c;今后所有的操作都…

Sharding-JDBC实现读写分离

前言 快一个月没有更新文章了&#xff0c;太忙了太忙了&#xff0c;虽然慢了一点&#xff0c;但是我肯定不会断更。上一篇文章是《Mysql主从复制》&#xff0c;光是数据库层面的主从复制可不行&#xff0c;应用层面也是需要读写分离的&#xff0c;所以接上一篇文章我们来讲如何…

赶紧进来看看---万字博客详解C/C++中的动态内存管理

本篇博客主要介绍了C/C程序内部的内存开辟.动态内存分布 动态内存函数malloc calloc realloc free的使用 常见的动态内存错误.以及柔性数组的概念与使用 学会动态内存管理将不再局限于使用静态的空间,对内存空间的理解和使用将更进一层楼~ C/C动态内存管理一.认识C/C程序的内存…

【C++升级之路】类与对象(中)

&#x1f31f;hello&#xff0c;各位读者大大们你们好呀&#x1f31f; &#x1f36d;&#x1f36d;系列专栏&#xff1a;【C学习与应用】 ✒️✒️本篇内容&#xff1a;类与对象知识汇总&#xff0c;包括6大默认成员函数、日期类的实现 &#x1f6a2;&#x1f6a2;作者简介&…

graphQL入门分享

是什么 一种用于 API 的查询语言&#xff1b;它与特定技术无关&#xff0c;你可以用任何语言实现它 简单理解&#xff0c;他能提供一个接口&#xff0c;让我们来调用&#xff0c;只是返回的数据格式更多是由我们前端来控制 为什么 官网&#xff1a;https://graphql.cn/ 1.请求你…

深入理解计算机系统前篇总结

&#x1f343;博主昵称&#xff1a;一拳必胜客 博主主页面链接&#xff1a;博主主页传送门 博主专栏页面连接&#xff1a;专栏传送门–计算机考研 &#x1f351;创作初心&#xff1a;本博客的初心是每天分享记录自己学习的脚步&#xff0c;和各位技术友探讨交流&#xff0c;同时…

惠州龙门大米飘香 国稻种芯-中国水稻节:广东乡村振兴样板

惠州龙门大米飘香 国稻种芯-中国水稻节&#xff1a;广东乡村振兴样板 人民日报客户端 新闻中国采编网 中国新闻采编网 谋定研究中国智库网 中国农民丰收节国际贸易促进会 国稻种芯中国水稻节 中国三农智库网-功能性农业农业大健康大会报道&#xff1a; 粒粒“龙门大米”精美飘…

百度地图API的使用(附案例)

文章目录JavaScript API GL一、申请秘钥Hello World显示地址案例定位功能步行导航搜索功能地铁路线规划JavaScript API GL 百度地图JavaScript API是一套由JavaScript语言编写的应用程序接口&#xff0c;可帮助您在网站中构建功能丰富、交互性强的地图应用&#xff0c;支持PC端…

经典文献阅读之--用于自动驾驶的高清地图生成技术

0. 简介 这篇文章我们介绍一下论文“High-Definition Map Generation Technologies For Autonomous Driving: A Review“&#xff0c;2022年6月11日&#xff0c;来自加拿大Ontario Tech University。相较于网上的其他文章&#xff0c;本文更在意向读者更轻松全面的了解文章中介…

【Web前端大作业】基于HTML+CSS+JavaScript制作西北大学新闻网站(7页)

&#x1f389;精彩专栏推荐 &#x1f4ad;文末获取联系 ✍️ 作者简介: 一个热爱把逻辑思维转变为代码的技术博主 &#x1f482; 作者主页: 【主页——&#x1f680;获取更多优质源码】 &#x1f393; web前端期末大作业&#xff1a; 【&#x1f4da;毕设项目精品实战案例 (10…

悬浮坐标解决方案:如何在图片获取xy鼠标位置和增加标注信息

悬浮坐标的定义&#xff0c;基于固定分辨率的图片&#xff0c;通过获取该图片x和y坐标确定位置后并添加标注&#xff0c;实现位置展示、对应图片内物品展示的一种标注开发方式。 技术要点 自动获取图片x和y坐标&#xff1b;将多个坐标xy在图片上通过CSS定位的方式予以展示&am…

pytorch学习(三)——模型层

文章目录1. 自定义模型层2. 使用预训练模型3. 模型构建风格3.1 使用 add_module 方法3.2 添加进 Sequential3.3 Sequential作为模型容器3.4 ModuleList作为模型容器3.5 ModuleDict作为模型容器当我们构建了数据管道能够将数据一个batch一个batch的取出来后&#xff0c;下一步就…

微信小程序函数处理之保姆级讲解

目录 生命周期函数 生命周期函数的调用过程 页面事件函数 页面路由管理 自定义函数 setData设值函数 生命周期函数 在使用Page&#xff08;&#xff09;构造器注册页面时&#xff0c;需要使用生命周期函数&#xff0c;包括onLoad&#xff08;&#xff09;页面加载时生命周…

硬件工程师成长之路(10.1)——芯片选型

系列文章目录 1.元件基础 2.电路设计 3.PCB设计 4.元件焊接 5.板子调试 6.程序设计 7.算法学习 8.编写exe 9.检测标准 10.项目举例 11.职业规划 文章目录前言一、电机驱动类1 、直流电机驱动芯片2、步进电机③、资料前言 送给大学毕业后找不到奋斗方向的你&#xff08;每周…

【车间调度】基于全球邻域和爬坡来优化模糊柔性作业车间调度问题(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️❤️&#x1f4a5;&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑…

VS Studio 搭建跨平台开发环境

VS Studio 搭建跨平台开发环境 增加VS的工作负载 打开Visual Studio Installer 安装器&#xff0c;点击修改 在这个界面找到Linux开发环境&#xff0c;勾上然后在点击右下角的修改等待安装。我的是因为已经有了所以下面那里显示的是关闭&#xff0c;没有的是显示的修改 等待安…

LabVIEW强制重新安装无法运行或损坏的NI软件

LabVIEW强制重新安装无法运行或损坏的NI软件 可以参考附件的录像说明。LabVIEW强制重新安装无法运行或损坏的NI软件 - 北京瀚文网星科技有限公司 (bjcyck.com) 某些NI软件&#xff0c;工具包或驱动程序已损坏&#xff0c;损坏或无法按预期运行&#xff0c;想尝试重新安装以进…

【ArchSummit】众安金融微服务架构演进实战

前言 &#x1f4eb; 作者简介&#xff1a;小明java问道之路&#xff0c;专注于研究 Java/ Liunx内核/ C及汇编/计算机底层原理/源码&#xff0c;就职于大型金融公司后端高级工程师&#xff0c;擅长交易领域的高安全/可用/并发/性能的架构设计与演进、系统优化与稳定性建设。 &a…