两种安装
原生命令安装--易于理解架构 (生产环境中,一般不使用原生命令安装)
1.配置开启节点
port ${port}
daemonize yes
dir "opt/soft/redis/data"
dbfilename "dump-${port}.rdb"
logfile "${port}.log"
cluster-enabled yes (是否集群节点)
cluster-config-file nodes-${port}.conf(记录所有节点配置)
开启节点:
redis-server redis-7000.conf
redis-server redis-7001.conf
redis-server redis-7002.conf
redis-server redis-7003.conf
redis-server redis-7004.conf
redis-server redis-7005.conf
2.memt(节点通信)
cluster meet ip port
例如:
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7001
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7002
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7003
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7004
redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7005
3.Cluster节点主要配置
cluster-enabled yes
cluster-node-timeout 15000(例如超时时间默认配置15000)
cluster-config-file "nodes.conf"(集群节点的配置)
cluster-require-full-coverage yes (集群中有一个节点down掉,对外就不提供服务了,默认为yes,但我们一般配置为no)
分配槽
cluster addslots slots [slot ....] (Redis Cluster槽的范围是0 ~ 16383,即一共16384个槽。)
例如:
redis-cli -h 127.0.0.1 -p 7000 cluster addslots {0 ...5461}
redis-cli -h 127.0.0.1 -p 7001 cluster addslots {5462 ...10922}
redis-cli -h 127.0.0.1 -p 7002 cluster addslots {10923 ... 16383}
4.设置主从关系
cluster replicate node-id (是指集群节点的id,node-id是不会重置的 replicate 动词复制的意思)
例如:
redis-cli -h 127.0.0.1 -p 7003 cluster replicate ${node-id-7000} (将7003节点复制7000)
redis-cli -h 127.0.0.1 -p 7004 cluster replicate ${node-id-7001}
redis-cli -h 127.0.0.1 -p 7005 cluster replicate ${node-id-7002}
官方工具安装
Ruby环境
Ruby环境准备:
下载,编译,安装Ruby
1.ruby下载
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
2. 安装ruby
tar -xvf ruby-2.3.1.tar.gz
./configure -prefix = /usr/local/ruby
make
make install
cd /usr/local/ruby
cp bin/ruby /usr/local/bin
cp bin/gem/ /usr/local/bin
安装rubygem redis (ruby客户端)
wget https://rubygems.org/downloads/redis/redis-3.0.0.gem
sudo gem install -l redis-3.0.0.gem
sudo gem list -- check redis gem
安装redis-trib.rb
cp ${REDIS_HOME}/src/redis-trib.rb /usr/local/bin
redis-trib.rb搭建集群
配置开启Redis
redis-server redis-8000.conf
redis-server redis-8001.conf
redis-server redis-8002.conf
redis-server redis-8003.conf
redis-server redis-8004.conf
redis-server redis-8005.conf
一键开启
./redis-trib.rb create --replicas 1 127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 127.0.0.1:8004 127.0.0.1:8005
完成!
原生命令和redis-trib.rb对比
1.原生命令安装
优点:理解Redis Cluster架构
缺点:生产环境不可用(一般不用)
2. 官方工具安装
优点:高效,准确。
生产环境可以使用。
3.其他
可视化部署
网友评论