redis-cluster的安裝管理
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的開魯網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!環(huán)境介紹
Red Hat Enterprise Linux Server release 6.2 (Santiago)
Linux zxt-02.com 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
redis-3.0.5
redis-01.comredis-02.com
IP192.168.1.193 192.168.1.176
Zlibruby1.9.2rubygemgem-redis
http://redis.io/topics/cluster-spec
http://redis.io/topics/cluster-tutorial
Redis Redis installationRedis Redis Redis Redis
Redis partitionavailability
Redis
split
Redis hash, .
Redis 16384,keyCRC1616384.hash,,3,:
A 0 5500
B 5501 11000 .
C 11001 16384.
. D, A, B, CD. A,ABC,A.
,.
,N-1.
ABC,,B5501-11000.
A1B1C1,masterslaveBB1
BB1 .
Redis . .
. :
B.
B.
B1, B2 B3.
Redis
Redis .
A B C A1 B1 C1 A B C A1 B1 C1 ABC Z1
A C A1 B1 C1 B Z1 .
Z1B, ,,B1masterZ1B.
Z1 B node timeout Redis
redis-cluster3redis
node1 192.168.1.193:6379 node2 192.168.1.193:6479 node3 192.168.1.193:6579 備機(jī)節(jié)點(diǎn): node1 192.168.1.176:6379 node2 192.168.1.176:6479 node3 192.168.1.176:6579
Zlibyum
[zxt@redis-01 ~]$ yum install -y zlib* [zxt@redis-01 ~]$ rpm -qa |grep zlib zlib-1.2.3-27.el6.x86_64 zlib-devel-1.2.3-27.el6.x86_64
#download: http://www.zlib.net/ tar zxf zlib-1.2.7.tar.gz cd zlib ./configure make make install
yumRedHat6.2yum1.8.7
#ruby-2.1.7.tar.gz tar zxvf ruby-2.1.7.tar.gz cd ruby-2.1.7 ./configure -prefix=/usr/local/ruby make make install cp ruby /usr/local/bin
# rubygems-1.8.5.tgz tar zxvf rubygems-1.8.5.tgz cd rubygems-1.8.5 ruby setup.rb cp bin/gem /usr/local/bin
redis
gem sources --remove https://rubygems.org/ gem sources -a http://ruby.sdutlinux.org/ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org
http://rubygems.org/
http://gems.github.com
http://gems.rubyforge.org
http://ruby.sdutlinux.org/
https://ruby.taobao.org gem
tar xzf redis-3.0.5.tar.gz cp -r redis-3.0.5 /opt/app/ ln -s /opt/app/redis-3.0.5/ /opt/redis cd /opt/redis make test make make install
make install/usr/local/binredis-serverredis-cliredis-benchmarkredis-check-aof redis-check-dump
redis-serverRedisdaemon
redis-cliRedistelnet
redis-benchmarkRedisRedis
redis-check-aof
redis-check-dump
1
cd /opt/redis cp /opt/redis/src/redis-trib.rb /usr/local/bin
2redis cluster
daemonize yes #以后臺(tái)進(jìn)程redis運(yùn)行. pidfile /opt/redis/run/redis_6379.pid #若以后臺(tái)進(jìn)程運(yùn)行Reids,則需指定pid文件及路徑. port 6379 #指定redis監(jiān)聽端口. tcp-backlog 511 #在高并發(fā)的環(huán)境中,為避免客戶端的連接緩慢問(wèn)題. bind 0.0.0.0 #綁定主機(jī)IP.(這里設(shè)置為4個(gè)0可以方便程序調(diào)用). timeout 0 #客戶端連接時(shí)的超時(shí)時(shí)間,單位為秒. tcp-keepalive 60 #在 Linux 上,指定值(秒)用于發(fā)送 ACKs 的時(shí)間,注意關(guān)閉連接需要雙倍的時(shí)間.默認(rèn)為 0 loglevel notice #日志記錄等級(jí),有4個(gè)可選值,debug,verbose(默認(rèn)值),notice,warning logfile "/var/log/redis/redis_6379.log" #log 文件地址 databases 16 #可用數(shù)據(jù)庫(kù)數(shù) save 900 1 save 300 10 save 60 10000 #根據(jù)給定的時(shí)間間隔和寫入次數(shù)將數(shù)據(jù)保存到磁盤,單位為秒 stop-writes-on-bgsave-error yes #后臺(tái)存儲(chǔ)錯(cuò)誤停止寫。 rdbcompression yes #存儲(chǔ)至本地?cái)?shù)據(jù)庫(kù)時(shí)(持久化到dump.rdb文件)是否壓縮數(shù)據(jù),默認(rèn)為 yes rdbchecksum yes #是否校驗(yàn)rdb文件. dbfilename dump_6379.rdb #本地持久化數(shù)據(jù)庫(kù)文件名,默認(rèn)值為 dump.rdb dir /opt/redis/data #數(shù)據(jù)庫(kù)鏡像備份的文件放置的路徑。 #slaveof#設(shè)置該數(shù)據(jù)庫(kù)為其他數(shù)據(jù)庫(kù)的從數(shù)據(jù)庫(kù)時(shí)啟用該參數(shù)。 #masterauth #slave服務(wù)連接master的密碼 slave-serve-stale-data yes slave-read-only yes #slave只讀 repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 #requirepass foobared #設(shè)置客戶端連接密碼 appendonly yes #打開aof持久化 appendfilename "appendonly_6379.aof" #aof文件名,默認(rèn)為appendonly.aof appendfsync everysec #每秒一次aof寫 no-appendfsync-on-rewrite yes #關(guān)閉在aof rewrite的時(shí)候?qū)π碌膶懖僮鬟M(jìn)行fsync auto-aof-rewrite-percentage 100 #部署在同一機(jī)器的redis實(shí)例,把a(bǔ)uto-aof-rewrite搓開,因?yàn)閏luster環(huán)境下內(nèi)存占用基本一致. #防止同一機(jī)器下瞬間fork所有redis進(jìn)程做aof rewrite,占用大量?jī)?nèi)存(ps:cluster必須開啟aof) auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes #打開redis集群 cluster-config-file nodes-6379.conf #集群節(jié)點(diǎn)配置文件(啟動(dòng)自動(dòng)生成) cluster-node-timeout 15000 #節(jié)點(diǎn)互連超時(shí)的閥值 cluster-migration-barrier 1 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
192.1.168.1.193 cd /opt/redis redis-server redis_6379.conf redis-server redis_6479.conf redis-server redis_6579.conf 192.1.168.1.193 cd /opt/redis redis-server redis_6379.conf redis-server redis_6479.conf redis-server redis_6579.conf
netstat –lntp
redis-trib.rb create --replicas 1 192.168.1.193:6379 192.168.1.193:6479 192.168.1.193:6579 192.168.1.176:6379 192.168.1.193:6479 192.168.1.193:6579
#redis-trib.rb 的check子命令 #ip:port可以是集群的任意節(jié)點(diǎn) redis-trib.rb check 192.168.1.193:6379
,()ok
empty node
a)
192.168.1.187:6379 192.168.1.187:6479 cd /opt/redis scp redis_6379.conf 192.168.1.187:/opt/redis/ cp redis_6379.conf redis_6479.conf sed –ie s/6379/6479/g redis_6479.conf
b)
redis-server redis_6379.conf
c)
redis-trib.rb add-node 192.168.1.187:6379 192.168.1.193:6379 add-node 將一個(gè)節(jié)點(diǎn)添加到集群里面, 第一個(gè)是新節(jié)點(diǎn)ip:port, 第二個(gè)是任意一個(gè)已存在節(jié)點(diǎn)ip:port
failover
d)
redis-trib.rb reshard 192.168.1.187:6379 #根據(jù)提示選擇要遷移的哈希插槽數(shù)量 How many slots do you want to move (from 1 to 16384)? 1000
#選擇要接受這些哈希插槽的node-id What is the receiving node ID? 36c46361327dbb15d098a0c3794ac3d72869e508
#選擇哈希插槽來(lái)源: #all表示從所有的master重新分配, #或者數(shù)據(jù)要提取哈希插槽的master節(jié)點(diǎn)id,最后用done結(jié)束 Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. Source node #1:all
#打印被移動(dòng)的哈希插槽后,輸入yes開始移動(dòng)哈希插槽以及對(duì)應(yīng)的數(shù)據(jù). #Do you want to proceed with the proposed reshard plan (yes/no)? yes
#
redis-trib.rb check 192.168.1.176:6379
redis-trib.rb check 192.168.1.176:6379 redis-cli -c -p 6379 cluster nodes
a):master
master
b):redis-clishell,:cluster replicate masternode-id192.168.1.187:6379id
redis-cli -h 192.168.1.187 -p 6479 cluster replicate 36c46361327dbb15d098a0c3794ac3d72869e508 exit
:slave bgsavemasterslave slaverdbrdbMasterIO,
法一: #redis-trib del-node ip:port '' redis-trib.rb del-node 192.168.1.187:6479 4655fccff00ef4a7b99c10ffd590c8328ec6db8d
直接停止或kill掉 節(jié)點(diǎn)即可 Redis-cli –p 6479 shutdown or kill -9 `cat /opt/redis/run/redis_6479.pid`
a):masterreshardmasterslot,
#把192.168.1.187:6379當(dāng)前master遷移到192.168.1.176:6579上 redis-trib.rb reshard 192.168.1.176:6579 #根據(jù)提示選擇要遷移的哈希插槽數(shù)量 How many slots do you want to move (from 1 to 16384)? 1000 (被刪除master的所有哈希插槽數(shù)量) #選擇要接受這些哈希插槽的192.168.1.176:6579 What is the receiving node ID? e1c06dd4682a37eb6773d6cb1d5709034a3f2769(ps: 192.168.1.176:6579的node-id) Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. Source node #36c46361327dbb15d098a0c3794ac3d72869e508 (被刪除master的node-id) Source node #2:done
#打印被移動(dòng)的哈希插槽后,輸入yes開始移動(dòng)哈希插槽以及對(duì)應(yīng)的數(shù)據(jù). #Do you want to proceed with the proposed reshard plan (yes/no)? yes
b):master
redis-trib.rb del-node 192.168.1.187:6379 '36c46361327dbb15d098a0c3794ac3d72869e508'
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。