Centos7安装redis-cluster集群(6.2.3)

1、redis下载地址:

https://redis.io/download

2、升级gcc版本
centos7.6默认安装gcc版版本为4.8.5,由于redis6需要gcc-5.3及以上所以升级gcc版本到9.3

yum install centos-release-scl devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils -y
// 临时有效,退出 shell 或重启会恢复原 gcc 版本
sudo scl enable devtoolset-9 bash
// 长期有效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
source /etc/profile
gcc -v

3、编译安装redis

https://download.redis.io/releases/redis-6.2.3.tar.gz
tar zxf redis-6.2.3.tar.gz -C /data/
cd /data/redis-6.2.3-cluster
make
nohup /data/redis-6.2.3-cluster/src/redis-server /data/redis-6.2.3-cluster/redis.conf &

/data/redis-6.0.7/src/redis-cli
127.0.0.1:6379> set testKey aaa
OK
127.0.0.1:6379> get testKey
"aaa"
127.0.0.1:6379> quit

4、配置redis-cluster集群
4.1、主机规划(每台服务器三个redis节点 一主两从)

10.255.49.63
10.255.49.64
10.255.49.65
10.255.49.66
10.255.49.67

4.2、端口规划

6000 master
6001 slave 
6002 slave

4.3、每台服务器上传三个配置文件

cd /data/redis-6.2.3-cluster/
mkdir cluster && cd cluster
mkdir 6000 6001 6002

4.4、配置文件内容如下

cat 6000/redis.conf
bind 0.0.0.0
protected-mode no
port 6002
tcp-backlog 511
timeout 300
tcp-keepalive 300
daemonize no
pidfile /data/redis-6.2.3-cluster/cluster/6002/redis_6002.pid
loglevel notice
logfile "/data/redis-6.2.3-cluster/cluster/6002/redis-6002.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis-6.2.3-cluster/cluster/6002
masterauth cloud_redis_zte
requirepass cloud_redis_zte
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
maxclients 10000
maxmemory 20gb
maxmemory-policy allkeys-lru
maxmemory-samples 10
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-6002.conf
cluster-node-timeout 30000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes

4.5、启动所有节点的redis

sh start-all-redis.sh

cat start-all-redis.sh
#!/bin/bash

redis_server=/data/redis-6.2.3-cluster
redis_conf=/data/redis-6.2.3-cluster/cluster
prot1=6000
prot2=6001
prot3=6002

#启动redis
$redis_server/src/redis-server $redis_conf/$prot1/redis.conf &
sleep 2
$redis_server/src/redis-server $redis_conf/$prot2/redis.conf &
sleep 2
$redis_server/src/redis-server $redis_conf/$prot3/redis.conf &

4.6、创建集群

/data/redis-6.2.3-cluster/src/redis-cli -a 'cloud_redis_zte' --cluster create 10.255.49.63:6000 10.255.49.63:6001 10.255.49.63:6002 10.255.49.64:6000 10.255.49.64:6001 10.255.49.64:6002 10.255.49.65:6000 10.255.49.65:6001 10.255.49.65:6002 10.255.49.66:6000 10.255.49.66:6001 10.255.49.66:6002 10.255.49.67:6000 10.255.49.67:6001 10.255.49.67:6002 --cluster-replicas 2
#--cluster-replicas 2 创建一主两从

4.7、检查集群状态

/data/redis-6.2.3-cluster/src/redis-cli -a 'cloud_redis_zte' --cluster check 10.255.49.63:6000
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.255.49.63:6000 (e14f0060...) -> 0 keys | 3277 slots | 2 slaves.
10.255.49.65:6000 (5c2af3af...) -> 0 keys | 3276 slots | 2 slaves.
10.255.49.67:6000 (0f4630d2...) -> 0 keys | 3277 slots | 2 slaves.
10.255.49.66:6000 (c7bfc594...) -> 0 keys | 3277 slots | 2 slaves.
10.255.49.64:6000 (f3695d7e...) -> 0 keys | 3277 slots | 2 slaves.
[OK] 0 keys in 5 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.255.49.63:6000)
M: e14f0060d9e1022cdd34c52bd814c712555bf52a 10.255.49.63:6000
   slots:[0-3276] (3277 slots) master
   2 additional replica(s)
S: dc0234ce813e914b90ecc4f5dbff990eaa3d3edc 10.255.49.63:6002
   slots: (0 slots) slave
   replicates 5c2af3afcb1f5ee1fafc960a6358280b4652a4f3
S: 75a6fc5a5a9ee5c75f8a6a649f31ed15634f0f17 10.255.49.64:6001
   slots: (0 slots) slave
   replicates e14f0060d9e1022cdd34c52bd814c712555bf52a
S: fdd95918147157c80426a1c6c0cb10cfe2db1a98 10.255.49.65:6002
   slots: (0 slots) slave
   replicates c7bfc594c73bc69c0ceb60fb74aabc85693039ff
S: d6ec594026c6c2c27176764c9e4202a3e6e89fc1 10.255.49.65:6001
   slots: (0 slots) slave
   replicates e14f0060d9e1022cdd34c52bd814c712555bf52a
S: 858421285ee77c736e6e36a9b3d507f7ab646f1f 10.255.49.64:6002
   slots: (0 slots) slave
   replicates 5c2af3afcb1f5ee1fafc960a6358280b4652a4f3
M: 5c2af3afcb1f5ee1fafc960a6358280b4652a4f3 10.255.49.65:6000
   slots:[6554-9829] (3276 slots) master
   2 additional replica(s)
S: f5e4b5b795231a1cbd160f09ffa060ea1b55505f 10.255.49.63:6001
   slots: (0 slots) slave
   replicates 0f4630d2726851c5581d18ecd7165b05c14ce955
M: 0f4630d2726851c5581d18ecd7165b05c14ce955 10.255.49.67:6000
   slots:[13107-16383] (3277 slots) master
   2 additional replica(s)
S: 2b2fb9b85876afc6b547be2270dec0955cd93b9b 10.255.49.67:6001
   slots: (0 slots) slave
   replicates f3695d7e16c46368c2c8850b40c42cfece94e828
S: 3e6b7752d7d8c5f2fc13d4cbfce686b95e503625 10.255.49.66:6002
   slots: (0 slots) slave
   replicates 0f4630d2726851c5581d18ecd7165b05c14ce955
M: c7bfc594c73bc69c0ceb60fb74aabc85693039ff 10.255.49.66:6000
   slots:[9830-13106] (3277 slots) master
   2 additional replica(s)
M: f3695d7e16c46368c2c8850b40c42cfece94e828 10.255.49.64:6000
   slots:[3277-6553] (3277 slots) master
   2 additional replica(s)
S: c2b591a8e648f8bc917dd2950ccc5f7a922b5f45 10.255.49.66:6001
   slots: (0 slots) slave
   replicates f3695d7e16c46368c2c8850b40c42cfece94e828
S: 82e1ef7756560792922cdaebd0e1fbf34b1865a3 10.255.49.67:6002
   slots: (0 slots) slave
   replicates c7bfc594c73bc69c0ceb60fb74aabc85693039ff
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

看到以上信息说明redis集群已经部署完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维那些事~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值