赞
踩
哨兵模式提高了系统的可用性
哨兵模式中,本质上还是 redis 主/从节点(内存,256G,512G.上 TB 的服务器也不是没有(贵))存储数据,其中就要求一个主节点/从节点,就得存储整个数据的"全集
- for port in $(seq 1 9); \
- do \
- mkdir -p redis${port}/
- touch redis${port}/redis.conf
- cat << EOF > redis${port}/redis.conf
- port 6379
- bind 0.0.0.0
- protected-mode no
- appendonly yes
- cluster-enabled yes
- cluster-config-file nodes.conf
- cluster-node-timeout 5000
- cluster-announce-ip 172.30.0.10${port}
- cluster-announce-port 6379
- cluster-announce-bus-port 16379
- EOF
- done
- # 注意 cluster-announce-ip 的值有变化.
- for port in $(seq 10 11); \
- do \
- mkdir -p redis${port}/
- touch redis${port}/redis.conf
- cat << EOF > redis${port}/redis.conf
- port 6379
- bind 0.0.0.0
- protected-mode no
- appendonly yes
- cluster-enabled yes
- cluster-config-file nodes.conf
- cluster-node-timeout 5000
- cluster-announce-ip 172.30.0.1${port}
- cluster-announce-port 6379
- cluster-announce-bus-port 16379
- EOF
- done
编写 docker-compose.yml
version: '3.3' networks: mynet: ipam: config: - subnet: 172.30.0.0/24 services: redis1: image: 'redis:5.0.9' container_name: redis1 restart: always volumes: - ./redis1/:/etc/redis/ ports: - 6371:6379 - 16371:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.101 redis2: image: 'redis:5.0.9' container_name: redis2 restart: always volumes: - ./redis2/:/etc/redis/ ports: - 6372:6379 - 16372:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.102 redis3: image: 'redis:5.0.9' container_name: redis3 restart: always volumes: - ./redis3/:/etc/redis/ ports: - 6373:6379 - 16373:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.103 redis4: image: 'redis:5.0.9' container_name: redis4 restart: always volumes: - ./redis4/:/etc/redis/ ports: - 6374:6379 - 16374:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.104 redis5: image: 'redis:5.0.9' container_name: redis5 restart: always volumes: - ./redis5/:/etc/redis/ ports: - 6375:6379 - 16375:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.105 redis6: image: 'redis:5.0.9' container_name: redis6 restart: always volumes: - ./redis6/:/etc/redis/ ports: - 6376:6379 - 16376:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.106 redis7: image: 'redis:5.0.9' container_name: redis7 restart: always volumes: - ./redis7/:/etc/redis/ ports: - 6377:6379 - 16377:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.107 redis8: image: 'redis:5.0.9' container_name: redis8 restart: always volumes: - ./redis8/:/etc/redis/ ports: - 6378:6379 - 16378:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.108 redis9: image: 'redis:5.0.9' container_name: redis9 restart: always volumes: - ./redis9/:/etc/redis/ ports: - 6379:6379 - 16379:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.109 redis10: image: 'redis:5.0.9' container_name: redis10 restart: always volumes: - ./redis10/:/etc/redis/ ports: - 6380:6379 - 16380:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.110 redis11: image: 'redis:5.0.9' container_name: redis11 restart: always volumes: - ./redis11/:/etc/redis/ ports: - 6381:6379 - 16381:16379 command: redis-server /etc/redis/redis.conf networks: mynet: ipv4_address: 172.30.0.111
1)生成每个 redis 节点的配置文件
2)使用 docker 创建出 11 个 redis 节点, 并且启动容器
3)使用 redis-cli 执行构建集群命令
redis-cli --cluster create 172.30.0.101:6379 172.30.0.102:6379 172.30.0.103:6379 172.30.0.104:6379 172.30.0.105:6379 172.30.0.106:6379 172.30.0.107:6379 172.30.0.108:6379 172.30.0.109:6379 --cluster-replicas 2
101-1099个主机,构成了3主,6 从结构的集群了
110 和 111 也加入到集群中
以110为 master, 111为 slave.=>把数据分片从 3->4
集群扩容操作,是一件风险较高,成本较大的操作!!!
redis-cli --cluster add-node 172.30.0.110:6379 172.30.0.101:6379
redis-cli --cluster reshard 172.30.0.101:6379
redis-cli --cluster add-node 172.30.0.111:6379 172.30.0.101:6379 --cluster-slave --cluster-master-id c999d6e82415680b57868cc3c59f9f1a779a59cd
把一些节点拿掉,减少分片的数量,
般都是进行扩容,很少缩容!
1)集群是什么,解决了什么问题?
2)数据分片算法[重点/考点]
a)哈希求余
b)一致性哈希算法
c)哈希槽分区算法(redis)
3)搭建 redis 集群,
4)集群容灾.故障转移
5)集群扩容.
6)代码连接集群
使用的库, 得能够支持 集群模式.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。