R_01 centos8.0 redis4.0 伪集群搭建

【R_01 centos8.0 redis4.0 伪集群搭建】弱龄寄事外,委怀在琴书。这篇文章主要讲述R_01 centos8.0 redis4.0 伪集群搭建相关的知识,希望能为你提供帮助。
一、环境

#单节点6个redis进程不同端口 7001-7006,redis1.conf-redis7.conf为配置文件
127.0.0.1 7001--configredis1.conf
127.0.0.1 7002--configredis2.conf
127.0.0.1 7003--configredis3.conf
127.0.0.1 7004--configredis4.conf
127.0.0.1 7005--configredis5.conf
127.0.0.1 7006--configredis6.conf

二、安装1、安装编译
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
mv redis-4.0.10.tar.gz /opt & & cd /opt & & tar xzvf redis-4.0.10.tar.gz

#安装tcl
dnf installtcl.x86_64 gcc -y

#编译redis,拷贝redis-x命令
cd redis-4.0.10 & & make test
make & & make install

2、目录结构
#创建目录
mkdir -p /opt/redis/data/redis1,redis2,redis3,redis4,redis5,redis6
mkdir -p /opt/redis/logs/
mkdir -p /opt/redis/config

3、redis1配置模板#配置文件: redis1.conf-redis6.conf
bind 0.0.0.0#监听ip
protected-mode yes
port 7001# 端口7001,7001-7006
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes#后台运行
supervised no
pidfile /var/run/redis_7001.pid#文件
loglevel notice#日志级别
logfile "/opt/redis/logs/redis1.log"#日志
databases 16
always-show-logo yes
save 900 1#在900秒之内有一次key的变化
save 300 10#在300秒之内,有10个key的变化
save 60 10000#在60秒之内有10000个key变化
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump1.rdb#rdb名字,分别为dump1.rdb-dump6.rdb
dir /opt/redis/data/redis1/#redis1的数据目录为redis1,其它为redis1-redis6
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
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 no
lua-time-limit 5000
cluster-enabled yes
cluster-node-timeout 15000
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

三、启动脚本#启动脚本
~ ]# cat start-all.sh
#! /bin/bash

redis-server /opt/redis/config/redis1.conf
redis-server /opt/redis/config/redis2.conf
redis-server /opt/redis/config/redis3.conf
redis-server /opt/redis/config/redis4.conf
redis-server /opt/redis/config/redis5.conf
redis-server /opt/redis/config/redis6.conf

#查看进程
ps aux | grep redis


四、创建集群#创建集群1副本
#! /bin/bash

redis-cli --cluster create 0.0.0.0:7006 0.0.0.0:7001 0.0.0.0:7002 0.0.0.0:7003 0.0.0.0:7004 0.0.0.0:7005 --cluster-replicas 1

#提示没有ruby、kernel_require.rb:59:in `require
/usr/bin/env: ‘ruby’: No such file or directory

Traceback (most recent call last):
2: from /usr/local/sbin/redis-trib.rb:25:in `< main>
1: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:59:in `require: cannot load such file -- redis (LoadError)

  #安装ruby 、gem安装redis  接口
dnf install ruby
gem install redis

#创建成功提示


#连接集群
~]# redis-cli -c -p 7001 -h 127.0.0.1
10.10.0.59:7001> set a a1
-> Redirected to slot [15495] located at 127.0.0.1:7004
OK
127.0.0.1:7004> get a
"a1"

连接集群需要加 -c  否则报错如下:


    推荐阅读