Redis 主從配置
一:redis 主從複製過程
當配置好slave 後,slave 與master 建立連線,然後傳送sync 命令。無論是第一次連線還是重新連線,master 都會啟動一個後臺程式,將資料庫快照儲存到檔案中,同時master 主進
程會開始收集新的寫命令並快取。後臺程式完成寫檔案後,master 就傳送檔案給slave,slave將檔案儲存到硬碟上,再載入到記憶體中,接著master 就會把快取的命令轉發給slave,後續
master 將收到的寫命令傳送給slave。如果master 同時收到多個slave 發來的同步連線命令,master 只會啟動一個程式來寫資料庫映象,然後傳送給所有的slave。
二:如何配置
配置slave 伺服器很簡單,只需要在slave 的配置檔案中加入如下配置
slaveof 192.168.1.1 6379 #指定master 的ip 和埠
下面我們做一個實驗來演示如何搭建一個主從環境:
# slaveof
slaveof localhost 6379
我們在一臺機器上啟動主庫(埠6379),從庫(埠6378)
啟動後主庫控制檯日誌如下:
[root@localhost redis-2.2.12]# src/redis-server redis.conf
[7064] 09 Aug 20:13:12 * Server started, Redis version 2.2.12
[7064] 09 Aug 20:13:12 # 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.
[7064] 09 Aug 20:13:12 * The server is now ready to accept connections on port 6379
[7064] 09 Aug 20:13:13 - 0 clients connected (0 slaves), 539512 bytes in use
[7064] 09 Aug 20:13:18 - 0 clients connected (0 slaves), 539512 bytes in use
[7064] 09 Aug 20:13:20 - Accepted 127.0.0.1:37789
[7064] 09 Aug 20:13:20 * Slave ask for synchronization
[7064] 09 Aug 20:13:20 * Starting BGSAVE for SYNC
[7064] 09 Aug 20:13:20 * Background saving started by pid 7067
[7067] 09 Aug 20:13:20 * DB saved on disk
[7064] 09 Aug 20:13:20 * Background saving terminated with success
[7064] 09 Aug 20:13:20 * Synchronization with slave succeeded
[7064] 09 Aug 20:13:23 - 0 clients connected (1 slaves), 547380 bytes in use
啟動後從庫控制檯日誌如下:
[root@localhost redis-2.2.12]# src/redis-server redis.slave
[7066] 09 Aug 20:13:20 * Server started, Redis version 2.2.12
[7066] 09 Aug 20:13:20 # 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.
[7066] 09 Aug 20:13:20 * The server is now ready to accept connections on port 6378
[7066] 09 Aug 20:13:20 - 0 clients connected (0 slaves), 539548 bytes in use
[7066] 09 Aug 20:13:20 * Connecting to MASTER...
三:redis 主從複製特點:
(1)、master 可以擁有多個slave
(2)、多個slave 可以連線同一個master 外,還可以連線到其他slave
(3)、主從複製不會阻塞master,在同步資料時,master 可以繼續處理client 請求
(4)、提高系統的伸縮性
當配置好slave 後,slave 與master 建立連線,然後傳送sync 命令。無論是第一次連線還是重新連線,master 都會啟動一個後臺程式,將資料庫快照儲存到檔案中,同時master 主進
程會開始收集新的寫命令並快取。後臺程式完成寫檔案後,master 就傳送檔案給slave,slave將檔案儲存到硬碟上,再載入到記憶體中,接著master 就會把快取的命令轉發給slave,後續
master 將收到的寫命令傳送給slave。如果master 同時收到多個slave 發來的同步連線命令,master 只會啟動一個程式來寫資料庫映象,然後傳送給所有的slave。
二:如何配置
配置slave 伺服器很簡單,只需要在slave 的配置檔案中加入如下配置
slaveof 192.168.1.1 6379 #指定master 的ip 和埠
下面我們做一個實驗來演示如何搭建一個主從環境:
# slaveof
slaveof localhost 6379
我們在一臺機器上啟動主庫(埠6379),從庫(埠6378)
啟動後主庫控制檯日誌如下:
[root@localhost redis-2.2.12]# src/redis-server redis.conf
[7064] 09 Aug 20:13:12 * Server started, Redis version 2.2.12
[7064] 09 Aug 20:13:12 # 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.
[7064] 09 Aug 20:13:12 * The server is now ready to accept connections on port 6379
[7064] 09 Aug 20:13:13 - 0 clients connected (0 slaves), 539512 bytes in use
[7064] 09 Aug 20:13:18 - 0 clients connected (0 slaves), 539512 bytes in use
[7064] 09 Aug 20:13:20 - Accepted 127.0.0.1:37789
[7064] 09 Aug 20:13:20 * Slave ask for synchronization
[7064] 09 Aug 20:13:20 * Starting BGSAVE for SYNC
[7064] 09 Aug 20:13:20 * Background saving started by pid 7067
[7067] 09 Aug 20:13:20 * DB saved on disk
[7064] 09 Aug 20:13:20 * Background saving terminated with success
[7064] 09 Aug 20:13:20 * Synchronization with slave succeeded
[7064] 09 Aug 20:13:23 - 0 clients connected (1 slaves), 547380 bytes in use
啟動後從庫控制檯日誌如下:
[root@localhost redis-2.2.12]# src/redis-server redis.slave
[7066] 09 Aug 20:13:20 * Server started, Redis version 2.2.12
[7066] 09 Aug 20:13:20 # 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.
[7066] 09 Aug 20:13:20 * The server is now ready to accept connections on port 6378
[7066] 09 Aug 20:13:20 - 0 clients connected (0 slaves), 539548 bytes in use
[7066] 09 Aug 20:13:20 * Connecting to MASTER...
三:redis 主從複製特點:
(1)、master 可以擁有多個slave
(2)、多個slave 可以連線同一個master 外,還可以連線到其他slave
(3)、主從複製不會阻塞master,在同步資料時,master 可以繼續處理client 請求
(4)、提高系統的伸縮性
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28624388/viewspace-1288682/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redis主從配置Redis
- docker 配置 Redis 主從DockerRedis
- Docker配置redis主從哨兵DockerRedis
- Redis 主從 Replication 的配置Redis
- Ubuntu+Redis主從配置UbuntuRedis
- Redis主從同步配置實踐Redis主從同步
- thinkphp5.1redis主從配置PHPRedis
- Redis 4.0主從複製配置Redis
- Redis安裝及主從配置Redis
- redis原理及叢集主從配置Redis
- keepalived配置redis主從切換Redis
- Redis replication主從複製原理及配置Redis
- Docker下redis的主從、持久化配置DockerRedis持久化
- Redis 主從配置和引數詳解Redis
- Dcoker教程之九配置Redis主從複製Redis
- CentOS7下配置redis主從關係CentOSRedis
- Redis主從同步Redis主從同步
- Redis主從搭建Redis
- 基於配置檔案的redis的主從複製Redis
- Redis - 主從複製Redis
- Redis主從切換Redis
- Redis:主從複製Redis
- centos 搭建redis主從CentOSRedis
- Redis主從複製Redis
- Redis主從模式部署Redis模式
- redis主從備份Redis
- 【Redis】Redis 主從複製之一Redis
- Mongodb主從配置MongoDB
- mysql主從配置MySql
- mysql 主從配置MySql
- mysql配置主從MySql
- MySQL 主從配置-之-一主一從MySql
- redis原始碼分析(一)複習redis命令、持久化方案、主從同步原理、配置Redis原始碼持久化主從同步
- Redis 主從複製原理Redis
- Redis 主從複製(Replication)Redis
- redis系列:主從複製Redis
- redis主從同步機制Redis主從同步
- Redis sentinel主從切換Redis