先学一个高端linux指令:
cat redis.conf | grep -v "^#" | grep -v "^$" > msconf/redis-master.conf
-v 反向查找 "^#"以#开头的行 "^$"空行
将redis.conf去掉空行和以#开头的行,写入到msconf文件夹的redis-master.conf文件中
1、master-6380.conf配置文件主要要修改的内容:
# bind 127.0.0.1 protected-mode no port 6380 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis_6380.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-6380.rdb dir ./ 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 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly no appendfilename "appendonly-6380.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes "redis-master.conf" 62L, 1436C
再学一个linux高端指令:
sed 's/6380/6381/g' redis-master.conf > redis-slave1.conf
把redis-master.conf中的6380全部替换为6381并写入redis-slave1.conf
配置从节点,让它跟随主节点
# bind 127.0.0.1
protected-mode no port 6382 slaveof 127.0.0.1 6380 //主要是这里让它跟随的ip和端口 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis_6382.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-6382.rdb dir ./ 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 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly no appendfilename "appendonly-6382.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb "redis-slave2.conf" 63L, 1459C
先启动主库,在启动从库,之后在主库添加内容,从库会自动写入。
如下主写 从读,可以做到redis的读写分离,高可靠性
标签:lazy,no,配置,redis,6380,conf,yes,主从 From: https://www.cnblogs.com/wscw/p/17931690.html