当前位置:网站首页>Docker configures redis and redis clusters
Docker configures redis and redis clusters
2022-07-05 12:36:00 【just4you】
Pull redis
docker pull redis
stand-alone redis
Preparing directories and files
- Create directory : /usr/local/redis/conf
- Prepare a redis.conf file , And modify the following
# Bind ip notes , For external access
#bind 127.0.0.1
# close daemon Pattern
daemonize no
# Turn off protection mode
protected-mode no
Will modify the redis.conf Replicated to the host /usr/local/redis/conf Under the table of contents .
start-up redis
docker run -d --name=myredis --privileged=true \
-p 6379:6379 \
-v /usr/local/redis/conf:/etc/redis/ \
-v /usr/local/redis/data:/data \
-v /usr/local/redis/logs:/var/log/redis \
-v /usr/local/redis:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf
The last line is when the container is started , perform redis-server command , And use /etc/redis/redis.conf As a configuration file .
Check the startup of the container
After starting , Use :docker ps, Check to see if startup succeeded .
If it doesn't start successfully , You can use :docker logs myredis, Check the container startup log , It is most likely that the directory permissions are insufficient . At this time, you need to add permissions to the directory : chmod -R 777 /usr/local/redis.
Be careful , When the container is first started , Automatically created docker Parameters -v The directory that needs to be mounted but has not been created specified in , So you need to start the container once , Create this nonexistent directory , Give again /usr/local/redis Directory add permissions .
After adding permissions , Restart the container .
docker restart myredis
Get into redis Container client
# Go straight into redis Container client
docker exec -it myredis redis-cli
# Or enter first redis Containers , Reuse redis-cli Enter the client
docker exec -it myredis bash
other
Can be found in /usr/local/redis/logs View under directory redis.log start log .
Cluster configuration
Create a 3 Lord 3 From redis colony
Preparing directories and files
- Create directory :/usr/local/redis-cluster/01/conf,
- Copy single node redis.conf To /usr/local/redis-cluster/01/conf Under the table of contents
- take 01 Copy the directory as 02,03,04,05,06
Create a container
Cluster planning | The name of the node | port |
---|---|---|
Master node | redis-7379 | 7379 |
Master node | redis-7380 | 7380 |
Master node | redis-7381 | 7381 |
From the node | redis-7479 | 7479 |
From the node | redis-7480 | 7480 |
From the node | redis-7481 | 7481 |
docker run -d --name=redis-7379 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/01/conf:/etc/redis/ \
-v /usr/local/redis-cluster/01/data:/data \
-v /usr/local/redis-cluster/01/logs:/var/log/redis \
-v /usr/local/redis-cluster/01:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7379 \
--cluster-enabled yes
docker run -d --name=redis-7380 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/02/conf:/etc/redis/ \
-v /usr/local/redis-cluster/02/data:/data \
-v /usr/local/redis-cluster/02/logs:/var/log/redis \
-v /usr/local/redis-cluster/02:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7380 \
--cluster-enabled yes
docker run -d --name=redis-7381 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/03/conf:/etc/redis/ \
-v /usr/local/redis-cluster/03/data:/data \
-v /usr/local/redis-cluster/03/logs:/var/log/redis \
-v /usr/local/redis-cluster/03:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7381 \
--cluster-enabled yes
docker run -d --name=redis-7479 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/04/conf:/etc/redis/ \
-v /usr/local/redis-cluster/04/data:/data \
-v /usr/local/redis-cluster/04/logs:/var/log/redis \
-v /usr/local/redis-cluster/04:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7479 \
--cluster-enabled yes
docker run -d --name=redis-7480 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/05/conf:/etc/redis/ \
-v /usr/local/redis-cluster/05/data:/data \
-v /usr/local/redis-cluster/05/logs:/var/log/redis \
-v /usr/local/redis-cluster/05:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7480 \
--cluster-enabled yes
docker run -d --name=redis-7481 \
--privileged=true \
--network=host \
-v /usr/local/redis-cluster/06/conf:/etc/redis/ \
-v /usr/local/redis-cluster/06/data:/data \
-v /usr/local/redis-cluster/06/logs:/var/log/redis \
-v /usr/local/redis-cluster/06:/var/lib/redis \
redis \
redis-server /etc/redis/redis.conf \
--port 7481 \
--cluster-enabled yes
- –network=host: Appoint docker The network mode of the container is host, That is, using the host IP The port of ( So there's no need to specify docker Port mapping of )
- –port 7379: Specify the port at startup , covers redis.conf Configuration in
- –cluster-enabled yes: Use cluster mode , covers redis.conf Configuration in
Check the startup of the container
Use :docker ps, Check the startup of the container .
If it doesn't start successfully , Use docker logs redis-7379 View reasons , It is most likely that it is still a directory permission problem .
# Add permissions
chmod -R 777 /usr/local/redis-cluster
# Restart
docker restart redis-7379 redis-7380 redis-7381 redis-7479 redis-7480 redis-7481
Create clusters
May refer to :Redis Cluster configuration
Enter any one of redis Containers
docker exec -it redis-7379 bash
Carry out orders , Create clusters
redis-cli --cluster create \
--cluster-replicas 1 \
192.168.10.121:7379 \
192.168.10.121:7380 \
192.168.10.121:7381 \
192.168.10.121:7479 \
192.168.10.121:7480 \
192.168.10.121:7481
Pay attention to IP Replace address with docker The host machine IP Address
-–cluster-relicas: Number of cluster copies . Here is 1, yes 1 host 1 Slave mode , If set to 2( namely :2 Slave machine ) Will fail . Because there must be at least 3 Host computer , So set 2 Slave machine hour , Need at least 9 Nodes .
The last parameter lists all redis host IP Address and port number .
At this time , See the hint :
>>> 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.10.121:7480 to 192.168.10.121:7379
Adding replica 192.168.10.121:7481 to 192.168.10.121:7380
Adding replica 192.168.10.121:7479 to 192.168.10.121:7381
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7379
slots:[0-5460] (5461 slots) master
M: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7380
slots:[5461-10922] (5462 slots) master
M: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7381
slots:[10923-16383] (5461 slots) master
S: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7479
replicates b9d01d8aebea6c8cd68054393941bc53d87c0a47
S: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7480
replicates b9d01d8aebea6c8cd68054393941bc53d87c0a47
S: b9d01d8aebea6c8cd68054393941bc53d87c0a47 192.168.10.121:7481
replicates b9d01d8aebea6c8cd68054393941bc53d87c0a47
Can I set the above configuration? (type 'yes' to accept):
Input "yes" Can be confirmed . The system will prompt that you are configuring slot.
>>> 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.10.121:7379)
M: 895f2c3d8b6c0e3bc9098bbad66facd7334c7238 192.168.10.121:7379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 04667d8651e9e814c8280d0a20643a03eba25ea3 192.168.10.121:7479
slots: (0 slots) slave
replicates f84b5434235e5f942c174a587099e67ca480510c
S: e4156936afea6259dfff037a08e93cdf247d2c57 192.168.10.121:7480
slots: (0 slots) slave
replicates 895f2c3d8b6c0e3bc9098bbad66facd7334c7238
S: 12862ccc89946cb427de1c4fb3807c05526a6c66 192.168.10.121:7481
slots: (0 slots) slave
replicates 4e7f8030516953cc99485f12bd6e57cdef490f50
M: 4e7f8030516953cc99485f12bd6e57cdef490f50 192.168.10.121:7380
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: f84b5434235e5f942c174a587099e67ca480510c 192.168.10.121:7381
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.
Usually, it will be executed quickly .
Inspection cluster
redis-cli --cluster check 192.168.10.121:7379
You can view the slot Distribution .
Cluster use
Login cluster
redis-cli -c -p 7379
- -c: Log in as a cluster
- -p: You can execute any redis Node ip And port
After logging in , It can operate normally redis. Use :cluster nodes, You can view the cluster nodes :
127.0.0.1:7379> cluster nodes
04667d8651e9e814c8280d0a20643a03eba25ea3 192.168.10.121:[email protected] slave f84b5434235e5f942c174a587099e67ca480510c 0 1644680101000 3 connected
e4156936afea6259dfff037a08e93cdf247d2c57 192.168.10.121:[email protected] slave 895f2c3d8b6c0e3bc9098bbad66facd7334c7238 0 1644680100025 1 connected
895f2c3d8b6c0e3bc9098bbad66facd7334c7238 192.168.10.121:[email protected] myself,master - 0 1644680099000 1 connected 0-5460
12862ccc89946cb427de1c4fb3807c05526a6c66 192.168.10.121:[email protected] slave 4e7f8030516953cc99485f12bd6e57cdef490f50 0 1644680102054 2 connected
4e7f8030516953cc99485f12bd6e57cdef490f50 192.168.10.121:[email protected] master - 0 1644680101039 2 connected 5461-10922
f84b5434235e5f942c174a587099e67ca480510c 192.168.10.121:[email protected] master - 0 1644680100000 3 connected 10923-16383
Be careful : Master node 7379 The corresponding slave node is not necessarily 7479. It's automatically assigned by the system .
May refer to :Redis Cluster configuration
边栏推荐
- How to recover the information server and how to recover the server data [easy to understand]
- JDBC -- extract JDBC tool classes
- MySQL function
- Swift - enables textview to be highly adaptive
- Flume common commands and basic operations
- The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
- Summary of C language learning problems (VS)
- Experimental design - using stack to realize calculator
- Resnet+attention project complete code learning
- PXE startup configuration and principle
猜你喜欢
Reinforcement learning - learning notes 3 | strategic learning
Detailed structure and code of inception V3
Learn the memory management of JVM 02 - memory allocation of JVM
Implementing Yang Hui triangle with cyclic queue C language
Average lookup length when hash table lookup fails
Embedded software architecture design - message interaction
Pytoch implements tf Functions of the gather() function
Redis highly available sentinel cluster
Pytoch loads the initialization V3 pre training model and reports an error
Summary of C language learning problems (VS)
随机推荐
Matlab superpixels function (2D super pixel over segmentation of image)
Kotlin变量
Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
Kotlin流程控制、循环
只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
GPON other manufacturers' configuration process analysis
Anaconda creates a virtual environment and installs pytorch
Deep discussion on the decoding of sent protocol
MySQL index - extended data
Get the variable address of structure member in C language
Learn the memory management of JVM 03 - Method area and meta space of JVM
Pytoch through datasets Imagefolder loads datasets directly from files
Distributed solution - distributed session consistency problem
强化学习-学习笔记3 | 策略学习
Automated test lifecycle
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Solve the error 1045 of Navicat creating local connection -access denied for user [email protected] (using password
Summary of C language learning problems (VS)
IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
mysql拆分字符串做条件查询