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

Posted X糊涂仙儿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R_01 centos8.0 redis4.0 伪集群搭建相关的知识,希望对你有一定的参考价值。

一、环境

#单节点6个redis进程不同端口 7001-7006,redis1.conf-redis7.conf为配置文件
127.0.0.1 7001 --config redis1.conf
127.0.0.1 7002 --config redis2.conf
127.0.0.1 7003 --config redis3.conf
127.0.0.1 7004 --config redis4.conf
127.0.0.1 7005 --config redis5.conf
127.0.0.1 7006 --config redis6.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 install tcl.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
R_01
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

R_01


四、创建集群

#创建集群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

#创建成功提示

R_01

R_01

#连接集群

~]# 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 否则报错如下:

R_01

以上是关于R_01 centos8.0 redis4.0 伪集群搭建的主要内容,如果未能解决你的问题,请参考以下文章

redis4.0.14集群搭建

docker redis4.0 集群(cluster)搭建

linux7.0下2台服务器安装redis4.0.2集群

Redis4.0数据库:Redis4.0之持久化存储(上)

redis4.0.1三主三从

Linux上编译Redis4.0.2