redis6.x cluster集群部署

系统:centos 7.9 64bit

redis:6.12

准备工作

yum install gcc gcc-c++ make  #安装编译软件
cd /usr/local/src

wget https://download.redis.io/releases/redis-6.2.1.tar.gz?_ga=2.92397789.1507039917.1614738531-166516213.1614738531   #下载redis
tar xzvf redis-6.2.1.tar.gz\?_ga\=2.92397789.1507039917.1614738531-166516213.1614738531                                #解压redis

cd redis-6.2.1
make                       #编译
make install               #安装

如果编译报错,请按下方方法操作 (未测试,我自己编译未出现报错现象) 转自: http://t.zoukankan.com/wangjinyu-p-13469409.html

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
sudo scl enable devtoolset-9 bash
注意:scl命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。如果要长期生效的话,执行如下

sudo echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
source /etc/profile

创建配置文件路径及拷贝配置文件,cluster至少需要6个节点,设置端口未6379--6384

[root@k8s redis-6.2.1]# pwd
/usr/local/src/redis-6.2.1

mkdir /etc/redis
cp redis.conf  /etc/redis/redis6379.conf
cp redis.conf  /etc/redis/redis6380.conf
cp redis.conf  /etc/redis/redis6381.conf
cp redis.conf  /etc/redis/redis6382.conf
cp redis.conf  /etc/redis/redis6383.conf
cp redis.conf  /etc/redis/redis6384.conf

修改配置文件,以下为需要修改的配置项,每个配置文件端口需根据实际端口修改

vim /etc/redis/redis6379.conf
bind 192.168.11.128 #6节点都一致 port 6379 #根据实际端口修改 daemonize yes #开启守护模式 protected-mode no #关闭保护模式
requirepass 123456 #设置密码123456 cluster
-enabled yes #开启集群 cluster-config-file nodes-6379.conf #配置集群端口配置(启动集群后会自动生成) #其他配置项可根据实际情况修改,本次实验略过..

依次启动6个redis节点,直接执行脚本即可启动

#!/bin/bash

port=(6379 6380 6381 6382 6383 6384)

for i in ${port[*]}
do
/usr/local/bin/redis-server /etc/redis/redis${i}.conf
done

以下启动完成之后的样子

 

 

 

创建集群,3个主节点,每个主节点分别有1个从节点,共计6个节点

redis-cli --cluster create 192.168.11.128:6379 192.168.11.128:6380 192.168.11.128:6381 192.168.11.128:6382 192.168.11.128:6383 192.168.11.128:6384 --cluster-replicas 1 -a 123456

 

 

 

 

登录集群, 需增加 -c选项才是登录集群.

redis-cli -c -p 6379 -h 192.168.11.128 

 

posted @ 2021-03-03 17:29  Buster_Hsueh  阅读(362)  评论(0编辑  收藏  举报