Redis主從搭建

來源:互聯網
上載者:User

標籤:redis   主從複製   

原創文章,轉載請註明出處:http://www.huyanping.cn/?p=259
Jenner

1


redis安裝方法見:初識Redis——邂逅安裝環境:
[[email protected] redis]# redis-server --versionRedis server v=2.8.7 sha=00000000:0 malloc=jemalloc-3.2.0 bits=32 build=df8b796b6fcf0127[[email protected] redis]# cat /proc/versionLinux version 2.6.18-92.el5 ([email protected]) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)) #1 SMP Tue Jun 10 18:49:47 EDT 2008
1、複製設定檔
#master設定檔cp redis.conf redis-master.conf#slave設定檔cp redis.conf redis-slave.conf#備份設定檔cp redis.conf redis-bak.conf
2、修改設定檔
#master設定檔#保證PID檔案區分,PID檔案主要用於保證守護進程單例運行pidfile /var/run/redis-master.pid#區分LOG檔案logfile "/data/redis/6379/log/redis.log"#區分持久化檔案dir /data/redis/6379/data#區分連接埠port 6379#slave設定檔pidfile /var/run/redis-slave.pidlogfile "/data/redis/6380/log/redis.log"dir /data/redis/6380/dataport 6380slaveof 127.0.0.1 6379#如果為yes,slave執行個體唯讀,如果為no,slave執行個體可讀可寫。預設slave-read-only yes
3、啟動
redis-server /etc/redis/redis-master.confredis-server /etc/redis/redis-slave.conf

4、驗證master開機記錄
[[email protected] redis]# cat /data/redis/6379/log/redis.log[24787] 13 Sep 10:39:45.143 * Max number of open files set to 10032[24787] 13 Sep 10:39:45.145 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with ‘noeviction‘ policy now._.__.-``__ ‘‘-.__.-``    `.  `_.  ‘‘-._           Redis 2.8.7 (00000000/0) 32 bit.-`` .-```.  ```\/    _.,_ ‘‘-._(    ‘      ,       .-`  | `,    )     Running in stand alone mode|`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379|    `-._   `._    /     _.-‘    |     PID: 24787`-._    `-._  `-./  _.-‘    _.-‘|`-._`-._    `-.__.-‘    _.-‘_.-‘||    `-._`-._        _.-‘_.-‘    |           http://redis.io`-._    `-._`-.__.-‘_.-‘    _.-‘|`-._`-._    `-.__.-‘    _.-‘_.-‘||    `-._`-._        _.-‘_.-‘    |`-._    `-._`-.__.-‘_.-‘    _.-‘`-._    `-.__.-‘    _.-‘`-._        _.-‘`-.__.-‘[24787] 13 Sep 10:39:45.146 # Server started, Redis version 2.8.7[24787] 13 Sep 10:39:45.146 # 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.[24787] 13 Sep 10:39:45.146 * The server is now ready to accept connections on port 6379[24787] 13 Sep 10:40:54.342 * DB saved on disk[24787] 13 Sep 10:42:50.581 * Slave asks for synchronization[24787] 13 Sep 10:42:50.581 * Full resync requested by slave.[24787] 13 Sep 10:42:50.581 * Starting BGSAVE for SYNC[24787] 13 Sep 10:42:50.582 * Background saving started by pid 24816[24816] 13 Sep 10:42:50.586 * DB saved on disk[24816] 13 Sep 10:42:50.587 * RDB: 0 MB of memory used by copy-on-write[24787] 13 Sep 10:42:50.673 * Background saving terminated with success[24787] 13 Sep 10:42:50.673 * Synchronization with slave succeeded[24787] 13 Sep 10:47:04.093 * DB saved on disk


slave 開機記錄
[[email protected] redis]# cat /data/redis/6380/log/redis.log[24813] 13 Sep 10:42:50.578 * Max number of open files set to 10032[24813] 13 Sep 10:42:50.579 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with ‘noeviction‘ policy now._.__.-``__ ‘‘-.__.-``    `.  `_.  ‘‘-._           Redis 2.8.7 (00000000/0) 32 bit.-`` .-```.  ```\/    _.,_ ‘‘-._(    ‘      ,       .-`  | `,    )     Running in stand alone mode|`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6380|    `-._   `._    /     _.-‘    |     PID: 24813`-._    `-._  `-./  _.-‘    _.-‘|`-._`-._    `-.__.-‘    _.-‘_.-‘||    `-._`-._        _.-‘_.-‘    |           http://redis.io`-._    `-._`-.__.-‘_.-‘    _.-‘|`-._`-._    `-.__.-‘    _.-‘_.-‘||    `-._`-._        _.-‘_.-‘    |`-._    `-._`-.__.-‘_.-‘    _.-‘`-._    `-.__.-‘    _.-‘`-._        _.-‘`-.__.-‘[24813] 13 Sep 10:42:50.580 # Server started, Redis version 2.8.7[24813] 13 Sep 10:42:50.580 # 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.[24813] 13 Sep 10:42:50.580 * The server is now ready to accept connections on port 6380[24813] 13 Sep 10:42:50.580 * Connecting to MASTER 127.0.0.1:6379[24813] 13 Sep 10:42:50.580 * MASTER <-> SLAVE sync started[24813] 13 Sep 10:42:50.580 * Non blocking connect for SYNC fired the event.[24813] 13 Sep 10:42:50.581 * Master replied to PING, replication can continue...[24813] 13 Sep 10:42:50.581 * Partial resynchronization not possible (no cached master)[24813] 13 Sep 10:42:50.583 * Full resync from master: 9ef3d846e366f7643db9e9250b508d64a34c1079:1[24813] 13 Sep 10:42:50.673 * MASTER <-> SLAVE sync: receiving 31 bytes from master[24813] 13 Sep 10:42:50.673 * MASTER <-> SLAVE sync: Flushing old data[24813] 13 Sep 10:42:50.673 * MASTER <-> SLAVE sync: Loading DB in memory[24813] 13 Sep 10:42:50.674 * MASTER <-> SLAVE sync: Finished with success[24813] 13 Sep 10:47:04.096 * DB saved on disk

資料同步驗證:
[[email protected] redis]# redis-cli127.0.0.1:6379> set name testOK127.0.0.1:6379> saveOK[[email protected] redis]# redis-cli -p 6380127.0.0.1:6380> keys *1) "name"

Redis主從搭建

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.