1、環(huán)境說明
成都創(chuàng)新互聯(lián)公司專注于岳陽樓網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供岳陽樓營銷型網(wǎng)站建設(shè),岳陽樓網(wǎng)站制作、岳陽樓網(wǎng)頁設(shè)計、岳陽樓網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)公司服務(wù),打造岳陽樓網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供岳陽樓網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。在此文章中不對redis做詳細(xì)介紹,如果對redis不太了解的朋友可以參考此鏈接 http://www.runoob.com/redis/redis-tutorial.html
要讓redis集群正常工作至少需要3個主節(jié)點,在這里我們要創(chuàng)建6個redis節(jié)點,其中三個為主節(jié)點,三個為從節(jié)點,對應(yīng)的redis節(jié)點的ip和端口對應(yīng)關(guān)系如下:
主機(jī)和端口 |
192.168.102.51:6379、192.168.102.51:6380 |
192.168.102.52:6379、192.168.102.52:6380 |
192.168.102.53:6379、192.168.102.53:6380 |
說明:3臺服務(wù)器部署redis集群環(huán)境,如果你只用于測試部署,可在1臺服務(wù)器上配置,不過端口別重復(fù)就行。
2、準(zhǔn)備redis相關(guān)依賴包
( 在這3臺服務(wù)器都需要安裝)
包名 | 下載地址 |
zlib-1.2.8.tar.gz | http://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz |
ruby-2.2.4.tar.bz2 | https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 |
rubygems-2.5.1.tgz | https://rubygems.global.ssl.fastly.net/rubygems/rubygems-2.5.1.tgz |
redis-3.2.2.gem | https://rubygems.global.ssl.fastly.net/gems/redis-3.2.2.gem |
redis-3.2.3.tar.gz | http://download.redis.io/releases/redis-3.2.3.tar.gz |
2.1 安裝zlib
# gunzip zlib-1.2.8.tar.gz # tar -xvf zlib-1.2.8.tar # cd zlib-1.2.8 # ./configure # make # make install |
2.2 安裝ruby
# bunzip2 ruby-2.2.4.tar.bz2 # tar -xvf ruby-2.2.4.tar # cd ruby-2.2.4 # ./configure -prefix=/usr/local/ruby # make Generating RDoc documentation Parsing sources... 100% [967/967] vsnprintf.c Generating RI format into /root/ruby-2.2.4/.ext/rdoc... Files: 967 Classes: 1411 ( 581 undocumented) Modules: 280 ( 108 undocumented) Constants: 2160 ( 594 undocumented) Attributes: 1156 ( 255 undocumented) Methods: 10488 (2187 undocumented) Total: 15495 (3725 undocumented) 75.96% documented Elapsed: 744.0s # make install # cp ruby /bin |
2.3 安裝rubygems
# tar -zxvf rubygems-2.5.1.tgz # cd rubygems-2.5.1 # ruby setup.rb # cp bin/gem /bin |
注意:編譯中出現(xiàn)in 'require': cannot load such file -- json/pure (LoadError)的解決方法:
# gem install json_pure
Fetching: json_pure-1.8.3.gem (100%)
Successfully installed json_pure-1.8.3
Parsing documentation for json_pure-1.8.3
Installing ri documentation for json_pure-1.8.3
1 gem installed
2.4 安裝gem-redis
# gem install -l redis-3.2.2.gem Successfully installed redis-3.2.2 Parsing documentation for redis-3.2.2 Installing ri documentation for redis-3.2.2 1 gem installed |
3、安裝redis( 在這3臺服務(wù)器都需要安裝)
解壓、編譯
# tar -zxvf redis-3.2.3.tar.gz # cd redis-3.2.3 # make |
創(chuàng)建redis所需目錄
#mkdir -p /usr/local/redis/{bin,conf,data,logs} ##創(chuàng)建redis相關(guān)目錄 # cp src/redis-server /usr/local/redis/bin/ ##Redis服務(wù)器的daemon啟動程序 # cp src/redis-cli /usr/local/redis/bin/ ##Redis命令行操作工具 # cp src/redis-trib.rb /usr/local/redis/bin/ ##Redis Cluster工具 # cp src/redis-benchmark /usr/local/redis/bin/ ##Redis性能測試工具 # cp src/redis-check-aof /usr/local/redis/bin/ ##修復(fù)壞損壞的aof文件 # cp src/redis-check-dump /usr/local/redis/bin/ ##檢查導(dǎo)出工具 # cp src/redis-sentinel /usr/local/redis/bin/ ##Redis集群的管理工具 |
說明:如果你不想跟上面那樣麻煩操作,也可直接復(fù)制src目錄下所有的文件至 /usr/local/redis/bin/中
比如:cp src/* /usr/local/redis/bin/
復(fù)制redis配置文件
# cp redis.conf /usr/local/redis/conf/redis-6379.conf # cp redis.conf /usr/local/redis/conf/redis-6380.conf |
修改redis配置文件(修改紅色字體部分)
bind 0.0.0.0 #redis服務(wù)監(jiān)聽的地址 protected-mode yes port 6379 #如果是redis-6380.conf配置文件,修改為6380 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes #修改為yes,讓redis在后臺運行 supervised no pidfile /var/run/redis_6379.pid #如果是redis-6380.conf配置文件,修改為redis_6380.pid loglevel notice logfile /usr/local/redis/logs/redis-6379.log #如果是redis-6380.conf配置文件,修改為redis_6380.pid databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir ./ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes cluster-config-file nodes-51-6379.conf #如果是redis-6380.conf配置文件,修改為nodes-51-6380.conf cluster-node-timeout 5000 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-size -2 list-compress-depth 0 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 |
cluster-config-file nodes-51-6379.conf #這條配置要特別說明一下
一定要注意,這3臺服務(wù)器這條配置的名字最好不要取一樣的,建議按下面的方式取名(當(dāng)然你可以自己規(guī)定):
192.168.102.51:nodes-51-6379.conf nodes-51-6380.conf
192.168.102.52:nodes-52-6379.conf nodes-52-6380.conf
192.168.102.53:nodes-53-6379.conf nodes-53-6380.conf
說明:如果需要了解redis更多配置文件的詳細(xì)說明,請參考下面的鏈接
http://blog.csdn.net/neubuffer/article/details/17003909
4、redis集群啟動
4.1 redis實例啟動(按順序挨個啟動,先啟動6379、后啟動6380):
#/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6379.conf #分別按相順序啟動這3臺服務(wù)器的6379實例 #/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis-6380.conf #分別按相順序啟動3臺服務(wù)器的6380實例 |
然后檢查實例是否啟動正常:
#ps -ef | grep redis |
4.2 創(chuàng)建集群 (在第1臺redis服務(wù)器上創(chuàng)建,并執(zhí)行以下命令)
#/usr/local/redis/bin//bin/redis-trib.rb create --replicas 1 192.168.102.51:6379 192.168.102.52:6379 192.168.102.53:6379 192.168.102.51:6380 192.168.102.52:6380 192.168.102.53:6380 |
Can I set the above configuration? (type 'yes' to accept): yes #這里要輸入yes
查看集群節(jié)點:
檢測集群:
查看集群主節(jié)點:
如出現(xiàn)以上這些信息,說明集群安裝成功。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。