主库已经搭好
root 11312 1 0 Sep20 ? 00:05:54 redis-server *:6379
准备搭一个6380端口的备库
1.配置6380端口的conf文件 (端口可以用redis-server --port来指定,但是我还是想写在conf文件里)
1.1拷贝主库的redis.conf文件
cd /usr/local/redis-5.0.3/
cp redis.conf redis6380.conf
1.2 配置端口
vi redis6380.conf找到port那行,将6379改成6380
[root@lzl redis-5.0.3]# grep port redis6380.conf |grep -v ^#
port 6380
2.启动6380端口的redis服务
redis-server /usr/local/redis-5.0.3/redis6380.conf &
3.slaveof搭建备库
redis-cli -p 6380
127.0.0.1:6380> slaveof 127.0.01 6379
4 检查复制状态
4.1 replication状态
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:127.0.01
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:126
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:944904c9bf97e4be5e594e3458825b3323af931a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:126
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:126
4.2验证主从同步
127.0.0.1:6379> get lzl aaa
(error) ERR wrong number of arguments for 'get' command
127.0.0.1:6379> get lzl
"aaa"
127.0.0.1:6380> get aaa
(nil)
127.0.0.1:6380> get lzl
"aaa"
总结:
redis主从太简单了,没有mysql和oracle的数据初始化步骤。slaveof已经包含了初始化和同步。