当前位置:网站首页>CentOS installs redis multi master multi slave cluster
CentOS installs redis multi master multi slave cluster
2022-06-26 10:30:00 【Xianghan collection】
CentOS Stand alone installation Redis Cluster(3 Lord 3 from )
In order to save machines , Let's go straight to 6 individual Redis The instance is installed on the same machine (3 Lord 3 from ), Just use different port numbers .
machine IP 192.168.56.183
cd /usr/local/redis-5.0.5
mkdir redis-cluster
cd redis-cluster
mkdir 6291 6292 6293 6294 6295 6296
Copy redis Profile to 6291 Catalog
cp /usr/local/redis-5.0.5/redis.conf /usr/local/redis-5.0.5/redis-cluster/6291
modify 6291 Of redis.conf The configuration file , Content :
cd /usr/local/redis-5.0.5/redis-cluster/6291
>redis.conf
vim redis.conf
port 6291
requirepass 123456
daemonize yes
protected-mode no
dir /usr/local/redis-5.0.5/redis-cluster/6291/
cluster-enabled yes
cluster-config-file nodes-6291.conf
cluster-node-timeout 5000
appendonly yes
pidfile /var/run/redis_6291.pid
Be careful , Add this configuration to the Internet cluster :
# Actually allocated to each node network card IP( Public network IP)
cluster-announce-ip 47.xx.xx.xx
# Node mapping port
cluster-announce-port ${PORT}
# Node bus port
cluster-announce-bus-port 1${PORT}
hold 6291 Under the redis.conf Copy to other 5 A catalog .
cd /usr/local/redis-5.0.5/redis-cluster/6291
cp redis.conf ../6292
cp redis.conf ../6293
cp redis.conf ../6294
cp redis.conf ../6295
cp redis.conf ../6296
Replace content in bulk
cd /usr/local/redis-5.0.5/redis-cluster
sed -i 's/6291/6292/g' 6292/redis.conf
sed -i 's/6291/6293/g' 6293/redis.conf
sed -i 's/6291/6294/g' 6294/redis.conf
sed -i 's/6291/6295/g' 6295/redis.conf
sed -i 's/6291/6296/g' 6296/redis.conf
start-up 6 individual Redis node
cd /usr/local/redis-5.0.5/
./src/redis-server redis-cluster/6291/redis.conf
./src/redis-server redis-cluster/6292/redis.conf
./src/redis-server redis-cluster/6293/redis.conf
./src/redis-server redis-cluster/6294/redis.conf
./src/redis-server redis-cluster/6295/redis.conf
./src/redis-server redis-cluster/6296/redis.conf
Is it activated 6 A process
ps -ef|grep redis
Create clusters
In the old version redis-trib.rb It's abandoned , Direct use –cluster command
Pay attention to the absolute IP, Do not use 127.0.0.1
cd /usr/local/redis-5.0.5/src/
redis-cli -a 123456 --cluster create 192.168.56.183:6291 192.168.56.183:6292 192.168.56.183:6293 192.168.56.183:6294 192.168.56.183:6295 192.168.56.183:6296 --cluster-replicas 1
Redis Will give an expected plan , Yes 6 Node assignment 3 Lord 3 from , If you think there is no problem , Input yes confirm
>>> 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:6295 to 127.0.0.1:6291
Adding replica 127.0.0.1:6296 to 127.0.0.1:6292
Adding replica 127.0.0.1:6294 to 127.0.0.1:6293
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: dfdc9c0589219f727e4fd0ad8dafaf7e0cfb4f1c 127.0.0.1:6291
slots:[0-5460] (5461 slots) master
M: 8c878b45905bba3d7366c89ec51bd0cd7ce959f8 127.0.0.1:6292
slots:[5461-10922] (5462 slots) master
M: aeeb7d7076d9b25a7805ac6f508497b43887e599 127.0.0.1:6293
slots:[10923-16383] (5461 slots) master
S: ebc479e609ff8f6ca9283947530919c559a08f80 127.0.0.1:6294
replicates aeeb7d7076d9b25a7805ac6f508497b43887e599
S: 49385ed6e58469ef900ec48e5912e5f7b7505f6e 127.0.0.1:6295
replicates dfdc9c0589219f727e4fd0ad8dafaf7e0cfb4f1c
S: 8d6227aefc4830065624ff6c1dd795d2d5ad094a 127.0.0.1:6296
replicates 8c878b45905bba3d7366c89ec51bd0cd7ce959f8
Can I set the above configuration? (type 'yes' to accept):
Look for the slot The distribution of :
6291 [0-5460] (5461 Slot )
6292 [5461-10922] (5462 Slot )
6293 [10923-16383] (5461 Slot )
Cluster creation complete
>>> 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:6291)
M: dfdc9c0589219f727e4fd0ad8dafaf7e0cfb4f1c 127.0.0.1:6291
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 8c878b45905bba3d7366c89ec51bd0cd7ce959f8 127.0.0.1:6292
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: aeeb7d7076d9b25a7805ac6f508497b43887e599 127.0.0.1:6293
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 8d6227aefc4830065624ff6c1dd795d2d5ad094a 127.0.0.1:6296
slots: (0 slots) slave
replicates aeeb7d7076d9b25a7805ac6f508497b43887e599
S: ebc479e609ff8f6ca9283947530919c559a08f80 127.0.0.1:6294
slots: (0 slots) slave
replicates dfdc9c0589219f727e4fd0ad8dafaf7e0cfb4f1c
S: 49385ed6e58469ef900ec48e5912e5f7b7505f6e 127.0.0.1:6295
slots: (0 slots) slave
replicates 8c878b45905bba3d7366c89ec51bd0cd7ce959f8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
The way to reset the cluster is to execute on each node cluster reset, Then recreate the cluster
Connect to the client
redis-cli -p 6291
redis-cli -p 6292
redis-cli -p 6293
Batch write value
cd /usr/local/redis-5.0.5/redis-cluster/
vim setkey.sh
The script content
#!/bin/bash
for ((i=0;i<20000;i++))
do
echo -en "helloworld" | redis-cli -h 192.168.56.183 -p 6291 -c -x set name$i >>redis.log
done
chmod +x setkey.sh
./setkey.sh
Data distributed by each node
127.0.0.1:6292> dbsize
(integer) 6683
127.0.0.1:6293> dbsize
(integer) 6665
127.0.0.1:6291> dbsize
(integer) 6652
Other commands , For example, add nodes 、 Delete node , Redistributing data :
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
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--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
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help
For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
appendix :
Cluster command
cluster info : Print cluster information
cluster nodes : List all nodes currently known to the cluster (node), And information about these nodes .
cluster meet : take ip and port The specified node is added to the cluster , Make it a part of the cluster .
cluster forget <node_id> : Remove from cluster node_id Specified node ( Make sure the empty channel ).
cluster replicate <node_id> : Set current node to node_id The slave node of the specified node .
cluster saveconfig : Save the node configuration file to the hard disk .
Slot slot command
cluster addslots [slot …] : Place one or more slots (slot) assign (assign) To the current node .
cluster delslots [slot …] : Remove the assignment of one or more slots to the current node .
cluster flushslots : Remove all slots assigned to the current node , Make the current node a node without any slots assigned .
cluster setslot node <node_id> : Put the groove slot Assign to node_id Specified node , If the slot is already assigned to another node , Let another node delete the slot first >, Then assign .
cluster setslot migrating <node_id> : The slot of this node slot Migrate to node_id In the specified node .
cluster setslot importing <node_id> : from node_id Import slot in the specified node slot To this node .
cluster setslot stable : Cancel slot slot Import of (import) Or migration (migrate).
Key command
cluster keyslot : Calculate the key key Which slot should be placed in .
cluster countkeysinslot : Return slot slot Number of key value pairs currently included .
cluster getkeysinslot : return count individual slot Key in groove
边栏推荐
- The fourteenth MySQL operation - e-mall project
- Allocation of heap memory when creating objects
- 字符串常量池、class常量池和运行时常量池
- MySQL 8th job
- Appium自动化测试基础 — 移动端测试环境搭建(二)
- Develop current learning objectives and methods
- Threading model in webrtc native
- Nested recyclerview in nestedscrollview automatically slides to the bottom after switching
- Openxcap usage
- cmake / set 命令
猜你喜欢

【LeetCode】59. Spiral matrix II

The fourteenth MySQL operation - e-mall project

Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals

SSH, SCP command appears permission denied, please try again solution

MySQL第十次作业-视图

String constant pool, class constant pool, and runtime constant pool

Use of exec series functions (EXECL, execlp, execle, execv, execvp)

Detailed explanation of winsorflow quantum installation process

Using foreach to loop two-dimensional array

Allocation de mémoire tas lors de la création d'objets
随机推荐
二叉树常见面试题
MySQL 10th job - View
VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
MySQL第五章总结
【Leetcode】76. Minimum covering substring
Reshape a two-dimensional array with 3 rows and 3 columns to find the sum of the diagonals
118. Yanghui triangle
Express (I) - easy to get started
How do technicians send notifications?
挖财商学院证券开户安全嘛?
[untitled]
Blog post index summary --c #
Blog article index summary -- Software Engineering
Record the handling of oom problems caused by too many threads at one time
方法区里面有什么——class文件、class文件常量池、运行时常量池
Omni channel, multi scenario and cross platform, how does app analyze channel traffic with data
Global and Chinese market of amateur football helmets 2022-2028: Research Report on technology, participants, trends, market size and share
How to start the learning journey of webrtc native cross platform development?
開發者,微服務架構到底是什麼?
Today's headline adaptation scheme code