当前位置:网站首页>Redis6 cluster setup
Redis6 cluster setup
2022-07-06 05:48:00 【Python's path to immortality】
Redis6 Cluster building
At present redis The latest version is already 6.2.6, On cluster construction and redis3.x、redis4.x Difference is very big .redis5 in the future , There's no need to install ruby 了 , And the new version redis Creating a cluster is no longer used redis-trib.rb, While using redis-cli. The following is the new version redis6.2.6 Cluster setup record . This article uses three servers ,6 individual redis Service instance (redis The cluster will automatically try to prevent two instances of the same machine from being master-slave to each other ).
List of articles
One 、 Environmental preparation
ip | port |
---|---|
101.0.0.101 | 7001 、7002 |
101.0.0.102 | 7001 、7002 |
101.0.0.103 | 7001 、7002 |
Two 、 Build and start redis example
1.1 take redis-6.2.6.tar.gz( Download address :https://redis.io/download) Upload to server , Decompress and compile
yum -y install gcc
tar xzf redis-6.2.6.tar.gz -C home/
cd home/redis-6.2.6
make MALLOC=libc
make PREFIX=/home/redis-6.2.6 install # Such as make PREFIX=/usr/local/redis install, keyword PREFIX= This keyword is used to specify the path where the program is stored at compile time , Suppose you don't add the keyword Linux The executable file will be stored in /usr/local/bin Catalog , Library files will be stored in /usr/local/lib Catalog . The configuration file will be stored in /usr/local/etc Catalog .
Other resource files will be stored in usr/local/share Catalog . The directory number is specified here to facilitate subsequent unloading , Follow up direct rm -rf /usr/local/redis You can delete redis.
1.2 Create related directories , Modify the configuration file
mkdir home/rediscluster/{
7000,7001} -p
mkdir home/rediscluster/7000/{
conf,data,log} -p
mkdir /home/rediscluster/7001/{
conf,data,log} -p
cp /home/redis-6.2.6/redis.conf /home/rediscluster/7000/conf/
cp /home/redis-6.2.6/redis.conf /home/rediscluster/7001/conf/
1.3 Modify the configuration file
modify /home/rediscluster/7000/conf/redis.conf( The following cluster configuration must be modified , Other configurations are modified according to the actual situation ):
bind 101.0.0.101
port 7000
daemonize yes
pidfile "/home/rediscluster/7000/data/redis_7000.pid"
logfile "/home/rediscluster/7000/log/redis_7000.log"
dbfilename dump-7000.rdb
dir "/home/rediscluster/7000/data/"
masterauth "myredis" # Set the password ,redis Be sure to enable password authentication requirepass and masterauth Simultaneous setting ;masterauth effect : Mainly aimed at master Corresponding slave Node settings , stay slave Node data synchronization is used .requirepass effect : Restrict login permissions ,redis For each node requirepass Can be independent 、 Different .requirepass Verify client ,masterauth Verify slave Library .
requirepass "myredis"
cluster-enabled yes
cluster-node-timeout 5000
take 7000 Copy the configuration file of the directory to 7001 Instance and pay attention to the 7000 Change it to 7001:
cp /home/rediscluster/7000/conf/redis.conf /home/rediscluster/7001/conf/redis.conf
sed -i 's#7000#7001#g' /home/rediscluster/7001/conf/redis.conf
1.4 Configure environment variables
echo 'export REDIS_HOME=/home/redis-6.2.2' >> /etc/profile
echo 'export PATH=$REDIS_HOME/bin:$PATH' >> /etc/profile
source /etc/profile
1.5 start-up redis
redis-server /home/rediscluster/7000/conf/redis.conf
redis-server /home/rediscluster/7001/conf/redis.conf
1.6 The other two servers
Repeat the above steps on the other two servers , Pay attention to redis.conf Inside bind IP Change to native IP.
Ensure the availability of three servers redis Node starts normally :
3、 ... and 、 establish redis colony
On three servers redis After the instance is successfully started , Execute the command on the first server to create the cluster ( Note that if redis.conf The password is set in , Here we need to add -a ‘ password ’, If there is no password , No more -a Parameters ):
Password :
redis-cli --cluster create --cluster-replicas 1 101.0.0.101:7000 101.0.0.101:7001 101.0.0.102:7000 101.0.0.102:7001 101.0.0.103:7000 101.0.0.103:7001 -a myredis
password-less :
redis-cli --cluster create --cluster-replicas 1 101.0.0.101:7000 101.0.0.101:7001 101.0.0.102:7000 101.0.0.102:7001 101.0.0.103:7000 101.0.0.103:7001
/usr/local/redis/bin/redis-cli --cluster create 10.11.0.148:7001 10.11.0.149:7002 10.11.0.149:7001 10.11.0.150:7002 10.11.0.150:7001 10.11.0.148:7002 --cluster-replicas 1
Create a screenshot of the process , Note the confirmation input in the figure “yes”.
Four 、 verification redis colony
After the cluster is created successfully , Sign in redis verification , Pay attention to adding cluster parameters -c:
redis-cli -h 101.0.0.101 -p 7000 -a myredis -c # Sign in redis colony
101.0.0.101:7000> cluster nodes # View the cluster nodes
101.0.0.101:7000> cluster info # View cluster information
verification OK,redis6.2.2 The cluster has been set up .
5、 ... and 、Redis Configuration file parameter description
1. Redis The default is not to run as a daemon , This configuration item can be modified , Use yes Enable daemons
daemonize no
2. When Redis Run as a daemon ,Redis By default the pid write in /var/run/redis.pid file , Can pass pidfile Appoint
pidfile /var/run/redis.pid
3. Appoint Redis Listening port , The default port is 6379, In one of his blog posts, the author explains why 6379 As default port , because 6379 On the phone buttons MERZ The corresponding number , and MERZ From the Italian singer Alessia Merz Name
port 6379
4. The bound host address
bind 127.0.0.1
5. When How long does the client sit idle before closing the connection , If specified as 0, Indicates that the feature is turned off
timeout 300
6. Specifies the logging level ,Redis There are four levels supported :debug、verbose、notice、warning, The default is verbose
loglevel verbose
7. Logging mode , The default is standard output , If configured Redis Run for daemon mode , This is configured for logging as standard output , The log will be sent to /dev/null
logfile stdout
8. Set the number of databases , The default database is 0, have access to SELECT <dbid> The command specifies the database on the connection id
databases 16
9. Specify how long , How many update operations are there , Synchronize the data to the data file , Multiple conditions can be used
save <seconds> <changes>
Redis Three conditions are provided in the default configuration file :
save 900 1
save 300 10
save 60 10000
respectively 900 second (15 minute ) There are 1 A change ,300 second (5 minute ) There are 10 Changes and 60 In seconds 10000 A change .
10. Specifies whether data is compressed when stored to a local database , The default is yes,Redis use LZF Compress , If in order to save money CPU Time , This option can be turned off , But it can make the database files huge
rdbcompression yes
11. Specifies the local database file name , The default value is dump.rdb
dbfilename dump.rdb
12. Specifies the local database hosting directory
dir ./
13. Set when the native is slav The service , Set up master Service IP Address and port , stay Redis Startup time , It will automatically follow master Data synchronization
slaveof <masterip> <masterport>
14. When master When the service is password protected ,slav Service connection master Password
masterauth <master-password>
15. Set up Redis Connect the password , If the connection password is configured , The client is connecting Redis Need to go through AUTH <password> Command provide password , Off by default
requirepass foobared
16. Sets the maximum number of client connections at one time , Default limit ,Redis The number of client connections that can be opened simultaneously is Redis The maximum number of file descriptors that a process can open , If you set maxclients 0, No restrictions . When the number of client connections reaches the limit ,Redis The new connection is closed and returned to the client max number of clients reached error message
maxclients 128
17. Appoint Redis Maximum memory limit ,Redis Data is loaded into memory at startup , After reaching the maximum memory ,Redis It will first try to clear those that are due or are about to expire Key, When this method is handled after , Still reaches the maximum memory setting , Will no longer be able to write , But you can still do a read .Redis new vm Mechanism , Will be able to Key Storage memory ,Value Will be stored in a swap District
maxmemory <bytes>
18. Specifies whether to log after each update operation ,Redis By default, data is written asynchronously to disk , If you don't turn it on , Data may be lost for a period of time during a power outage . because redis The itself synchronization data file is pressed above save Condition to synchronize , So some data will only exist in memory for a while . The default is no
appendonly no
19. Specifies the file name of the update log , The default is appendonly.aof
appendfilename appendonly.aof
20. Specifies an update log condition , share 3 Optional values : no: Means that the operating system synchronizes the data cache to disk ( fast ) always: Represents a manual call after each update operation fsync() Write data to disk ( slow , Security ) everysec: That means once per second ( compromise , The default value is )
appendfsync everysec
21. Specifies whether the virtual memory mechanism is enabled , The default value is no, A brief introduction ,VM The mechanism stores data in pages , from Redis Cold data for less visited pages swap To disk , Pages with multiple accesses are automatically swapped out from disk to memory ( I will analyze it carefully in the following articles Redis Of VM Mechanism )
vm-enabled no
22. Virtual memory file path , The default value is /tmp/redis.swap, Not more than one Redis The instance Shared
vm-swap-file /tmp/redis.swap
23. I'm going to make everything greater than vm-max-memory Is stored in virtual memory , No matter what vm-max-memory Set up small , All index data is stored in memory (Redis Index data of Namely keys), in other words , When vm-max-memory Set to 0 When , It's all value Both exist on disk . The default value is 0
vm-max-memory 0
24. Redis swap The file is divided into many parts page, An object can be stored in more than one page above , But a page Can't be Shared by multiple objects ,vm-page-size It's based on storage The data size is set , The authors suggest storing many small objects ,page The size is best set to 32 perhaps 64bytes; If you store large objects , You can use a larger one page, If you don't determine , Just use the default values
vm-page-size 32
25. Set up swap In the document page Number , Because the page table ( One that indicates that a page is free or in use bitmap) It's in memory ,, Each on disk 8 individual pages Will consume 1byte Of memory .
vm-pages 134217728
26. Set access swap Number of threads in the file , It is best not to exceed the audit of the machine , If set to 0, So all right swap The operation of the file is serial , May cause a relatively long delay . The default value is 4
vm-max-threads 4
27. Set when to reply to the client , Whether to combine smaller packages into a single package , On by default
glueoutputbuf yes
28. Specifies when a certain number or maximum of elements exceeds a certain threshold , A special hash algorithm is used
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
29. Specifies whether to activate the reset hash , On by default ( In the introduction Redis The hash algorithm is introduced in detail )
activerehashing yes
30. Specifies that additional configuration files are included , More than one can be on the same host Redis The same configuration file is used between instances , At the same time, each instance has its own specific configuration file
include /path/to/local.conf
边栏推荐
- Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
- Jushan database appears again in the gold fair to jointly build a new era of digital economy
- Station B, Master Liu Er - dataset and data loading
- 清除浮动的方式
- Embedded interview questions (IV. common algorithms)
- Game push image / table /cv/nlp, multi-threaded start
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- continue和break的区别与用法
- Is it difficult for an information system project manager?
- YYGH-11-定时统计
猜你喜欢
Yygh-11-timing statistics
Analysis of grammar elements in turtle Library
JS array list actual use summary
巨杉数据库再次亮相金交会,共建数字经济新时代
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
Station B, Master Liu Er - back propagation
26file filter anonymous inner class and lambda optimization
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
03. Login of development blog project
LTE CSFB process
随机推荐
Improve jpopup to realize dynamic control disable
Yunxiaoduo software internal test distribution test platform description document
Go language -- language constants
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
类和对象(一)this指针详解
B站刘二大人-线性回归 Pytorch
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
进程和线程
Embedded interview questions (I: process and thread)
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Web Security (V) what is a session? Why do I need a session?
Promise summary
Redis message queue
局域网同一个网段通信过程
[machine learning notes] univariate linear regression principle, formula and code implementation
H3C V7版本交换机配置IRF
Problems encountered in installing mysql8 on MAC
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
Station B Liu Erden softmx classifier and MNIST implementation -structure 9