1.复制一份redis.conf并将6380都改成6379
[redis@t3-dtpoc-dtpoc-web06 conf]$ cp redis.conf redis_6380.conf
[redis@t3-dtpoc-dtpoc-web06 conf]$ vi redis_6380.conf
port 6380
daemonize yes
pidfile "/home/redis/redis/logs/redis_6380.pid"
logfile "/home/redis/redis/logs/redis_6380.log"
dir "/home/redis/redis/data"
protected-mode no
#save 120 1
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump_6380.rdb"
appendonly yes
appendfilename "appendonly_6380.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 10M
aof-load-truncated yes
2.启动从节点6380
[redis@t3-dtpoc-dtpoc-web06 bin]$ ./redis-server ../conf/redis_6380.conf
3.登录从节点6380,并配置主从关系
[redis@t3-dtpoc-dtpoc-web06 bin]$ ./redis-cli -p 6380
127.0.0.1:6380> slaveof 10.153.119.7 6379
OK
4.测试主从复制
主库:[redis@t3-dtpoc-dtpoc-web06 bin]$ ./redis-cli -p 6379
127.0.0.1:6379> set name1 xyz
OK
从库:
127.0.0.1:6380> get name1
"xyz"
127.0.0.1:6380> set name1 liys
(error) READONLY You can't write against a read only replica.
5.主从信息查看
主库:
[redis@t3-dtpoc-dtpoc-web06 bin]$ ./redis-cli -p 6379
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.153.119.7,port=6380,state=online,offset=784,lag=0
master_replid:8b17a7c2b77bb3370a938953c946597fbc4a5469
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:784
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:784
127.0.0.1:6379>
从库:
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:10.153.119.7
master_port:6379
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:980
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:8b17a7c2b77bb3370a938953c946597fbc4a5469
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:980
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:980
6.主从手动切换
6379:
127.0.0.1:6379> slaveof 10.153.119.7 6380
OK
6380:
127.0.0.1:6380> slaveof no one
OK
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.153.119.7,port=6379,state=online,offset=1778,lag=0
master_replid:984cef15a6d628c7d6021a31b5e7f79bcbf91322
master_replid2:8b17a7c2b77bb3370a938953c946597fbc4a5469
master_repl_offset:1778
second_repl_offset:1765
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1751
repl_backlog_histlen:28
127.0.0.1:6380>