Redis4叢集安裝部署實戰
阿新 • • 發佈:2018-12-25
redis伺服器的叢集主從配置,從redis的安裝到例項開啟,到叢集建立。叢集配置如圖:
So in practical terms, what you get with Redis Cluster?
The ability to automatically split your dataset among multiple nodes.
The ability to continue operations when a subset of the nodes are experiencing failures or are unable to communicate with the rest of the cluster.
1.安裝redis,下載Redis並編譯
在三臺伺服器上分別安裝redis,進行如下操作:
ubuntu需要安裝
sudo apt install tcl8.6
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar xzf redis-4.0.1.tar.gz
$ cd redis-4.0.1
$ make
$ mv /opt/
$ make test
2.叢集檔案配置
resdis叢集整體架構
三臺伺服器,配置如上圖,在每臺伺服器上配置如下(以伺服器3為列)
$ /opt/redis-4.0 .1# mkdir redis-cluster
$ /opt/redis-4.0.1# mkdir redis-cluster/nodes-7004
$ /opt/redis-4.0.1# mkdir redis-cluster/nodes-7005
$ /opt/redis-4.0.1# cp redis.conf redis-cluster/nodes-7004
$ /opt/redis-4.0.1# cp redis.conf redis-cluster/nodes-7005
依次配置redis.conf(以nodes-7005為列)
$ /opt/redis-4.0.1# vim redis-cluster/nodes-7005/redis.conf
port 7005 #在不同的伺服器和nodes-xx中,埠也不同
cluster-enabled yes
bind 10.80.67.238
# daemonize yes #redis後臺執行
cluster-config-file nodes-7005.conf
cluster-node-timeout 5000
appendonly yes
3.依次啟動redis例項
src/redis-server redis-cluster/nodes-7000/redis.conf
後臺啟動
nohup src/redis-server redis-cluster/nodes-7000/redis.conf > redis-cluster/nodes-7000/redis-server.out 2>&1 &
nohup(no hang up) 不掛起,後臺執行程式。並將輸出資訊重定向到
redis-cluster/nodes-7000/redis-server.out
如何關閉?
檢視pidps aux | grep redis
關閉程序kill -9 pid
每個redis例項都有獨立唯一都id,啟動和關閉不會改變id。如上依次開啟6個redis例項。
4.建立叢集
只需在redis-cluster1伺服器上操作
僅需要在redis-cluster1伺服器上安裝gem redis (為來redis-trib可以執行),其他伺服器不用。
gem install redis #預設安裝的版本上3.3(無所謂)
開啟叢集
src/redis-trib.rb create --replicas 1 10.80.67.225:7000 10.80.67.225:7001 10.80.67.230:7002 10.80.67.230:7003 10.80.67.238:7004 10.80.67.238:7005
在Can I set the above configuration? (type 'yes' to accept):
輸入yes
叢集建立完成,執行正常。
[OK] All 16384 slots covered.
意味著叢集中的16384個槽至少有一個主節點在處理。