嚣张研究站呀 · 2021年11月14日 0

redis单机集群

1、安装gcc套装:

此图片的alt属性为空;文件名为image.png

yum install cpp

 yum install binutils

yum install glibc

yum install glibc-kernheaders

yum install glibc-common

yum install glibc-devel

yum install gcc

 yum install make

2、升级gcc

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

3、安装redis:

wget http://download.redis.io/releases/redis-6.0.3.tar.gz

tar xzf redis-6.0.3.tar.gz

cd redis-6.0.3

make

make PREFIX=/usr/local/redis install

4、启动redis  cd到bin目录

[root@VM-55fbfec9-2204-4954-90b1-67271ee7c4b0 bin]# ./redis-server redis.conf ./redis-cli [root@VM-55fbfec9-2204-4954-90b1-67271ee7c4b0 bin]# [root@VM-55fbfec9-2204-4954-90b1-67271ee7c4b0 bin]# redis-cli 127.0.0.1:6379> ping PONG

5.修改创建配置文件 至6个

#port 6380

#dbfilename “dump6380.rdb”

#cluster-enabled yes

 #cluster-config-file node-6380.conf

#cluster-node-timeout 15000

6.启动6个实例

./redis-server  ../redis7001.conf(6次)

查看实例进程:

7.创建集群:

[root@VM-55fbfec9-2204-4954-90b1-67271ee7c4b0 bin]# ./redis-cli –cluster create 10.228.76.52:7001 10.228.76.52:7002 10.228.76.52:7003 10.228.76.52:7004 10.228.76.52:7005 10.228.76.52:7006 –cluster-replicas 1 -a gvrkgUd6

  • a参数为密码  要远程使用集群注意 创建的ip(可设置为远程ip)及密码 (为了安全记得加密码) 记得在防火墙开启端口

查看集群:

[root@localhost bin]# ./redis-cli -a gvrkgUd6 -c -p 7001

Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.

127.0.0.1:7001> ping

PONG

127.0.0.1:7001> cluster nodes

a88722e6c714b9fc396a9805b8e69c63a7fb7853 10.228.76.52:7006@17006 slave 283c1bfb3c4bb701946bbb7ebf4d0f5878ddcffb 0 1636591386000 6 connected

283c1bfb3c4bb701946bbb7ebf4d0f5878ddcffb 10.228.76.52:7001@17001 myself,master – 0 1636591385000 1 connected 0-5460

35a3d41c3149cd3ea560949c18e35ddb701da22a 10.228.76.52:7003@17003 master – 0 1636591387190 3 connected 10923-16383

f3ce9e7bb5f9270dc95eae75c7d16739189c1692 10.228.76.52:7005@17005 slave 35a3d41c3149cd3ea560949c18e35ddb701da22a 0 1636591384000 5 connected

21db14b2d8e5ba8ac250f04c2ad2a23dacd796d3 10.228.76.52:7002@17002 master – 0 1636591385183 2 connected 5461-10922

5fe3141e0197c8d0c4cb7bb52dcbf0db86b33460 10.228.76.52:7004@17004 slave 21db14b2d8e5ba8ac250f04c2ad2a23dacd796d3 0 1636591386187 4 connected

127.0.0.1:7001>