Redis主从读写分离

Table of Contents

一主一从

默认主写从读

master

redis.6379.conf
port 6379
daemonize yes
dbfilename redis.6379.rdb
dir ./db/
logfile "./log/redis.6379.log"
pidfile ./tmp/pids/redis_6379.pid

slave

redis.6380.conf
port 6380
daemonize yes
dbfilename redis.6380.rdb
dir ./db/
slaveof 127.0.0.1 6379
logfile "./log/redis.6380.log"
pidfile ./tmp/pids/redis_6380.pid

启动

redis-server ./config/redis.6379.conf
redis-server ./config/redis.6380.conf

测试

redis for docker

修改启动默认配置(从上至下依次):

bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问

protected-mode no #默认yes,开启保护模式,限制为本地访问

daemonize no#默认no,改为yes意为以守护进程方式启动,可后台运行,除非kill进程,改为yes会使配置文件方式启动redis失败

databases 16 #数据库个数(可选),我修改了这个只是查看是否生效。。

dir  ./ #输入本地redis数据库存放文件夹(可选)

appendonly yes #redis持久化(可选)

4.docker启动redis命令

docker run -p 6379:6379 --name myredis -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes

链接:

Date: 2022-06-11 Sat 20:47

Author: yangk

Created: 2023-01-03 Tue 12:43

hello-world