亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Redis-簡單實(shí)現(xiàn)星形主從配置

Original 2016-11-09 13:54:27 523
abstrakt:簡單應(yīng)用場景現(xiàn)在配置redis 星形 集群, 有三臺服務(wù)器, 怎樣實(shí)現(xiàn)?復(fù)制redis.conf兩份, 分別命名為redis6380.conf, redis6381.confmaster指向redis.conf, slave1指向6380.conf, slave2指向redis6381.confmaster關(guān)閉rdb, 開啟aofslave1開啟rdb, 關(guān)閉aofslave2

簡單應(yīng)用場景

現(xiàn)在配置redis 星形 集群, 有三臺服務(wù)器, 怎樣實(shí)現(xiàn)?
復(fù)制redis.conf兩份, 分別命名為redis6380.conf, redis6381.conf
master指向redis.conf, slave1指向6380.conf, slave2指向redis6381.conf

master關(guān)閉rdb, 開啟aof
slave1開啟rdb, 關(guān)閉aof
slave2關(guān)閉rdb和aof

配置redis6380.conf

#pidfile /var/run/redis.pid    改為
pidfile /var/run/redis6380.pid
...
#port 6379    改為
port 6380
...
#dbfilename dump.rdb    改為
dbfilename dump6380.rdb    #讓slave1執(zhí)行rdb工作
...
# slaveof <masterip> <masterport>    改為
slaveof localhost 6379    #表示作為6379的slave
...
appendonly no    #aof也不用產(chǎn)生, 因此關(guān)閉
...
slave-read-only yes    #只讀

配置redis6381.conf

pidfile /var/run/redis6381.pid
...
port 6381
...
#save 900 1    #兩臺從服務(wù)器其中一臺產(chǎn)生rdb就可以了, 另一臺沒必要再次產(chǎn)生rdb, 因此注釋掉
#save 300 10
#save 60 10000
...
appendonly no    #aof也不用產(chǎn)生, 因此關(guān)閉
...
slaveof localhost 6379
...
slave-read-only yes    #只讀

配置redis.conf

#save 900 1    #因?yàn)閟lave1已經(jīng)存在rdb了, 所以master不在需要rdb
#save 300 10
#save 60 10000
...
appendonly yes    #master的aof可以打開, 因?yàn)橹鞣?wù)器的aof最全最快

啟動, 分別在終端打開:

ql@ql:~$ redis-server /usr/local/etc/redis/redis.conf
ql@ql:~$ redis-server /usr/local/etc/redis/redis6380.conf
ql@ql:~$ redis-server /usr/local/etc/redis/redis6381.conf

啟動master的客戶端

ql@ql:~$ redis-cli
127.0.0.1:6379> set title sunshine
OK
127.0.0.1:6379>

啟動slave1的客戶端

ql@ql:~$ redis-cli -p 6380
127.0.0.1:6380> keys *    #可以看到master中的內(nèi)容
1) "title"
127.0.0.1:6380> get title
"sunshine"
127.0.0.1:6380>

啟動slave2的客戶端

ql@ql:~$ redis-cli -p 6381
127.0.0.1:6381> keys *    #也能看到master中的內(nèi)容
1) "title"
127.0.0.1:6381> get title
"sunshine"
127.0.0.1:6381>

現(xiàn)在要為master設(shè)置密碼, 即redis.conf

# 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-password>
requirepass admin123    #新加的一行

再次打開終端
打開reids-server
打開reids-cli

ql@ql:~$ redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.    #沒有輸入密碼進(jìn)行認(rèn)證
127.0.0.1:6379> 
127.0.0.1:6379> auth admin123    #auth+密碼進(jìn)行認(rèn)證
OK
127.0.0.1:6379> keys *
1) "title"
127.0.0.1:6379> get title
"sunshine"
127.0.0.1:6379>

此時從服務(wù)器連不上主服務(wù)器, 因?yàn)橛忻艽a

修改redis6380.conf

# masterauth <master-password>    改為
masterauth admin123

redis6381.conf的修改如上

redis主從復(fù)制的缺陷

每次slave斷開后(無論是主動斷開還是網(wǎng)絡(luò)故障), 再連接master,
都要 master 全部 dump 出來 rdb 再 aof,
即同步的過程都要執(zhí)行一遍
所以: 多臺slave不要一下同時啟動起來, 否則master可能IO劇增, 拖垮master


Versionshinweise

Beliebte Eintr?ge