- 说明:本次文章安装的5.0.9版本信息,本次搭建用3主3从,准备3台机器
准备使用的端口,6380 6381 - 软件版本:redis-5.0.9.tar.gz
第一步:安装gcc
yum -y install gcc #执行完成即可
第二步:解压下载好的redis
tar -xf redis-5.0.9.tar.gz
然后进入目录,安装
cd redis-5.0.9 && make && make install
这里需要注意,安装的目录和路径,不懂的可以去百度下
第三步:把redis-5.0.9里面的redis.conf单独拎出来
我的redis-5.0.9在 /root/tool/ 目录下
我在root目录下创建了redis目录
mkdir redis
在redis下创建6380 6381 文件夹
然后把redis-5.0.9的redis.conf文件分别复制到/root/redis/6380/conf/和/root/redis/6380/conf/目录下
以上的三步骤,在另外两台机器上做一样的
通过几次实践,以下的配置文件,最好不要直接复制直接使用,可能会导致集群起不来,最好的方式是,复制解压后的redis.conf然后针对某些需要修改的值进行修改
#这里是redis.conf的配置,请分清楚,6380和6381,不要混淆了
bind 0.0.0.0
protected-mode yes
port 6380 #修改端口
tcp-backlog 511
timeout 60
tcp-keepalive 300
daemonize yes #deamon 进程运行
supervised no
pidfile "/data/redis/6380/redis.pid" #修改pid的存放路径 以6380为例
loglevel notice
logfile "/data/redis/6380/log/redis.log" #修改log 的路径 以6380为例
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/redis/6380/db" #以6380为例
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
maxclients 60000 #修改最大连接
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes #开启aof
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" #nodes 信息配置文件 以6380为例
cluster-node-timeout 60000 #集群的超时时间
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
# masterauth "1ZdqlgWBfw" #这个是从访问mater密码
# requirepass "1ZdqlgWBfw" # master 密码 密码最好搭建完成后再加
启动6个redis,每台执行
redis-server /root/redis/6380/conf/redis.conf
redis-server /root/redis/6381/conf/redis.conf
开始启动集群,这个是5.0以后集群启动的方式,和以前的不同,下面的截图是其他地方的
redis-cli --cluster CREATE 10.1.1.69:6380 10.1.1.70:6380 10.1.1.168:6380 10.1.1.69:6381 10.1.1.70:6381 10.1.1.168:6381 --cluster-replicas 1
# cluster-replicas 1 这里的1其实代表的是一个比例,就是主节点数/从节点数的比例
![QQ截图20200421190605.png](https://upload-images.jianshu.io/upload_images/22951634-4e52de07740a95a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
查看集群是否成功
redis-cli --cluster check 10.1.1.70:6380
QQ截图20200421190802.png
集群搭建完毕,开始设置密码,6个节点都要设置,下面拿一个举例
[root@localhost ~]# redis-cli -h 10.1.1.70 -p 6380
10.1.1.70:6380> config SET masterauth rp123456
OK
10.1.1.70:6380> config SET requirepass rp123456
OK
10.1.1.70:6380> auth rp123456
OK
10.1.1.70:6380> config rewrite
OK
10.1.1.70:6380> EXIT
最后设置完后再次查看集群状态
redis-cli --cluster check 10.1.1.168:6380 -a 'rp123456'
QQ截图20200421192805.png