新聞中心
該文使用centos 6.5 64位 Redis3.2.8

創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計與策劃設(shè)計,梁山網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:梁山等地區(qū)。梁山做網(wǎng)站價格咨詢:13518219792
主從復(fù)制
Redis的復(fù)制功能是支持多個數(shù)據(jù)庫之間的數(shù)據(jù)同步。一類是主數(shù)據(jù)庫(master)一類是從數(shù)據(jù)庫(slave),主數(shù)據(jù)庫可以進行讀寫操作,當發(fā)生寫操作的時候自動將數(shù)據(jù)同步到從數(shù)據(jù)庫,而從數(shù)據(jù)庫一般是只讀的,并接收主數(shù)據(jù)庫同步過來的數(shù)據(jù),一個主數(shù)據(jù)庫可以有多個從數(shù)據(jù)庫,而一個從數(shù)據(jù)庫只能有一個主數(shù)據(jù)庫。通過redis的復(fù)制功能可以很好的實現(xiàn)數(shù)據(jù)庫的讀寫分離,提高服務(wù)器的負載能力。主數(shù)據(jù)庫主要進行寫操作,而從數(shù)據(jù)庫負責讀操作。
Redis主從復(fù)制:主從復(fù)制可以允許多個slave server 擁有和master server相同的數(shù)據(jù)庫副本
1、Redis主從復(fù)制的特點:
a、 master 可以有多個slave
b、 多個slave 可以鏈接同一個master外,還可以鏈接其他slave
c、 主從復(fù)制不會阻塞master,在數(shù)據(jù)同步的時候,master可以繼續(xù)處理client請求
d、 提高系統(tǒng)的伸縮性
2、Redis主從復(fù)制的過程:
a、 slave與master建立鏈接,發(fā)送sync同步請求。
b、 master會啟動一個后臺進程,將數(shù)據(jù)庫快照保存到文件中,同時master主進程會開始收集新的寫命令并緩存。
c、 后臺完成保存后,就將此文件發(fā)送給slave
d、 Slave將此文件保存到硬盤上。
3、Redis 主從復(fù)制操作步驟
環(huán)境:
Redis主從結(jié)構(gòu)支持一主多從(所有從節(jié)點的配置都一樣)
master:192.168.6.190
slave:192.168.6.191
配置:
配置slave服務(wù)器,在slave服務(wù)器的配置文件中加入一下代碼
slaveof 192.168.222.1 6379 #指定master的ip和端口
################################# REPLICATION #################################
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
# slaveof
slaveof 192.168.6.190 6379
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth
啟動master服務(wù)器:
[root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf
查看master配置信息:127.0.0.1:6379> info
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.6.191,port=6379,state=online,offset=141,lag=0
master_repl_offset:141
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:140
啟動slave服務(wù)器:
[root@localhost bin]# ./redis-server /usr/local/redis/etc/redis.conf
查看slave配置信息:127.0.0.1:6379> info
# Replication
role:slave
master_host:192.168.6.190
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:99
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:
slave:
配置時遇到錯誤:master_link_status:down
1、確定master與slave的redis端口是開放的,未被防火墻攔截
2、修改 master redis.cnf 文件中bind 為bind 0.0.0.0
網(wǎng)站名稱:CentOS6.564位下Redis主從復(fù)制配置
URL分享:http://www.5511xx.com/article/dpejiei.html


咨詢
建站咨詢
