您好,登錄后才能下訂單哦!
redis集群是一個無中心的分布式redis存儲架構,可以在多個節點之間進行數據共享,解決了redis高可用、可擴展等問題,redis集群提供了以下兩個好處: 1)將數據自動切分(split)到多個節點 2)當集群中的某一個節點故障時,redis還可以繼續處理客戶端的請求。
Redis Cluster的特點如下:
? 節點自動發現
? slave->master選舉,集群容錯
? Hot resharding:在線分片
? 集群管理:clusterxxx
? 基于配置(nodes-port.conf)的集群管理
? ASK 轉向/MOVED轉向機制
? 布署無需指定master
? 可以支持超過1,000臺節點的集群
服務器IP 主機名|安裝組件 備注
192.168.27.211 Client1 redis-5.0.5 集群各結點,單個結點開三個服務進程模擬三臺服務器。
192.168.27.212 Client2 redis-5.0.5
192.168.27.213 Client3 redis-5.0.5
192.168.27.210 master ansible 堡壘機
官方最新版下載地址:http://download.redis.io/releases/redis-5.0.5.tar.gz
解壓并編譯安裝:
192.168.27.211配置文件配置:(切換用戶后注意權限sudo chown jerry.root -R redis-5.0.5所有結點)
mkdir /data/redis-5.0.5/redis-cluster/{7000,7001,7002} -pv
[jerry@client1 redis-cluster]$ cat 7000/redis.conf
port 7000
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7000.pid
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 10100
appendonly yes
[jerry@client1 redis-cluster]$ cat 7001/redis.conf
port 7001
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7001.pid
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 10100
appendonly yes
[jerry@client1 redis-cluster]$ cat 7002/redis.conf
port 7002
bind 192.168.27.211
daemonize yes
pidfile /var/run/redis_7002.pid
cluster-enabled yes
cluster-config-file nodes_7002.conf
cluster-node-timeout 10100
appendonly yes
服務器:192.168.27.212:
[jerry@client2 redis-5.0.5]$ mkdir /data/redis-5.0.5/redis-cluster/{7003,7004,7005} -pv
[jerry@client2 redis-cluster]$ for i in {3,4,5} ; do cat ./700$i/redis.conf ; done
port 7003
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7003.pid
cluster-enabled yes
cluster-config-file nodes_7003.conf
cluster-node-timeout 10100
appendonly yes
port 7004
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7004.pid
cluster-enabled yes
cluster-config-file nodes_7004.conf
cluster-node-timeout 10100
appendonly yes
port 7005
bind 192.168.27.212
daemonize yes
pidfile /var/run/redis_7005.pid
cluster-enabled yes
cluster-config-file nodes_7005.conf
cluster-node-timeout 10100
appendonly yes
192.168.27.213配置文件:
[jerry@client3 redis-5.0.5]$ mkdir /data/redis-5.0.5/redis-cluster/{7006,7007,7008} -pv
port 7006
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7006.pid
cluster-enabled yes
cluster-config-file nodes_7006.conf
cluster-node-timeout 10100
appendonly yes
port 7007
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7007.pid
cluster-enabled yes
cluster-config-file nodes_7007.conf
cluster-node-timeout 10100
appendonly yes
port 7008
bind 192.168.27.213
daemonize yes
pidfile /var/run/redis_7008.pid
cluster-enabled yes
cluster-config-file nodes_7008.conf
cluster-node-timeout 10100
appendonly yes
啟動各結點上的redis
[jerry@client1 redis-cluster]$ for i in {0..2}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
[jerry@client2 redis-cluster]$ for i in {3..5}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
[jerry@client3 redis-cluster]$ for i in {6..8}; do /data/redis-5.0.5/src/redis-server /data/redis-5.0.5/redis-cluster/700$i/redis.conf; done
用堡壘機查看下各結點啟動情況:
[root@master ~]# ansible k8s -m shell -a'ps -ef |grep redis'
[jerry@client1 src]$ ./redis-trib.rb create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
報錯:
安裝ruby組件:https://centos.pkgs.org/7/centos-sclo-rh-x86_64/rh-ruby22-ruby-devel-2.2.2-16.el7.x86_64.rpm.html(集群中某一結點安裝即可)
yum install centos-release-scl-rh
yum install rh-ruby22-ruby-devel
[jerry@client1 src]$ sudo yum -y install ruby ruby-devel rubygems rpm-build
[jerry@client1 src]$ sudo ./redis-trib.rb create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
提示5.0.5版本命令已經更換.
格式不對:
[jerry@client1 src]$ sudo ./redis-cli create --replicas 1 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008
Could not connect to Redis at 127.0.0.1:6379: Connection refused
新版正確格式:
[jerry@client1 src]$ sudo ./redis-cli --cluster create 192.168.27.211:7000 192.168.27.211:7001 192.168.27.211:7002 192.168.27.212:7003 192.168.27.212:7004 192.168.27.212:7005 192.168.27.213:7006 192.168.27.213:7007 192.168.27.213:7008 --cluster-replicas 1
訪問:
測試觀察集群:
211上連接設置一個鍵值name,值設置為jerry
嘗試212上獲取鍵值
213服務器上更改name值
211上再次攻取其值:
212上再次獲取其值:
集群信息查看:
192.168.27.211:7000> cluster info
注意新版命令有所變化:
參考文獻:https://redis.io/topics/cluster-tutorial
https://blog.serverdensity.com/monitor-redis/
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。