使用ruby 進行redis叢集安裝
阿新 • • 發佈:2020-07-27
環境:centos7、docker 、有外網
1、下載映象
docker pull redis
docker pull ruby
2、建配置模板
在/home 目錄下建立redis-cluster資料夾並在redis-cluster資料夾下建立配置檔案redis-cluster.conf cd /home && mkdir redis-cluster && touch redis-cluster.conf 開啟redis-cluster.conf 並插入配置資訊如下: cat <<EOF >/home/redis-cluster.conf port \${PORT} cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 192.168.10.44 cluster-announce-port \${PORT} cluster-announce-bus-port 1\${PORT} appendonly yes EOF
3、建網路
docker network create redis-net docker network ls
4、建配置
for port in `seq 6000 6005`; do mkdir -p /home/redis-cluster/${port}/conf && PORT=${port} envsubst < ./redis-cluster.conf > /home/redis-cluster/${port}/conf/redis.conf && mkdir-p /home/redis-cluster/${port}/data;done
5、啟動redis
for port in `seq 6000 6005`; do docker run -d -ti -p ${port}:${port} -p 1${port}:1${port} -v /home/redis-cluster/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf -v /home/redis-cluster/${port}/data:/data --restart always --name redis-${port} --net redis-net --sysctl net.core.somaxconn=1024redis redis-server /usr/local/etc/redis/redis.conf; done
6、加入叢集
echo yes | docker run -i --rm --net redis-net ruby sh -c ' gem install redis && wget http://download.redis.io/redis-stable/src/redis-trib.rb && ruby redis-trib.rb create --replicas 1 '"$(for port in `seq 6000 6005`; do echo -n "$(docker inspect --format '{{ (index .NetworkSettings.Networks "redis-net").IPAddress }}' "redis-${port}")":${port} ' ' ; done)"
7、安裝 redis-cli
cd /tmp wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make 報錯折執行下面語句 make MALLOC=libc cp src/redis-cli /usr/bin/
8、檢測redis叢集
redis-cli -h 192.168.10.44 -p 6000 CLUSTER NODES redis-cli -h 192.168.10.44 -p 6000 -c set a 3 get a