启动Redis
[iyunv@localhost redis-3.0.2]# redis-server /application/redis/conf/redis.conf
5522:M 18 Feb 05:02:08.448 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 5522
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
5522:M 18 Feb 05:02:08.463 # Server started, Redis version 3.0.2
5522:M 18 Feb 05:02:08.464 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
5522:M 18 Feb 05:02:08.470 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5522:M 18 Feb 05:02:08.470 * The server is now ready to accept connections on port 6379
[iyunv@localhost redis-3.0.2]# redis-server /application/redis/conf/redis.conf
5560:M 18 Feb 05:05:23.085 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 5560
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
5560:M 18 Feb 05:05:23.087 # Server started, Redis version 3.0.2
5560:M 18 Feb 05:05:23.088 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5560:M 18 Feb 05:05:23.088 * DB loaded from disk: 0.001 seconds
5560:M 18 Feb 05:05:23.088 * The server is now ready to accept connections on port 6379
redis集合 这种将3个值集合在一个变量值上 对应标签功能
127.0.0.1:6379> sadd myset a
(integer) 1
127.0.0.1:6379> sadd myset b
(integer) 1
127.0.0.1:6379> sadd myset c
(integer) 1
127.0.0.1:6379> smembers myset
1) "c"
2) "b"
3) "a"
redis 主从同步
MASTER 192.168.2.1
SLAVE 192.168.2.4
编辑slave的redis.conf
vim /application/redis/conf/redis.conf
在slaveof下面添加:
slaveof 192.168.2.1 6379 主库地址和端口号
slave查看
[iyunv@localhost redis-3.0.2]# redis-server /application/redis/conf/redis.conf
6631:S 24 Mar 06:21:26.599 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 6631
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
6631:S 24 Mar 06:21:26.611 # Server started, Redis version 3.0.2
6631:S 24 Mar 06:21:26.613 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6631:S 24 Mar 06:21:26.613 * DB loaded from disk: 0.000 seconds
6631:S 24 Mar 06:21:26.613 * The server is now ready to accept connections on port 6379
6631:S 24 Mar 06:21:27.602 * Connecting to MASTER 192.168.2.1:6379
6631:S 24 Mar 06:21:27.602 * MASTER <-> SLAVE sync started 已经成功
6631:S 24 Mar 06:21:27.603 * Non blocking connect for SYNC fired the event.
6631:S 24 Mar 06:21:27.604 * Master replied to PING, replication can continue...
6631:S 24 Mar 06:21:27.606 * Partial resynchronization not possible (no cached master)
6631:S 24 Mar 06:21:27.611 * Full resync from master: 7a09e0f69c3888561658ec8a480d250d219c2444:1
6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: receiving 83 bytes from master
6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: Flushing old data
6631:S 24 Mar 06:21:27.671 * MASTER <-> SLAVE sync: Loading DB in memory
6631:S 24 Mar 06:21:27.672 * MASTER <-> SLAVE sync: Finished with success
MASTER查看
[iyunv@localhost ~]# redis-server /application/redis/conf/redis.conf
2178:M 19 Feb 03:22:56.204 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.2 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2178
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
2178:M 19 Feb 03:22:56.224 # Server started, Redis version 3.0.2
2178:M 19 Feb 03:22:56.224 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2178:M 19 Feb 03:22:56.224 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2178:M 19 Feb 03:22:56.224 * DB loaded from disk: 0.000 seconds
2178:M 19 Feb 03:22:56.224 * The server is now ready to accept connections on port 6379
2178:M 19 Feb 03:37:57.011 * 1 changes in 900 seconds. Saving...
2178:M 19 Feb 03:37:57.014 * Background saving started by pid 2374
2374:C 19 Feb 03:37:57.046 * DB saved on disk
2374:C 19 Feb 03:37:57.046 * RDB: 6 MB of memory used by copy-on-write
2178:M 19 Feb 03:37:57.120 * Background saving terminated with success
2178:M 19 Feb 03:52:58.020 * 1 changes in 900 seconds. Saving...
2178:M 19 Feb 03:52:58.031 * Background saving started by pid 2546
2546:C 19 Feb 03:52:58.049 * DB saved on disk
2546:C 19 Feb 03:52:58.049 * RDB: 6 MB of memory used by copy-on-write
2178:M 19 Feb 03:52:58.138 * Background saving terminated with success
2178:M 19 Feb 04:09:04.556 * Slave 192.168.2.4:6379 asks for synchronization
2178:M 19 Feb 04:09:04.556 * Full resync requested by slave 192.168.2.4:6379
2178:M 19 Feb 04:09:04.556 * Starting BGSAVE for SYNC with target: disk
2178:M 19 Feb 04:09:04.557 * Background saving started by pid 2773
2773:C 19 Feb 04:09:04.580 * DB saved on disk
2773:C 19 Feb 04:09:04.581 * RDB: 6 MB of memory used by copy-on-write 主库也接受到了
2178:M 19 Feb 04:09:04.620 * Background saving terminated with success
2178:M 19 Feb 04:09:04.620 * Synchronization with slave 192.168.2.4:6379 succeeded
在从库做个监控,主库写数据验证
[iyunv@localhost ~]# redis-cli 主库创建数据库
127.0.0.1:6379> set t1 xiaohu01
OK
127.0.0.1:6379> get t1
"xiaohu01"
查看从库同步
[iyunv@localhost ~]# redis-cli -h 192.168.2.4 get t1
"xiaohu01"
远程连接到从库查看数据同步了