Redis教程

redis4.0 三主三从集群部署文档

本文主要是介绍redis4.0 三主三从集群部署文档,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、创建redis根目录
mkdir /opt/application/redis
cd /opt/application/redis

2、创建redis节点1主从目录
mkdir cluster cluster/7001 cluster/8001
wget http://download.redis.io/releases/redis-4.0.7.tar.gz
tar -zxvf redis-4.0.7.tar.gz

cd redis-4.0.7
3、// 安装redis
make PREFIX=/opt/application/redis/redis-master install && make PREFIX=/opt/application/redis/redis-slave install

4、复制redis配置文件到主从节点目录
cp redis-4.0.7/redis.conf cluster/7001/redis-7001.conf && cp redis-4.0.7/redis.conf cluster/8001/redis-8001.conf
mkdir -p /data/redis/10179678/7001/ /data/redis/10179678/8001/

5、修改配置文件
vi cluster/7001/redis-7001.conf

配置文件详情

bind 0.0.0.0
protected-mode yes
port 7001
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /opt/application/redis/cluster/7001/redis-7001.pid
loglevel notice
logfile ""
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/10179678/7001/
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
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
cluster-enabled yes

vi cluster/8001/redis-8001.conf

配置文件详情

bind 0.0.0.0
protected-mode yes
port 8001
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /opt/application/redis/cluster/8001/redis-8001.pid
loglevel notice
logfile ""
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/10179678/8001/
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
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
cluster-enabled yes

6、启动redis 3台服务器的6个redis都要启动..具体操作步骤同上
/opt/application/redis/redis-master/bin/redis-server /opt/application/redis/cluster/7001/redis-7001.conf && /opt/application/redis/redis-slave/bin/redis-server /opt/application/redis/cluster/8001/redis-8001.conf

7、注意 使用ruby进行部署redis集群环境时报错,提示ruby版本低于2.4.0时,使用一下解决方案,
使用5版本的cli执行
下载:
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
make PREFIX=/opt/application/redis/redis-master-5 install && make PREFIX=/opt/application/redis/redis-slave-5 install
使用 redis-5.0.3 r edis-cli 命令创建redis集群 , 5的版本只make 不做make install使用下面这个命令即可完成安装。

/opt/application/redis/redis-5.0.3/src/redis-cli --cluster create 12.21.21.21:7001 12.21.21.21:8001 12.21.21.21:7001 12.21.21.21:8001 12.21.21.21:7001 12.21.21.21:8001 --cluster-replicas 1

8、 redis集群 各个node 设置密码
可以在第一台机器上连接集群的所有节点, redis-cli -c -h 12.21.21.21 -p 7001 ,加参数 -C 可连接到集群,因为上面 redis.conf 将 bind 改为了ip地址,所以 -h 参数不可以省略 (如在本地执行不要-h)。分别创建密码

config set masterauth 密码
config set requirepass 密码

验证:

auth 密码
config rewrite

这篇关于redis4.0 三主三从集群部署文档的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!