標籤:style os io strong ar for 檔案 sp line
1 master/slave server 啟動
利用預設redis.conf設定檔啟動master server,連接埠6379 。
[7304] 29 Aug 09:57:26 - 0 clients connected (0 slaves), 673996 bytes in use
[7304] 29 Aug 09:57:31 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:57:31 - 0 clients connected (0 slaves), 673996 bytes in use
[7304] 29 Aug 09:57:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:57:36 - 0 clients connected (0 slaves), 673996 bytes in use
[7304] 29 Aug 09:57:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.
修改redis設定檔, 主要修改連接埠為6380,不是預設的6379, 然後修改slaveof欄位,設定主master為127.0.0.7 6379
啟動後如下
[1704] 29 Aug 10:03:16 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:21 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:21 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:26 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:26 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:31 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:31 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:36 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:41 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:46 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:46 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:51 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:51 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:03:56 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:03:56 - 1 clients connected (0 slaves), 681872 bytes in use
[1704] 29 Aug 10:04:01 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:04:01 - 1 clients connected (0 slaves), 681872 bytes in use
主master已經檢測到有一個slave串連
[7304] 29 Aug 09:58:31 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:58:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:58:36 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:58:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:58:41 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:58:46 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:58:46 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:58:51 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:58:51 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:58:56 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:58:56 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:59:01 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:59:01 - 0 clients connected (1 slaves), 681960 bytes in use
[7304] 29 Aug 09:59:06 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 09:59:06 - 0 clients connected (1 slaves), 681960 bytes in use
用戶端如果串連到slave,則slave如下顯示:
[1704] 29 Aug 10:05:52 - 2 clients connected (0 slaves), 689700 bytes in use
[1704] 29 Aug 10:05:57 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:05:57 - 2 clients connected (0 slaves), 689700 bytes in use
[1704] 29 Aug 10:06:02 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[1704] 29 Aug 10:06:02 - 2 clients connected (0 slaves), 689700 bytes in use
如果串連到master,則結果如下
[7304] 29 Aug 10:06:53 - Accepted 127.0.0.1:65311
[7304] 29 Aug 10:06:57 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 10:06:57 - 1 clients connected (1 slaves), 689788 bytes in use
[7304] 29 Aug 10:07:02 - DB 0: 15 keys (0 volatile) in 16 slots HT.
[7304] 29 Aug 10:07:02 - 1 clients connected (1 slaves), 689788 bytes in use
2 Replication測試
在master存貯一個值,如下
redis 127.0.0.1:6379> SET company aluOKredis 127.0.0.1:6379> GET company alu(error) ERR wrong number of arguments for ‘get‘ commandredis 127.0.0.1:6379> GET company"alu"redis 127.0.0.1:6379>
串連到slave查詢,已經自動複製。如下
redis 127.0.0.1:6380> GET company"alu"redis 127.0.0.1:6380> SET company asbOKredis 127.0.0.1:6380>
slave我這裡預設是讀寫都可以的,一般應該預設是唯讀,這個可以再設定檔修改!
讀寫分離,類似於mysql cluster提供的讀寫分離,機制是一樣的。
Redis Master-Slave 讀寫分離測試