Redis單機安裝|叢集安裝|6臺伺服器 三主三備
阿新 • • 發佈:2018-12-25
此文章中需要的安裝檔案可以從我的網盤下載相同版本的安裝檔案
1、需要在六臺伺服器上面都安裝上redis,將redis-3.0.2.tar.gz分別上傳到六臺伺服器上面。 > tar xvf redis-3.0.2.tar.gz > cd redis-3.0.2 > make > make install PREFIX=/home/advert/redis 如圖則成功2、啟動redis (1) 前臺啟動 > cd redis/bin/ > ./redis-server 如圖則啟動成功
(2) 後端啟動
在伺服器的/home/advert/redis目錄下面有一下兩個目錄
接下來正式建立叢集 建立一個資料夾redis-cluster,將redis檔案複製到redis-cluster檔案下,並且重名成redis01複製6個 > cd > mkdir redis-cluster > cp -R redis redis-cluster/redis01 > cd redis-cluster > cp -R redis01 redis02 > cp -R redis01 redis03
> cp -R redis01 redis04
> cp -R redis01 redis05
> cp -R redis01 redis06
修改
安裝redis和ruby的依賴包 使用redis-trib.rb檔案建立叢集 ./redis-trib.rb create --replicas 1 192.168.2.1:7001 192.168.2.1:7002 192.168.2.1:7003 192.168.2.1:7004 192.168.2.1:7005 192.168.2.1:7006
解釋下這個指令碼 ./redis-trib.rb 執行指令碼 create --replicas 建立叢集 1 一個備份 192.168.2.1:7001 192.168.2.1:7002 192.168.2.1:7003 192.168.2.1:7004 192.168.2.1:7005 192.168.2.1:7006 由於是一臺伺服器,所以ip都是一樣的,他們的埠不同 至此一臺六個例項的建立好了 再介紹6臺3主3備的,6臺的叢集的安裝流程和一臺也一樣 首先,在六臺上面都上傳redis的壓縮包並且解壓安裝具體安裝方式可以參考前面,大致都是make && make install等等 六臺伺服器都複製redis.conf檔案到redis/bin資料夾下,需要兩個地方 將daemonize no改為daemonize yes 去掉cluster-enable yes前面的#註釋 注意:埠不用修改,在一臺的時候需要不同的埠,現在在六臺不需要區別埠 接下來,分別啟動六臺伺服器的redis,接下來的操作都是在第一臺伺服器上面操作的,不需要再在其他五臺伺服器有任何操作 按照上面的要求,在第一臺伺服器上面安裝ruby,安裝依賴包redis-3.0.0.gem
之後建立叢集 ./redis-trib.rb create --replicas 1 192.168.2.1:7001 192.168.2.2:7001 192.168.2.3:7001 192.168.2.4:7001 192.168.2.5:7005 192.168.2.6:7001
這行命令的中六臺伺服器的ip不同,埠都可以採用7001 執行命令後看到下面提示,即安裝成功 [email protected]D:~> ./redis-trib.rb create --replicas 1 192.168.2.1:7001 192.168.2.2:7001 192.168.2.3:7001 192.168.2.4:7001 192.168.2.5:7001 192.168.2.6:7001 >>> Creating cluster Connecting to node 192.168.2.1:7001: OK Connecting to node 192.168.2.2:7001: OK Connecting to node 192.168.2.3:7001: OK Connecting to node 192.168.2.4:7001: OK Connecting to node 192.168.2.5:7001: OK Connecting to node 192.168.2.6:7001: OK >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.2.1:7001 192.168.2.1:7001 192.168.2.1:7001 Adding replica 192.168.2.4:7001 to 192.168.2.1:7001 Adding replica 192.168.2.5:7001 to 192.168.2.2:7001 Adding replica 192.168.2.6:7001 to 192.168.2.3:7001 M: 02b79605ab98aff02205a8abebc1f004c2c0990d 192.168.2.1:7001 slots:0-5460 (5461 slots) master M: 7d657993f8afbfe2762c6e5e3a9b5c004f075da2 192.168.2.2:7001 slots:5461-10922 (5462 slots) master M: 5f5cd4545895a7b8271c8a7fe62819cabef39bf0 192.168.2.3:7001 slots:10923-16383 (5461 slots) master S: 6682374bf5ab841a600c032f0eefb304c4a742ea 192.168.2.4:7001 replicates 02b79605ab98aff02205a8abebc1f004c2c0990d S: a4250ce009c5097b1ad2ceb21d78351655a84843 192.168.2.5:7001 replicates 7d657993f8afbfe2762c6e5e3a9b5c004f075da2 S: 6587cfa79933d1ef7396589b9541af8b75d68fbd 192.168.2.6:7001 replicates 5f5cd4545895a7b8271c8a7fe62819cabef39bf0 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.... >>> Performing Cluster Check (using node 192.168.23.208:7001) M: 02b79605ab98aff02205a8abebc1f004c2c0990d 192.168.2.1:7001 slots:0-5460 (5461 slots) master M: 7d657993f8afbfe2762c6e5e3a9b5c004f075da2 192.168.2.2:7001 slots:5461-10922 (5462 slots) master M: 5f5cd4545895a7b8271c8a7fe62819cabef39bf0 192.168.2.3:7001 slots:10923-16383 (5461 slots) master M: 6682374bf5ab841a600c032f0eefb304c4a742ea 192.168.2.4:7001 slots: (0 slots) master replicates 02b79605ab98aff02205a8abebc1f004c2c0990d M: a4250ce009c5097b1ad2ceb21d78351655a84843 192.168.2.5:7001 slots: (0 slots) master replicates 7d657993f8afbfe2762c6e5e3a9b5c004f075da2 M: 6587cfa79933d1ef7396589b9541af8b75d68fbd 192.168.2.6:7001 slots: (0 slots) master replicates 5f5cd4545895a7b8271c8a7fe62819cabef39bf0 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [email protected]:~> 問題描述: 在執行gem install redis-3.2.0.gem的時候提示下面錯誤 ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources 這個問題,基本配置下gem的源就可以解決,但是如果的伺服器是無法訪問網路的,可以執行 gem install redis-3.2.0.gem --local