当前位置:网站首页>Ubuntu18.04 set up redis cluster [learning notes]
Ubuntu18.04 set up redis cluster [learning notes]
2022-07-28 06:52:00 【[dissimilarity space]】
explain
In the same Ubuntu Simulation setup under the host redis The process of clustering , Distinguish by different port numbers
Create a cluster profile
7000.conf
port 7000
bind 192.168.1.106
daemonize yes
pidfile 7000.pid
cluster-enabled yes
cluster-config-file 7000_node.conf
cluster-node-timeout 15000
appendonly yes
7001.conf
port 7001
bind 192.168.1.106
daemonize yes
pidfile 7001.pid
cluster-enabled yes
cluster-config-file 7001_node.conf
cluster-node-timeout 15000
appendonly yes
7002.conf
port 7002
bind 192.168.1.106
daemonize yes
pidfile 7002.pid
cluster-enabled yes
cluster-config-file 7002_node.conf
cluster-node-timeout 15000
appendonly yes
7003.conf
port 7003
bind 192.168.1.106
daemonize yes
pidfile 7003.pid
cluster-enabled yes
cluster-config-file 7003_node.conf
cluster-node-timeout 15000
appendonly yes
7004.conf
port 7004
bind 192.168.1.106
daemonize yes
pidfile 7004.pid
cluster-enabled yes
cluster-config-file 7004_node.conf
cluster-node-timeout 15000
appendonly yes
7005.conf
port 7005
bind 192.168.1.106
daemonize yes
pidfile 7005.pid
cluster-enabled yes
cluster-config-file 7005_node.conf
cluster-node-timeout 15000
appendonly yes
Copy redis-trib.rb To the specified directory
sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/
install ruby
sudo apt-get install ruby
install redis library
[email protected]:~/redis colony $ sudo gem install redis
establish redis-server colony
1. Turn on redis-server
[email protected]:~/redis colony $ sudo redis-server 7001.conf
3473:C 02 May 15:48:03.867 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3473:C 02 May 15:48:03.867 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3473, just started
3473:C 02 May 15:48:03.867 # Configuration loaded
[email protected]:~/redis colony $ sudo redis-server 7002.conf
3479:C 02 May 15:48:07.019 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3479:C 02 May 15:48:07.019 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3479, just started
3479:C 02 May 15:48:07.019 # Configuration loaded
[email protected]:~/redis colony $ sudo redis-server 7003.conf
3485:C 02 May 15:48:11.147 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3485:C 02 May 15:48:11.147 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3485, just started
3485:C 02 May 15:48:11.147 # Configuration loaded
[email protected]:~/redis colony $ sudo redis-server 7004.conf
3491:C 02 May 15:48:15.623 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3491:C 02 May 15:48:15.623 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3491, just started
3491:C 02 May 15:48:15.623 # Configuration loaded
[email protected]:~/redis colony $ sudo redis-server 7005.conf
3497:C 02 May 15:48:20.155 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3497:C 02 May 15:48:20.155 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3497, just started
3497:C 02 May 15:48:20.156 # Configuration loaded
[email protected]:~/redis colony $ ps aux | grep redis
redis 1519 0.2 0.1 58556 3628 ? Ssl 15:20 0:03 /usr/bin/redis-server 192.168.1.106:6379
root 3466 0.1 0.2 58556 4244 ? Ssl 15:47 0:00 redis-server 192.168.1.106:7000 [cluster]
root 3474 0.2 0.2 58556 4308 ? Ssl 15:48 0:00 redis-server 192.168.1.106:7001 [cluster]
root 3480 0.1 0.2 58556 4312 ? Ssl 15:48 0:00 redis-server 192.168.1.106:7002 [cluster]
root 3486 0.2 0.2 58556 4352 ? Ssl 15:48 0:00 redis-server 192.168.1.106:7003 [cluster]
root 3492 1.1 0.1 58556 3496 ? Ssl 15:48 0:00 redis-server 192.168.1.106:7004 [cluster]
root 3498 0.2 0.2 58556 4248 ? Ssl 15:48 0:00 redis-server 192.168.1.106:7005 [cluster]
wang 3503 0.0 0.0 21540 1032 pts/0 S+ 15:48 0:00 grep --color=auto redis
2. shipment ⾏ Create a cluster with the following command
[email protected]:~/redis colony $ redis-trib.rb create --replicas 1 192.168.1.106:7000 192.168.1.106:7001 192.168.1.106:7002 192.168.1.106:7003 192.168.1.106:7004 192.168.1.106:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.106:7000
192.168.1.106:7001
192.168.1.106:7002
Adding replica 192.168.1.106:7004 to 192.168.1.106:7000
Adding replica 192.168.1.106:7005 to 192.168.1.106:7001
Adding replica 192.168.1.106:7003 to 192.168.1.106:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 5ee9435260da554c63b6f2e8e8ae7af7cc499ba6 192.168.1.106:7000
slots:0-5460 (5461 slots) master
M: 92408098106f9dc4ab6531503a70f853ef34715b 192.168.1.106:7001
slots:5461-10922 (5462 slots) master
M: 268a37b1064166e092796934e67fe9b138ec0f4c 192.168.1.106:7002
slots:10923-16383 (5461 slots) master
S: 93d540f33cec141253aaff991888f2253566d307 192.168.1.106:7003
replicates 92408098106f9dc4ab6531503a70f853ef34715b
S: 45965df077a1ff5afc4611708b99114eff53c07b 192.168.1.106:7004
replicates 268a37b1064166e092796934e67fe9b138ec0f4c
S: 9a439a9e53aeb9c078b60952212b50830924b3fa 192.168.1.106:7005
replicates 5ee9435260da554c63b6f2e8e8ae7af7cc499ba6
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.1.106:7000)
M: 5ee9435260da554c63b6f2e8e8ae7af7cc499ba6 192.168.1.106:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 268a37b1064166e092796934e67fe9b138ec0f4c 192.168.1.106:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 9a439a9e53aeb9c078b60952212b50830924b3fa 192.168.1.106:7005
slots: (0 slots) slave
replicates 5ee9435260da554c63b6f2e8e8ae7af7cc499ba6
M: 92408098106f9dc4ab6531503a70f853ef34715b 192.168.1.106:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 45965df077a1ff5afc4611708b99114eff53c07b 192.168.1.106:7004
slots: (0 slots) slave
replicates 268a37b1064166e092796934e67fe9b138ec0f4c
S: 93d540f33cec141253aaff991888f2253566d307 192.168.1.106:7003
slots: (0 slots) slave
replicates 92408098106f9dc4ab6531503a70f853ef34715b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Prompt complete , Successful cluster construction .
Test and verify
From the above creation information, you can get the main information of the cluster redis Yes 7000,7001,7002; from redis Yes 7003,7004,7005
[email protected]:~/redis colony $ redis-cli -h 192.168.1.106 -p 7000 -c
192.168.1.106:7000> set name zhangsan
-> Redirected to slot [5798] located at 192.168.1.106:7001
OK
192.168.1.106:7001> keys *
1) "name"
192.168.1.106:7001> get name
"zhangsan"
explain
- redis cluster In design , Just think about going to China ⼼ turn , Go to middleware , in other words , In the cluster Every node in the network is an equal relationship , They are all equal , Each node holds each ⾃ And the entire set The state of a group . Each node is connected to all other nodes ,⽽ And these connections stay active , In this way, we can guarantee Prove that we only need to connect any ⼀ Nodes , You can get data from other nodes
- Redis Cluster does not make ⽤ Conventional ⼀ Hash to allocate data ,⽽ It's mining ⽤ in addition ⼀ It's called hash Slot (hash slot) Of ⽅ It's divided by the formula .redis cluster By default 16384 individual slot, When we set⼀ individual key when , Meeting ⽤CRC16 Algorithm to get the module to belong to slot, And then put this key It's divided into On the node of the trough section , The specific algorithm is :CRC16(key) % 16384. So what we're testing is When I saw set and get When , Jump straight to 7000 End ⼝ The node of
- Redis The data will exist in the cluster ⼀ individual master node , And then here master Corresponding to it salve In between ⾏ Data synchronization . When the data is read , According to ⼀ Coherent hashing algorithm to the corresponding master section Point to get the data . Only when ⼀ individual master After hanging up , Will start ⼀ A corresponding salve node , charge When master
It should be noted that : It has to be 3 More than one master node , Otherwise, it will fail to create the cluster , And when you save The number of live major nodes ⼩ Of the total number of nodes ⼀ Half an hour , The whole cluster is ⽆ The law serves
边栏推荐
猜你喜欢

explain详解

NIO示例

What's a good gift for Tanabata? Niche and advanced product gift recommendation

JS reverse question 100 - question 1

Prometheus monitoring Nacos

mongoDB复制集及分片集群

DNS domain name resolution service

Mongodb replica set and partitioned cluster
![[c language] - step by step to achieve minesweeping games](/img/ee/49ddfcd948ccd5c8c9dec3c48c6112.png)
[c language] - step by step to achieve minesweeping games

Graphic pipeline foundation (II)
随机推荐
Water bottle effect production
数组转链表
Elastic common high frequency commands
Hdu-5783 divide the sequence (greedy water question)
redis缓存设计与性能优化
cocos2d-x 学习笔记——瓦片地图TiledMap
Source code analysis of countdownlatch of AQS
KVM hot migration
Mongodb quick start
prometheus监控nacos
Ubuntu18.04搭建redis集群【学习笔记】
JS四则运算重新封装,解决精度丢失问题
Compilation and preprocessing of C language
Test life | second tier cities with an annual salary of more than 40W? How did you achieve 100% salary increase under the epidemic?
Pku-2524-ubiquitous relations (parallel search template)
NiO example
Code tidiness (I)
HDU-5805-NanoApe Loves Sequence(思维题)
Fermat's theorem
File operation in C language