linux redis-cluster ipv6方式

配置文件,具体字段的含义,可以参考其他文档。

1.单个文件的配置信息   redis_36380.conf

requirepass Paas_2024

port 36380

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile /data/paas/apps/aicache-redis/redis_36380.pid

loglevel notice

logfile "/data/paas/apps/aicache-redis/logs/redis36380.log"

databases 16


dbfilename dump.rdb

dir /data/paas/apps/aicache-redis/data


appendonly no

appendfilename "appendonly36380.aof"

appendfsync everysec


cluster-enabled yes
cluster-config-file nodes36380.conf
cluster-node-timeout 20000
cluster-announce-ip 2409:806a:5af0:2000::f8ac
cluster-announce-port 36380
cluster-announce-bus-port 46380
masterauth Paas_2024

这会看配置,才发现,timeout的值设置错了,想设置成20000的,结果,设置为了0。

 2.其余配置文件

将redis_36380.conf 复制6份,将对应端口都sed修改成对应的端口。

redis_36380.conf   -->ip1/ redis_36381.conf

redis_36380.conf   --> ip2/redis_36380.conf

redis_36380.conf   --> ip2/redis_36381.conf

redis_36380.conf   --> ip3/redis_36380.conf

redis_36380.conf   --> ip3/redis_36381.conf

3.各个redis都要启动

 cat start_redis.sh 
cd  /data/paas/apps/aicache-redis; bin/redis-server redis_36380.conf
echo "36380 start done"

cd  /data/paas/apps/aicache-redis36381; bin/redis-server redis_36381.conf
echo "36381 start done"

4.集群启动

# bin/redis-cli -a Paas_2024 --cluster create 2409:806a:5af0:2000::f8ab:36380 2409:806a:5af0:2000::f8ab:36381 2409:806a:5af0:2000::f8ac:36380 2409:806a:5af0:2000::f8ac:36381 2409:806a:5af0:2000::f8ad:36380 2409:806a:5af0:2000::f8ad:36381 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 2409:806a:5af0:2000::f8ac:36381 to 2409:806a:5af0:2000::f8ab:36380
Adding replica 2409:806a:5af0:2000::f8ad:36381 to 2409:806a:5af0:2000::f8ac:36380
Adding replica 2409:806a:5af0:2000::f8ab:36381 to 2409:806a:5af0:2000::f8ad:36380
M: 1097bc8e8953c143a199aee52b337958ebad5e0f 2409:806a:5af0:2000::f8ab:36380
   slots:[0-5460] (5461 slots) master
S: cced91f4c571c5f104bec2031713b912fd47b27a 2409:806a:5af0:2000::f8ab:36381
   replicates 10009e5750acfb4fdfea12fa4a5237119715129a
M: be9bef007066c620a158666c15d10403d9435a9a 2409:806a:5af0:2000::f8ac:36380
   slots:[5461-10922] (5462 slots) master
S: 4576bd5d5ab4815a73b4efbe9dd4a3db19fcca79 2409:806a:5af0:2000::f8ac:36381
   replicates 1097bc8e8953c143a199aee52b337958ebad5e0f
M: 10009e5750acfb4fdfea12fa4a5237119715129a 2409:806a:5af0:2000::f8ad:36380
   slots:[10923-16383] (5461 slots) master
S: d2d28e829fc2813988e43ac263c51b6e0d238270 2409:806a:5af0:2000::f8ad:36381
   replicates be9bef007066c620a158666c15d10403d9435a9a
Can I set the above configuration? (type 'yes' to accept): yes
>>> 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 2409:806a:5af0:2000::f8ab:36380)
M: 1097bc8e8953c143a199aee52b337958ebad5e0f 2409:806a:5af0:2000::f8ab:36380
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 10009e5750acfb4fdfea12fa4a5237119715129a 2409:806a:5af0:2000::f8ad:36380
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: be9bef007066c620a158666c15d10403d9435a9a 2409:806a:5af0:2000::f8ac:36380
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 4576bd5d5ab4815a73b4efbe9dd4a3db19fcca79 2409:806a:5af0:2000::f8ac:36381
   slots: (0 slots) slave
   replicates 1097bc8e8953c143a199aee52b337958ebad5e0f
S: cced91f4c571c5f104bec2031713b912fd47b27a 2409:806a:5af0:2000::f8ab:36381
   slots: (0 slots) slave
   replicates 10009e5750acfb4fdfea12fa4a5237119715129a
S: d2d28e829fc2813988e43ac263c51b6e0d238270 2409:806a:5af0:2000::f8ad:36381
   slots: (0 slots) slave
   replicates be9bef007066c620a158666c15d10403d9435a9a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[paas@vga2prdfootk8snew73 aicache-redis]$ bin/redis-cli -c -p 36380
127.0.0.1:36380> cluster info
NOAUTH Authentication required.
127.0.0.1:36380> auth Paas_2024
OK
127.0.0.1:36380> 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:5
cluster_stats_messages_ping_sent:62
cluster_stats_messages_pong_sent:75
cluster_stats_messages_meet_sent:4
cluster_stats_messages_sent:141
cluster_stats_messages_ping_received:73
cluster_stats_messages_pong_received:66
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:141
127.0.0.1:36380> cluster nodes
be9bef007066c620a158666c15d10403d9435a9a 2409:806a:5af0:2000::f8ac:36380@46380 master - 0 1702190517490 3 connected 5461-10922
10009e5750acfb4fdfea12fa4a5237119715129a 2409:806a:5af0:2000::f8ad:36380@46380 myself,master - 0 1702190510000 5 connected 10923-16383
4576bd5d5ab4815a73b4efbe9dd4a3db19fcca79 2409:806a:5af0:2000::f8ac:36381@46381 slave 1097bc8e8953c143a199aee52b337958ebad5e0f 0 1702190513000 4 connected
d2d28e829fc2813988e43ac263c51b6e0d238270 2409:806a:5af0:2000::f8ad:36381@46381 slave be9bef007066c620a158666c15d10403d9435a9a 0 1702190514482 6 connected
cced91f4c571c5f104bec2031713b912fd47b27a 2409:806a:5af0:2000::f8ab:36381@46381 slave 10009e5750acfb4fdfea12fa4a5237119715129a 0 1702190516488 5 connected
1097bc8e8953c143a199aee52b337958ebad5e0f 2409:806a:5af0:2000::f8ab:36380@46380 master - 0 1702190515485 1 connected 0-5460
127.0.0.1:36380> 

正常情况下,redis的三主三从,在资源不足的情况下,每个主机上装2个节点。

# bin/redis-cli -p 36381 cluster info
NOAUTH Authentication required.
[paas@vga2prdfootk8snew73 aicache-redis]$ bin/redis-cli -a Paas_2024 -p 36381 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
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:3
cluster_stats_messages_ping_sent:215
cluster_stats_messages_pong_sent:218
cluster_stats_messages_meet_sent:4
cluster_stats_messages_sent:437
cluster_stats_messages_ping_received:216
cluster_stats_messages_pong_received:219
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:437

5.验证集群

bin/redis-cli -a Paas_2024 -p 36381 --cluster check 2409:806a:5af0:2000::f8ac:36380

# bin/redis-cli -a Paas_2024 -p 36381 --cluster check 2409:806a:5af0:2000::f8ac:36380
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
2409:806a:5af0:2000::f8ac:36380 (be9bef00...) -> 0 keys | 5462 slots | 1 slaves.
2409:806a:5af0:2000::f8ab:36380 (1097bc8e...) -> 0 keys | 5461 slots | 1 slaves.
2409:806a:5af0:2000::f8ad:36380 (10009e57...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 2409:806a:5af0:2000::f8ac:36380)
M: be9bef007066c620a158666c15d10403d9435a9a 2409:806a:5af0:2000::f8ac:36380
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 1097bc8e8953c143a199aee52b337958ebad5e0f 2409:806a:5af0:2000::f8ab:36380
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 4576bd5d5ab4815a73b4efbe9dd4a3db19fcca79 2409:806a:5af0:2000::f8ac:36381
   slots: (0 slots) slave
   replicates 1097bc8e8953c143a199aee52b337958ebad5e0f
S: d2d28e829fc2813988e43ac263c51b6e0d238270 2409:806a:5af0:2000::f8ad:36381
   slots: (0 slots) slave
   replicates be9bef007066c620a158666c15d10403d9435a9a
M: 10009e5750acfb4fdfea12fa4a5237119715129a 2409:806a:5af0:2000::f8ad:36380
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: cced91f4c571c5f104bec2031713b912fd47b27a 2409:806a:5af0:2000::f8ab:36381
   slots: (0 slots) slave
   replicates 10009e5750acfb4fdfea12fa4a5237119715129a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 6.高可用测试

6.1此时,若f8ac:36380主节点宕机,看master是否会漂移

6.2集群信息变更为

6.3重新将节点启动

6.4检查集群状态 

 

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要安装 Redis Cluster,可以编写一个 Shell 脚本来自动化安装过程。以下是一个示例脚本: ```shell #!/bin/bash # 下载 Redis wget http://download.redis.io/releases/redis-6.2.1.tar.gz tar xzf redis-6.2.1.tar.gz cd redis-6.2.1 # 编译 Redis make # 复制 Redis 可执行文件到 /usr/local/bin sudo cp src/redis-cli src/redis-server /usr/local/bin # 创建 Redis Cluster 目录 sudo mkdir /var/lib/redis-cluster # 配置 Redis Cluster 节点 for port in {7000..7005}; do sudo mkdir -p /var/lib/redis-cluster/$port sudo cp redis.conf /var/lib/redis-cluster/$port/ sudo sed -i "s/port 6379/port $port/" /var/lib/redis-cluster/$port/redis.conf sudo sed -i "s/# cluster-enabled yes/cluster-enabled yes/" /var/lib/redis-cluster/$port/redis.conf sudo sed -i "s/# cluster-config-file nodes-6379.conf/cluster-config-file nodes-$port.conf/" /var/lib/redis-cluster/$port/redis.conf sudo sed -i "s/# cluster-node-timeout 15000/cluster-node-timeout 5000/" /var/lib/redis-cluster/$port/redis.conf done # 启动 Redis Cluster 节点 for port in {7000..7005}; do redis-server /var/lib/redis-cluster/$port/redis.conf --daemonize yes done # 创建 Redis Cluster yes | redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1 # 清理安装文件 cd .. rm -rf redis-6.2.1 redis-6.2.1.tar.gz ``` 将以上脚本保存为 `install_redis_cluster.sh`,然后在终端中运行以下命令来执行脚本: ```shell chmod +x install_redis_cluster.sh ./install_redis_cluster.sh ``` 脚本将会下载、编译和配置 Redis,然后启动 Redis Cluster 节点,并创建 Redis Cluster。 请注意,此脚本仅适用于安装 Redis 6.2.1 版本的 Redis Cluster。如需安装其他版本,请根据具体情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值