|
#启动6379,6380配置
[root@redis-m ~]# netstat -tunlp |grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 1634/redis-server *
tcp 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 1647/redis-server *
tcp 0 0 :::6379 :::* LISTEN 1634/redis-server *
tcp 0 0 :::6380 :::* LISTEN 1647/redis-server *
#我们以6379作为主,6380作为主,编辑6380的配置文件
[root@redis-m ~]# vim /data/6380/redis.conf
slaveof 192.168.1.13 6379 #指定master的IP和端口信息
masterauth #这一项是设置master的密码的,我们没有密码所有没有进行设置
#重启6380的redis服务
[root@redis-m ~]# redis-cli -p 6380 shutdown
[1647] 28 Jul 14:25:48.209 # User requested shutdown...
[1647] 28 Jul 14:25:48.210 * Saving the final RDB snapshot before exiting.
[1647] 28 Jul 14:25:48.223 * DB saved on disk
[1647] 28 Jul 14:25:48.225 # Redis is now ready to exit, bye bye...
[root@redis-m ~]# netstat -tunlp |grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 1634/redis-server *
tcp 0 0 :::6379 :::* LISTEN 1634/redis-server *
[root@redis-m ~]# redis-server /data/6380/redis.conf &
[2] 1676
[root@redis-m ~]# [1676] 28 Jul 14:26:40.304 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6380
| `-._ `._ / _.-' | PID: 1676
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[1676] 28 Jul 14:26:40.307 # Server started, Redis version 2.8.9
[1676] 28 Jul 14:26:40.308 * DB loaded from disk: 0.000 seconds
[1676] 28 Jul 14:26:40.308 * The server is now ready to accept connections on port 6380
[1676] 28 Jul 14:26:41.308 * Connecting to MASTER 192.168.1.13:6379
[1676] 28 Jul 14:26:41.308 * MASTER SLAVE sync started
[1676] 28 Jul 14:26:41.308 * Non blocking connect for SYNC fired the event.
[1676] 28 Jul 14:26:41.308 * Master replied to PING, replication can continue...
[1676] 28 Jul 14:26:41.308 * Partial resynchronization not possible (no cached master)
[1634] 28 Jul 14:26:41.308 * Slave asks for synchronization
[1634] 28 Jul 14:26:41.308 * Full resync requested by slave.
[1634] 28 Jul 14:26:41.308 * Starting BGSAVE for SYNC
[1676] 28 Jul 14:26:41.310 * Full resync from master: 5e26f07d111a362449cd1fecfc4d720019e66339:1
[1634] 28 Jul 14:26:41.318 * Background saving started by pid 1679
[1679] 28 Jul 14:26:41.349 * DB saved on disk
[1679] 28 Jul 14:26:41.350 * RDB: 6 MB of memory used by copy-on-write
[1634] 28 Jul 14:26:41.367 * Background saving terminated with success
[1634] 28 Jul 14:26:41.368 * Synchronization with slave succeeded
#下面是主从建立后的同步信息
[1676] 28 Jul 14:26:41.368 * MASTER SLAVE sync: receiving 150 bytes from master
[1676] 28 Jul 14:26:41.368 * MASTER SLAVE sync: Flushing old data
[1676] 28 Jul 14:26:41.368 * MASTER SLAVE sync: Loading DB in memory
[1676] 28 Jul 14:26:41.368 * MASTER SLAVE sync: Finished with success
#测试连接到主redis上
[root@redis-m ~]# redis-cli -p 6379
127.0.0.1:6379> set docker kvm #增加一个key为docker,值为kvm
OK
127.0.0.1:6379> get docker
"kvm"
#在从redis上查看结果
[root@redis-m ~]# redis-cli -p 6380
127.0.0.1:6380> get docker #从库已经将数据同步过来,在从库上能正常查询到结果
"kvm"
#在redis的主从结构中slave是不能写数据的
127.0.0.1:6380> set ldap lyao
(error) READONLY You can't write against a read only slave. #提示slave是只读的
#查看slave的replication信息
[root@redis-m ~]# redis-cli -p 6380 info replication
# Replication
role:slave
master_host:192.168.1.13
master_port:6379
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_repl_offset:2004
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
#查看master的replication的信息
[root@redis-m ~]# redis-cli -p 6379 info replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.1.13,port=6380,state=online,offset=2074,lag=1
master_repl_offset:2074
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:2073
|
|
|