redis集群部署<create-cluster官方脚本版>

redis cluster部署<通过create-cluster脚本>

  • redis cluster部署<通过create-cluster脚本>
    • redis资源清单
    • 解压redis并安装
    • 修改utils/create-cluster下的集群配置文件
    • 启动redis
    • 创建redis集群
    • 查看redis集群节点详情

redis资源清单

服务器A 服务器B 服务器C
10.49.253.25 10.49.253.40 10.49.153.31

解压redis并安装

tar -xvf redis-5.0.7.tar.gz 
mv redis-5.0.7 redis
cd redis
make
make install

修改utils/create-cluster下的集群配置文件

PORT=30000     #启动的端口
TIMEOUT=2000   #超时时间
NODES=2        #2节点一主一从
REPLICAS=1     #主节点数


# start---> 修改
# 在redis-server 后添加--bind 10.49.253.25 --masterauth pwd1234 --requirepass pwd1234 
../../src/redis-server --port $PORT --bind 10.49.253.25 --masterauth pwd1234 --requirepass pwd1234 --protected-mode no --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes


# create---> 修改 添加要配置的redis集群的机器ip根据配置的port+1、+2(PORT=30000)
HOSTS="10.49.253.25:30001 10.49.253.25:30002 10.49.253.40:30001 10.49.253.40:30002 10.49.253.31:30001 10.49.253.31:30002"
# 注释这一部分
    #while [ $((PORT < ENDPORT)) != "0" ]; do
    #    PORT=$((PORT+1))
    #    HOSTS="$HOSTS 10.49.253.25:$PORT"
    #done
# 在redis-cli 后面添加集群密码
../../src/redis-cli -a pwd1234 --cluster create $HOSTS --cluster-replicas $REPLICAS

# stop ---> 修改 redis-cli后面添加-h 10.49.253.25 -a pwd1234
../../src/redis-cli -h 10.49.253.25 -p $PORT -a pwd1234 shutdown nosave

redis的集群配置文件中create参数只在第一台25节点上修改,其他服务器不需要修改
–bind参数为绑定IP地址
–masterauth --requirepass 参数为集群设置的授权密码

启动redis

# 3台服务器分别启动redis
./create-cluster start

创建redis集群

#在25节点上操作
./create-cluster create

查看redis集群节点详情

# 登录redis-cli 输入auth后输入CLUSTER NODES
10.49.253.25:30001> cluster nodes
1e0e9a9218d9866716d04871f88f00d9ca264174 10.49.253.25:30002@40002 slave 85569aa4f3f89ecefac43634b4993ba823c8a863 0 1683537250413 5 connected
c325181fbccb8cdcf502faaf1a0a588f1d38d8dd 10.49.253.40:30002@40002 slave 23456269745c6ff08defa5322e9464e9f87801a2 0 1683537250815 4 connected
85569aa4f3f89ecefac43634b4993ba823c8a863 10.49.253.31:30001@40001 master - 0 1683537251216 5 connected 10923-16383
222d246eb0b499b2f8878c19617d689f41a722dc 10.49.253.31:30002@40002 slave 0a393d60482e054645030620b5f2d80f6735ecb5 0 1683537250715 6 connected
23456269745c6ff08defa5322e9464e9f87801a2 10.49.253.25:30001@40001 myself,master - 0 1683537250000 1 connected 0-5460
0a393d60482e054645030620b5f2d80f6735ecb5 10.49.253.40:30001@40001 master - 0 1683537251014 3 connected 5461-10922

查看CLUSTER NODES后显示了6条数据,和规划的一致3主3从集群

你可能感兴趣的:(运维,redis,数据库,缓存)