版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/sunknew/article/details/79191764
环境
操作系统:CentOS 7.3
redis版本:Redis 3.2.8
两台主机,每台主机上3个节点
基本步骤
下载解压安装包
# 下载解压安装包
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar -zxvf redis-3.2.8.tar.gz
编译安装
# 正常编译安装
make && make install
# 若未安装gcc,则安装gcc
yum install gcc
# 若未安装jemalloc内存分配器,则使用如下命令编译安装
make MALLOC=libc && make install
创建相应目录,编写配置文件
本次搭建使用如下目录:
- 日志目录:
/opt/redis/logs
- 数据目录:
/opt/redis/db
- 集群文件目录:
/opt/redis/cluster-conf/端口
,如:/opt/redis/cluster-conf/7001
配置文件:简单配置文件,注意修改各节点的IP和端口。
启动各节点
# 启动各节点
cd /opt/redis/src
./redis-server ../cluster-conf/7001/redis.conf
./redis-server ../cluster-conf/7002/redis.conf
./redis-server ../cluster-conf/7003/redis.conf
./redis-server ../cluster-conf/7004/redis.conf
./redis-server ../cluster-conf/7005/redis.conf
./redis-server ../cluster-conf/7006/redis.conf
创建集群
# 安装ruby
yum -y install ruby ruby-devel rubygems rpm-build
# 安装redis包 (指定相应的版本号,https://rubygems.org/gems/redis)
gem install redis -v 3.3.0
# 创建集群
./redis-trib.rb create --replicas 1 192.168.192.128:7001 192.168.192.128:7002 192.168.192.128:7003 192.168.192.129:7004 192.168.192.129:7005 192.168.192.129:7006
- 使用RubyGems安装Redis包时,需指明版本号,否则会安装最新版的,因为该版本的CentOS的Ruby默认版本是2.0,最新的Redis包需要升级Ruby的版本才能安装。
简单配置文件
################################## INCLUDES ###################################
################################## NETWORK #####################################
bind 192.168.192.128
protected-mode yes
port 7001
tcp-backlog 511
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize yes
supervised no
pidfile /var/run/redis_7001.pid
loglevel notice
logfile "/opt/redis/logs/redis_7001.log"
databases 16
################################ SNAPSHOTTING ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /opt/redis/db
################################# REPLICATION #################################
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
################################## SECURITY ###################################
################################### LIMITS ####################################
############################## APPEND ONLY MODE ###############################
appendonly yes
appendfilename "appendonly_7001.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
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