部署redis集群

2022/8/1 2:23:25

本文主要是介绍部署redis集群,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.redis部署

版本:6.2.7

集群:6个节点(redis集群至少3个节点)

2. 创建集群目录:

mkdir /opt/redis-cluster

3. 创建redis单实例目录:

mkdir -p /opt/redis-cluster/redis01
mkdir -p /opt/redis-cluster/redis02
mkdir -p /opt/redis-cluster/redis03
mkdir -p /opt/redis-cluster/redis04
mkdir -p /opt/redis-cluster/redis05
mkdir -p /opt/redis-cluster/redis06

4.修改redis配置文件redis.conf

#bind 127.0.0.1 -::1protected-mode no

requirepass Tiye@123!
daemonize yes
cluster-enabled yes
port 6691

5.将redis的bin目录下的redis-benchmark 、 redis-check-aof、 redis-check-rdb、 redis-cli、 redis-sentinel 、 redis-server拷贝至redis01、redis02、redis03、redis04、redis05、redis06路径下

6.将redis.conf拷贝至redis01、redis02、redis03、redis04、redis05、redis06路径下

7.分别修改redis01、redis02、redis03、redis04、redis05、redis06路径下redis.conf文件,端口依次设置如下:

port 6691、port 6692、port 6693、port 6694、port 6695、port 6696

8.创建启动脚本 startup.sh(/opt/redis-cluster/路径下)。如下:

#!/bin/bash

cd /opt/redis-cluster/redis01
nohup ./redis-server /opt/redis-cluster/redis01/redis.conf &

cd /opt/redis-cluster/redis02
nohup ./redis-server /opt/redis-cluster/redis02/redis.conf &

cd /opt/redis-cluster/redis03
nohup ./redis-server /opt/redis-cluster/redis03/redis.conf &

cd /opt/redis-cluster/redis04
nohup ./redis-server /opt/redis-cluster/redis04/redis.conf &

cd /opt/redis-cluster/redis05
nohup ./redis-server /opt/redis-cluster/redis05/redis.conf &

cd /opt/redis-cluster/redis06
nohup ./redis-server /opt/redis-cluster/redis06/redis.conf &

9.启动服务:

./startup.sh

10.创建redis集群:

./redis-cli --cluster create 192.168.0.163:6691 192.168.0.163:6692 192.168.0.163:6693 192.168.0.163:6694 192.168.0.163:6695 192.168.0.163:6696 --cluster-replicas 1 -a Tiye@123!

注:192.168.0.163为主机IP。Tiye@123!为密码。

11.访问集群:

./redis-cli -h 192.168.0.163 -p 6691 -c -a Tiye@123!

注:-c 以集群方式登陆,cluster。-a 密码,authority



这篇关于部署redis集群的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程