Redis主从配置实践

来源:互联网 发布:文件加密锁软件 编辑:程序博客网 时间:2024/05/17 02:25

1.进入安装redis目录,拷贝配置文件供slave使用

#cd /usr/local/redis/redis-2.8.17

#mkdir slave

#cp redis.conf slave/redis_slave_1.conf

#vim slave/redis_slave_1.conf

pidfile /var/run/redis_slave_1.pid

port 6401      #master: port 6379

logfile "logs/redis_slave_1.log"

dbfilename  dump_slave_1.rdb    #master:dbfilename  dump.rdb

slaveof 127.0.0.1 6379  #新增


2.启动主从机检验是否生效

# nohup src/redis-server >>logs/redis_master.log 2>& 1 &

[1] 2759

# nohup src/redis-server ./slave/redis_slave_1.conf >>logs/redis_slave1.log 2>& 1 &
[2] 2769


# tail -f logs/redis_slave.log 
[2769] 08 Oct 09:53:31.054 * Connecting to MASTER 127.0.0.1:6379
[2769] 08 Oct 09:53:31.054 * MASTER <-> SLAVE sync started
[2769] 08 Oct 09:53:31.054 * Non blocking connect for SYNC fired the event.
[2769] 08 Oct 09:53:31.055 * Master replied to PING, replication can continue...
[2769] 08 Oct 09:53:31.055 * Partial resynchronization not possible (no cached master)
[2769] 08 Oct 09:53:31.058 * Full resync from master: c04c5262019736bbb30a49a7de799ed687d861df:1
[2769] 08 Oct 09:53:31.134 * MASTER <-> SLAVE sync: receiving 40 bytes from master
[2769] 08 Oct 09:53:31.134 * MASTER <-> SLAVE sync: Flushing old data
[2769] 08 Oct 09:53:31.134 * MASTER <-> SLAVE sync: Loading DB in memory
[2769] 08 Oct 09:53:31.134 * MASTER <-> SLAVE sync: Finished with success


# src/redis-cli

127.0.0.1:6379> set name copher
OK
127.0.0.1:6379> get name
"copher"
127.0.0.1:6379> exit
# src/redis-cli -p 6401
127.0.0.1:6401> get name
"copher"
127.0.0.1:6401> set age 999
(error) READONLY You can't write against a read only slave.
127.0.0.1:6401> set message "message"
(error) READONLY You can't write against a read only slave.
127.0.0.1:6401> exit

#


测试完毕,配置生效。




0 0
原创粉丝点击