标签:style mode conf add text amr ping 数据卷 creat
1、节点规划 (3 master 3 node)
ip | port | cpu/mem | data-volume |
192.168.40.132 |
7000 7003 |
4C & 8G |
/var/lib/redis/7000 /var/lib/redis/7003 |
192.168.40.133 |
7001 7004 |
4C & 8G |
/var/lib/redis/7001 /var/lib/redis/7004 |
192.168.40.134 |
7002 7005 |
4C & 8G |
/var/lib/redis/7002 /var/lib/redis/7005 |
2、创建数据卷挂载目录、准备redis配置文件
提前创建好用于存储 Redis 的配置文件和持久化数据的目录:
192.168.40.132:
$ mkdir -p /var/lib/redis/7000 & mkdir -p /var/lib/redis/7003 ## 7000 端口配置文件 $ cat > /var/lib/redis/7000/redis.conf << EOF port 7000 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF ## 7003 端口配置文件 $ cat > /var/lib/redis/7003/redis.conf << EOF port 7003 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF
192.168.40.133:
$ mkdir -p /var/lib/redis/7001 & mkdir -p /var/lib/redis/7004 ## 7001 端口配置:redis.conf $ cat > /var/lib/redis/7001/redis.conf << EOF port 7001 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF ## 7004 端口配置:redis-7004.conf $ cat > /var/lib/redis/7004/redis.conf << EOF port 7004 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF
192.168.40.134:
$ mkdir -p /var/lib/redis/7002 & mkdir -p /var/lib/redis/7005 ## 7002 端口配置:redis-7002.conf $ cat > /var/lib/redis/7002/redis.conf << EOF port 7002 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF ## 7005 端口配置:redis-7005.conf $ cat > /var/lib/redis/7005/redis.conf << EOF port 7005 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly yes daemonize no protected-mode no pidfile /data/redis.pid EOF
3、 准备redis镜像
$ docker pull redis:6.0.8
4、运行redis
不同服务器间的 Docker 是不能相互通信的,所有这里我们设置启动的容器网络模式为 host 模式,这样容器不会创建虚拟网卡,而是使用宿主机的网络。
--cpus:指定容器使用 CPU 数量; --memory:限制容器使用内存数量; --memory-swap:指定交换内存大小,这里设置为 0,即不用交换内存; --restart:指定 Docker 重启时容器的重启策略; --privileged:设置容器拥有特权,能够获取宿主机 Root 权限;
132:
## 运行 Redis 镜像 7000 端口 $ docker run -d -v /var/lib/redis/7000:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7000 redis:6.0.8 redis-server /data/redis.conf ## 运行 Redis 镜像 7003 端口 $ docker run -d -v /var/lib/redis/7003:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7003 redis:6.0.8 redis-server /data/redis.conf
133:
## 运行 Redis 镜像 7001 端口 $ docker run -d -v /var/lib/redis/7001:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7001 redis:6.0.8 redis-server /data/redis.conf ## 运行 Redis 镜像 7004端口 $ docker run -d -v /var/lib/redis/7004:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7004 redis:6.0.8 redis-server /data/redis.conf
134:
## 运行 Redis 镜像 7002 端口 $ docker run -d -v /var/lib/redis/7002:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7002 redis:6.0.8 redis-server /data/redis.conf ## 运行 Redis 镜像 7005 端口 $ docker run -d -v /var/lib/redis/7005:/data --cpus=1 --memory=2GB --memory-swap=0 --privileged=true --restart=always --net host --name redis-7005 redis:6.0.8 redis-server /data/redis.conf
5、组建集群
随意进入一台服务器,使用 Redis 镜像的 redis-cli 工具执行创建集群命令使各个 Redis 组成集群,这里本人进入第一台服务器 132
中,使用端口为 7000
的 Redis
端镜像
docker exec -it redis-7000 > redis-cli -p 7000 --cluster create > 192.168.40.132:7000 192.168.40.133:7001 192.168.40.134:7002 > 192.168.40.132:7003 192.168.40.133:7004 192.168.40.134:7005 > --cluster-replicas 1
>>> 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.40.133:7004 to 192.168.40.132:7000 Adding replica 192.168.40.134:7005 to 192.168.40.133:7001 Adding replica 192.168.40.132:7003 to 192.168.40.134:7002
...... [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
注解:
-p:指定连接 Redis 的端口; create:创建 Redis 集群; --cluster:使用 Redis 集群模式命令; --cluster-replicas:指定副本数(slave 数量);
6、查看集群相关信息
进入 Redis 镜像内部并折佣 redis-cli 命令:
$ docker exec -it redis-7000 redis-cli -p 7000 -c
注解:
-p:指定连接 Redis 的端点; -c:使用集群模式;
查看集群信息和节点
127.0.0.1:7000> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:162 cluster_stats_messages_pong_sent:184 cluster_stats_messages_sent:346 cluster_stats_messages_ping_received:179 cluster_stats_messages_pong_received:162 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:346 127.0.0.1:7000> cluster nodes 6101927bd2e2288ec7735a1dae692adcd015043a 192.168.40.133:7001@17001 master - 0 1613226764000 2 connected 5461-10922 e7b0d3c7c22efba297437b5497d855fb82b4d081 192.168.40.133:7004@17004 slave 6f477781eae7f94815e76aaa7e6ef786f00f36df 0 1613226765000 1 connected 10314487caa3ec6821d4d15e28f3f7e924bd4857 192.168.40.134:7005@17005 slave 6101927bd2e2288ec7735a1dae692adcd015043a 0 1613226765548 2 connected a625b7fb99fbff73a08a9880ca96203efb8905bd 192.168.40.132:7003@17003 slave 808ed4710f6eb214d03785375645ba5951c7686c 0 1613226764000 3 connected 808ed4710f6eb214d03785375645ba5951c7686c 192.168.40.134:7002@17002 master - 0 1613226765549 3 connected 10923-16383 6f477781eae7f94815e76aaa7e6ef786f00f36df 192.168.40.132:7000@17000 myself,master - 0 1613226763000 1 connected 0-5460
https://blog.csdn.net/a1041646584/article/details/107209783 大佬文章
https://mp.weixin.qq.com/s/Eyp0zo2Pgkc5sE_aqK1wXw 7000字 Redis 超详细总结笔记 !
https://mp.weixin.qq.com/s/CugJOaMRLArihsra2uWt7g 详细必看
redis进阶 https://www.cnblogs.com/ZhuChangwu/p/13697951.html
https://www.jianshu.com/p/8e1ed39fdab3
https://blog.csdn.net/qq_22937623/article/details/107523383
https://www.liuname.xyz/archives/977/ 主从
https://www.jianshu.com/p/eb430761f740 哨兵
https://www.cnblogs.com/doufy/p/12066866.html 容器版主从、哨兵
主从、哨兵、集群
容器版
二进制版
https://blog.csdn.net/as4589sd/article/details/108855399?utm_source=app Redis Cluster主从模式
标签:style mode conf add text amr ping 数据卷 creat
原文地址:https://www.cnblogs.com/zjz20/p/13588458.html