redis叢集搭建(docker)
阿新 • • 發佈:2021-06-28
記錄一下:
1 運行了一個ubantu映象
docker run -itd -p 10001:10001 -p 10002:10002 -p 10003:10003 -p 10004:10004 -p 10005:10005 -p 10006:10006 映象名 /bin/bash
2 下載redis
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
3 ubantu 映象真乾淨 (沒有make gcc)
yum install gcc gcc-c++ make automake autocon
4 解壓
tar xzf redis-6.0.6.tar.gz cd redis-6.0.6 make make install
5 執行測試
redis-server
redis-cli
6 開始搭建
mkdir -p /usr/local/redis-cluster/
cd /usr/local/redis-cluster/
mkdir 10001 10002 10003 10004 10005 10006
# cd 到 redis-6.0.6
cp redis.conf /usr/local/redis-cluster/10001
vim /usr/local/redis-cluster/10001/redis.conf
7 配置redis.conf (vim 中 /字串) 查詢
bind 172.17.0.2 # 自己的容器ip
port 10001 # 埠儘量與資料夾一致
daemonize yes # 設定守護
dir /usr/local/redis-cluster/10001/ # 指定配置檔案路徑
appendonly yes # 開啟日誌
cluster-enabled yes # 開啟叢集
cluster-config-file nodes-10002.conf # 指定節點檔案
cluster-node-timeout 5000
8 執行測試
redis-server /usr/local/redis-cluster/10001/redis.conf
9 配置多個節點( vim 命令 /%s/舊字串/新字串/g) 全域性替換
cp /usr/local/redis-custer/10001/redis.conf /usr/local/redis-custer/10002/
vim /usr/local/redis-custer/10002/redis.conf
/%s/10001/10002/g
.....
....
...
..
.
10.執行測試
redis-server /usr/local/redis-cluster/10001/redis.conf
redis-server /usr/local/redis-cluster/10002/redis.conf
redis-server /usr/local/redis-cluster/10003/redis.conf
redis-server /usr/local/redis-cluster/10004/redis.conf
redis-server /usr/local/redis-cluster/10005/redis.conf
redis-server /usr/local/redis-cluster/10006/redis.conf
ps -ef |grep redis
11.建立叢集 (redis5.0 之後 不在採用ruby 啟動 而是c)
redis-cli --cluster create 172.17.0.2:10001 172.17.0.2:10002 172.17.0.2:10003 172.17.0.2:10004 172.17.0.2:10005 172.17.0.2:10006 --cluster-replicas 1
成功 ....
12 驗證
redis-cli -c -p 172.17.0.2 -p 10001 cluster-info # 檢視叢集資訊 cluster nodes # 檢視節點詳細資訊
13 殺掉叢集
# kill 掉 ps -ef | grep redis 程序
rm /usr/local/redis-custer/10001/redis-nodes-10002.conf appendonly.aof # 刪除這兩個檔案
# 再重複 10, 11