Download mirror

(This is mukewang’s always packaged, ready to use)

[root@localhost ~]# docker pull yyyyttttwwww/redis # rename [root@localhost ~]# docker tag yyyyttttwwww/redis redis [root@localhost ~]# docker rmi-fyyyyttttwwww /redisCopy the code

Example Create a NET2 network segment

(My mysql cluster uses net1, so I’ll use a new network segment.)

[root@localhost ~]# docker network create --subnet=172.19.0.0/16 net2
Copy the code

Create a 6-node Redis container

[root@localhost ~]# docker run it -d --name r1 -p 5001:6379 --net=net2 -- IP 172.19.0.2 redis bash [root@localhost ~]# Docker run -d --name r2 -p 5002:6379 --net=net2 -- IP 172.19.0.3 redis bash [root@localhost ~]# docker run -d --name r3 -p 5003:6379 --net=net2 -- IP 172.19.0.4 redis bash [root@localhost ~]# docker run it -d --name r4-p 5004:6379 --net=net2 -- IP 172.19.0.5 redis bash [root@localhost ~]# docker run it -d --name r5 -p 5005:6379 --net=net2 -- IP 172.19.0.6 redis bash [root@localhost ~]# docker run it -d --name r6 -p 5006:6379 --net=net2 -- IP 172.19.0.7 redis  bashCopy the code

Enter node R1 (and so on for the following nodes)

[root@localhost ~]# docker exec -it r1 bash
Copy the code

Configure the Redis node

Daemonize yes # enable cluster 721 cluster-enabled yes # enable cluster configuration file 729 cluster-config-file node-6379.conf Appendonly Yes # enable AOF (persistent mode, available for restoration) appendOnly YesCopy the code

Use the editor to edit, compare the above edit (because this is already wrapped, basically do not need to change)

root@1f6a080bff27:/# vi /usr/redis/redis.conf
Copy the code

Enter the editing area and use the inclined bar to find the contents of the sample. Then change the value of /daemonize to the meaning of and above. Enter :wq to exit.

Enter the directory

Look for the root directory @ # 1 f6a080bff27: # / CD/usr/redis/SRC start root @ # 1 f6a080bff27: / usr/redis/src# / redis - server.. / redis. Conf exit vessel root @ 1 f6a080bff27: / usr/redis/src# exitCopy the code

Perform the same operations for other node mirroring.

Create cluster (this image is already written in Ruby script, so just run the command)

[root@localhost ~]# docker exec -it r1 bash root@1f6a080bff27:/# cd /usr/redis/ root@1f6a080bff27:/usr/redis# mkdir cluster root@1f6a080bff27:/usr/redis# cd src root@1f6a080bff27:/usr/redis/src# cp redis-trib.rb .. / cluster root @ 1 f6a080bff27: / usr/redis/src# / redis - trib. Rb create -- replicas 172.19.0.2:1 6379 172.19.0.3:6379 172.19.0.4:6379 172.19.0.5:6379 172.19.0.6:6379 172.19.0.7:6379Copy the code

After performing

After typing yes, you will see that the following is successful. After success, the exit command exits the R1 container

Test installation results

Test it again (using the Redis visual client, of course)

[root@localhost ~]# docker exec -it r1 bash # connect cluster root@1f6a080bff27:/# /usr/redis/src/redis-cli -c 127.0.0.1:6379> set Name Zhangxiaoxiang -> Redirected to slot [5798] located at 172.19.0.3:6379 OK 172.19.0.3:6379> get name "Zhangxiaoxiang 172.19.0.3:6379 >Copy the code

Explain (127.0.0.1:6379> info check version info, this is 3.2.3, not very new)