Redis Cluster部署
一、机器规划
| 机器 IP | 节点角色 | 端口 |
|---|---|---|
| 192.168.71.149 | 主节点 1、从节点 2 | 7000、7001 |
| 192.168.71.172 | 主节点 2、从节点 3 | 7000、7001 |
| 192.168.71.173 | 主节点 3、从节点 1 | 7000、7001 |
redis版本:redis-7.0.15
二、部署(三台节点统一执行)
1. 安装依赖并编译 Redis
yum install -y gcc make wget
tar -zxvf redis-7.0.15.tar.gz -C /opt
cd /opt/redis-7.0.15
make && make install
2. 创建节点目录
mkdir -p /data/redis-cluster/{7000,7001}
3. 配置文件
cat > /data/redis-cluster/7000/redis.conf << EOF port 7000 daemonize yes dir /data/redis-cluster/7000 logfile /data/redis-cluster/7000/redis.log dbfilename dump.rdb appendonly yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 protected-mode no bind 0.0.0.0 requirepass Hybridcloud2025 masterauth Hybridcloud2025 EOF
cat > /data/redis-cluster/7001/redis.conf << EOF port 7001 daemonize yes dir /data/redis-cluster/7001 logfile /data/redis-cluster/7001/redis.log dbfilename dump.rdb appendonly yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 protected-mode no bind 0.0.0.0 requirepass Hybridcloud2025 masterauth Hybridcloud2025 EOF
4. 启动节点
redis-server /data/redis-cluster/7000/redis.conf
redis-server /data/redis-cluster/7001/redis.conf
# 检查是否启动
ps -ef | grep redis

三、任意一台机器执行:创建集群
redis-cli --cluster create \ 192.168.71.149:7000 \ 192.168.71.172:7000 \ 192.168.71.173:7000 \ 192.168.71.149:7001 \ 192.168.71.172:7001 \ 192.168.71.173:7001 \ --cluster-replicas 1 \ -a Hybridcloud2025
# 执行后,看到 Can I set the above configuration? 时,输入 yes 回车

# 验证集群
redis-cli -c -h 192.168.71.149 -p 7000 -a Hybridcloud2025 cluster nodes

# 关闭集群节点
redis-cli -p 7000 -a Hybridcloud2025 shutdown
redis-cli -p 7001 -a Hybridcloud2025 shutdown

浙公网安备 33010602011771号