1.先到Redis官网(redis.io)或者GitHub下载redis安装包
redis-6.2.6.tar.gz
2.解压并进入其目录
cd redis-6.2.6
3.编译源程序
make
cd src
make install PREFIX=/usr/local/redis
4.进入redis安装目录
cd /usr/local/redis
5.创建配置文件目录
mkdir conf
6.创建配置文件
vim 6380.conf
7.配置文件内容:
bind 0.0.0.0
protected-mode no
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_6380.pid
loglevel notice
logfile "/usr/local/redis/logs/redis_6380.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /usr/local/redis/data/6380
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
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 yes
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-6380.conf
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
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
8.复制配置文件, 把配置文件中的端口修改成对应的端口
6381.conf,6382.conf,6383.conf,6384.conf,6385.conf
9.回到上级目录, 创建以下文件:
cd ..
vim start-all.sh #用于启动所有Redis
vim stop-all.sh #用于关闭所有Redis
vim clear.sh #用于清除数据
10. start-all.sh文件内容:
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6380.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6381.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6382.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6383.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6384.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6385.conf
11. stop-all.sh文件内容:
/usr/local/redis/bin/redis-cli -p 6380 shutdown &
/usr/local/redis/bin/redis-cli -p 6381 shutdown &
/usr/local/redis/bin/redis-cli -p 6382 shutdown &
/usr/local/redis/bin/redis-cli -p 6383 shutdown &
/usr/local/redis/bin/redis-cli -p 6384 shutdown &
/usr/local/redis/bin/redis-cli -p 6385 shutdown
11. clear.sh文件内容:
rm -rf /usr/local/redis/data/6380/* &
rm -rf /usr/local/redis/data/6381/* &
rm -rf /usr/local/redis/data/6382/* &
rm -rf /usr/local/redis/data/6383/* &
rm -rf /usr/local/redis/data/6384/* &
rm -rf /usr/local/redis/data/6385/*
12.设置开机启动
在/etc/init.d/目录下新建redis文件, 内容如下
vim /etc/init.d/redis
#!/bin/bash
# chkconfig: 2345 55 25
# description: redis-cluster Cloud Service
### BEGIN INIT INFO
# Provides: redis-cluster
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts redis-cluster
# Description: starts the redis-cluster
### END INIT INFO
init(){
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6380.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6381.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6382.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6383.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6384.conf &
/usr/local/redis/bin/redis-server /usr/local/redis/conf/6385.conf
}
init
增加执行权限
chmod +x /etc/init.d/redis
设置启动
chkconfig --add redis
chkconfig redis on
13.安装redis-trib所需的 ruby脚本 (6.0版本不需要ruby环境了, 这一步可以省略)
yum install centos-release-scl-rh #会在/etc/yum.repos.d/目录下多出一个CentOS-SCLo-scl-rh.repo源
yum install rh-ruby26 -y
scl enable rh-ruby26 bash #必要一步
ruby -v #查看版本
gem install redis #安装Redis内容
14.启动集群功能
进入redis安装目录的bin目录, 执行以下命令:
./redis-cli --cluster create 192.168.1.110:6380 192.168.1.110:6381 192.168.1.110:6382 192.168.1.110:6383 192.168.1.110:6384 192.168.1.110:6385 --cluster-replicas 1
15.开放对应端口
6380-6385
网友评论