[redis]-redis 通过redis-server命令建立redis主从关系 - Go语言中文社区

[redis]-redis 通过redis-server命令建立redis主从关系


redis 通过redis-server命令建立redis主从关系

 

[root@sqlserver redis]# redis-server -h

Usage: ./redis-server [/path/to/redis.conf] [options]

       ./redis-server - (read config from stdin)

       ./redis-server -v or --version

       ./redis-server -h or --help

       ./redis-server --test-memory <megabytes>

 

Examples:

       ./redis-server (run the server with default conf)

       ./redis-server /etc/redis/6379.conf

       ./redis-server --port 7777

       ./redis-server --port 7777 --slaveof 127.0.0.1 8888

       ./redis-server /etc/myredis.conf --loglevel verbose

 

Sentinel mode:

       ./redis-server /etc/sentinel.conf --sentinel

 

 

----测试命令----

redis通过--port 启动一个新端口 

通过--port 启动一个新端口 只修改端口号 但是延用指定conf中的其余配置入密码.

如果不指定conf 则使用默认配置 默认免密登录. redis-server  --port 6380

如果指定配置文件 配置文件是有密码验证的 那启动的端口是需要密码认证的.

redis-server  /usr/local/redis/redis.conf --port 6380

 

 

 

----测试命令----

 

下面开始实践

 

之前安装redis或者redis的主从都是用的不同的配置文件 配置起来比较繁琐.

这边想尝试一下 可不可以用slave of 和port的命令

修改/usr/local/redis/redis.conf如下

daemonize yes

pidfile "./redis.pid"

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile "./redis.log"

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename "dump.rdb"

#这里要设置成当前 否则文件会互相覆盖或者需要制定路径,就比较麻烦

dir "./"

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

requirepass "Hangzhou@123"

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

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-entries 512

list-max-ziplist-value 64

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

#率先设置好master密码,否则slave会报认证错误的.

masterauth Hangzhou@123

 

 

在/usr/local/redis路径下创建2个文件夹

mkdir 6379 6380

 

看到没有dump.db

连接上客户端

验证密码功能

创建测试的key

执行bgsave 之后再查看dump.db文件

发现已经生成了dump.db

 

cd ../6380/

redis-server /usr/local/redis/redis.conf --port 6380

连接6380 使用客户端发送的命令slaveof 127.0.0.1 6379命令建立主从

日志也显示建立成功

复制一份redis文件夹命名为redis-test

cp -r /usr/local/redis /usr/local/redis-test

cd /usr/local/redis-test

通过下面的命令启动6381的从端口 并设置master的端口

redis-server /usr/local/redis-test/redis.conf --port 6381 --slaveof 127.0.0.1 6379

查看同步数据 6381的slave也已经成功同步数据

 

 

 

校验redis数据 可以通过以下两个命令校验repl-id和offset是否一致

/usr/local/redis/src/redis-check-rdb dump.rdb

 

或者

od -c dump.rdb

 

 

这边没有测试当主从断开一定时间后,偏移量如果在缓冲区,这样建立的主从是增量同步,还是仍旧会使用dump.db同步.

 

可以参考

https://www.jianshu.com/p/6fe7c56e487c

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/xujiamin0022016/article/details/97245459
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-07 20:05:37
  • 阅读 ( 1583 )
  • 分类:Redis

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢