Centos7 Redis5.0.5 三主三從叢集安裝和環境配置
阿新 • • 發佈:2019-07-28
Centos7 Redis5.0.5 三主三從叢集安裝和環境配置
1.下載Redis
開啟redis官網https://redis.io/下載最新版http://download.redis.io/releases/redis-5.0.5.tar.gz
cd /usr/local/00temp
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
2.編譯安裝Redis
需要先安裝gcc編譯器
yum -y install gcc
解壓Redis包然後編譯安裝
tar -zxvf /usr/local/00temp/redis-5.0.5.tar.gz -C /usr/local cd /usr/local/redis-5.0.5 make && make install
二. 建立節點
1. 在/usr/local下建立了一個redis-cluster資料夾用於存放redis節點的配置檔案(redis.conf)
mkdir /usr/local/redis-cluster
cd /usr/local/redis-cluster
mkdir 9000 9001
cp /usr/local/redis-5.0.5/redis.conf /usr/local/redis-cluster/9000
2.修改配置檔案, 9000和9001資料夾下各一個配置檔案 都需要修改
bind 0.0.0.0//開啟網路,保證其他網路可以訪問該機子 port 9000//每個節點的埠號 daemonize yes//守護執行緒 ,後臺執行redis pidfile /var/run/redis_9000.pid appendonly yes//aof日誌每一個操作都記錄模式 cluster-enabled yes//開啟叢集模式 cluster-config-file nodes_9000.conf//叢集節點的配置 cluster-node-timeout 5000//節點請求超時時間
複製上面9000下改好的檔案
cp /usr/local/redis-cluster/9000/redis.conf /usr/local/redis-cluster/9001
9001參照9000的配置只需要把對應埠的地方改了
bind 0.0.0.0//開啟網路,保證其他網路可以訪問該機子 port 9001//每個節點的埠號 daemonize yes//守護執行緒 ,後臺執行redis pidfile /var/run/redis_9001.pid appendonly yes//aof日誌每一個操作都記錄模式 cluster-enabled yes//開啟叢集模式 cluster-config-file nodes_9001.conf//叢集節點的配置 cluster-node-timeout 5000//節點請求超時時間
三. 分發該配置到另外兩臺機器
scp -r /usr/local/redis-cluster 192.168.31.112:/usr/local
#然後輸入root密碼
scp -r /usr/local/redis-cluster 192.168.31.113:/usr/local
#然後輸入root密碼
四. 啟動每臺機器上的兩個節點
cd /usr/local/redis-5.0.5/src
redis-server /usr/local/redis-cluster/9000/redis.conf
redis-server /usr/local/redis-cluster/9001/redis.conf
同樣的操作去另外兩條機器啟動剩下的四個節點。五. 建立叢集
redis5.0叢集建立方式改為了C編寫的redis-cli建立,不用再安裝麻煩的ruby了。
#建立叢集,--cluster-replicas 1指定從庫數量1
cd /usr/local/redis-5.0.5/src
redis-cli --cluster create 192.168.31.111:9000 192.168.31.112:9000 192.168.31.113:9000 192.168.31.111:9001 192.168.31.112:9001 192.168.31.113:9001 --cluster-replicas 1
#建立順序三個主,三個從,前面三個是主後面三個是從
啟動後,可看到成功資訊,如下:
[root@localhost src]# redis-cli --cluster create 192.168.31.111:9000 192.168.31.112:9000 192.168.31.113:9000 192.168.31.111:9001 192.168.31.112:9001 192.168.31.113:9001 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.31.112:9001 to 192.168.31.111:9000
Adding replica 192.168.31.113:9001 to 192.168.31.112:9000
Adding replica 192.168.31.111:9001 to 192.168.31.113:9000
M: d84caba18d4913fdef35bad78b049a42453b9876 192.168.31.111:9000
slots:[0-5460] (5461 slots) master
M: 14cc319ba6b60eccb4412059f6676fc2a34cbd41 192.168.31.112:9000
slots:[5461-10922] (5462 slots) master
M: 0c97db8729b4fa8ff139e4bc163a9d533ccddd70 192.168.31.113:9000
slots:[10923-16383] (5461 slots) master
S: 180e7d0f39fb84827c8c084b74276d3d5bed8c00 192.168.31.111:9001
replicates 0c97db8729b4fa8ff139e4bc163a9d533ccddd70
S: 98d02ee6890df6fcfd9c44b4e3ae361d62c990be 192.168.31.112:9001
replicates d84caba18d4913fdef35bad78b049a42453b9876
S: 7ab7412f40f4223890266f6dfddf3ec7ec2e7515 192.168.31.113:9001
replicates 14cc319ba6b60eccb4412059f6676fc2a34cbd41
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.31.111:9000)
M: d84caba18d4913fdef35bad78b049a42453b9876 192.168.31.111:9000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 7ab7412f40f4223890266f6dfddf3ec7ec2e7515 192.168.31.113:9001
slots: (0 slots) slave
replicates 14cc319ba6b60eccb4412059f6676fc2a34cbd41
S: 98d02ee6890df6fcfd9c44b4e3ae361d62c990be 192.168.31.112:9001
slots: (0 slots) slave
replicates d84caba18d4913fdef35bad78b049a42453b9876
M: 0c97db8729b4fa8ff139e4bc163a9d533ccddd70 192.168.31.113:9000
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 180e7d0f39fb84827c8c084b74276d3d5bed8c00 192.168.31.111:9001
slots: (0 slots) slave
replicates 0c97db8729b4fa8ff139e4bc163a9d533ccddd70
M: 14cc319ba6b60eccb4412059f6676fc2a34cbd41 192.168.31.112:9000
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost src]#