准备工作
添加Redis对应端口到ip白名单
systemctl status firewalld
Active: inactive (dead) --关闭
Active: active (running) --运行中
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=6001/tcp --permanent
firewall-cmd --zone=public --add-port=6002/tcp --permanent
firewall-cmd --zone=public --add-port=6003/tcp --permanent
firewall-cmd --zone=public --add-port=6004/tcp --permanent
firewall-cmd --zone=public --add-port=6005/tcp --permanent
firewall-cmd --zone=public --add-port=6006/tcp --permanent
firewall-cmd --reload
systemctl start firewalld
firewall-cmd --zone=public --list-ports
安装ruby
ruby --version
curl -sSL https://get.rvm.io | bash -s stable
##引入证书
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
curl -sSL https://get.rvm.io | bash -s stable
source /usr/local/rvm/scripts/rvm
rvm list known
##选一个版本的ruby
rvm reload
rvm install 2.2.2
ruby --version
安装Redis
mkdir -p {/usr/dev/redis_cluster/log,/usr/dev/redis_cluster/6001,/usr/dev/redis_cluster/6002,/usr/dev/redis_cluster/6003,/usr/dev/redis_cluster/6004,/usr/dev/redis_cluster/6005,/usr/dev/redis_cluster/6006,/usr/dev/redis_cluster/6007,/usr/dev/redis_cluster/6008,/usr/dev/redis_cluster/6009,/usr/dev/redis_cluster/6010}
vi /usr/dev/redis_cluster/redis.conf
port 6001
dbfilename 6001.rdb
cluster-config-file nodes-6001.conf
pidfile /usr/dev/redis_cluster/redis_6001.pid
logfile "/usr/dev/redis_cluster/log/6001.log"
appendfilename "appendonly_6001.aof"
bind 10.115.1.25
protected-mode yes
cluster-enabled yes
daemonize yes
appendonly yes
cluster-node-timeout 15000
echo /usr/dev/redis_cluster/6001 /usr/dev/redis_cluster/6002 /usr/dev/redis_cluster/6003 /usr/dev/redis_cluster/6004 /usr/dev/redis_cluster/6005 /usr/dev/redis_cluster/6006 /usr/dev/redis_cluster/6007 /usr/dev/redis_cluster/6008 | xargs -n 1 cp -v /usr/dev/redis_cluster/redis.conf
##编辑对应redis.conf
vi /usr/dev/redis_cluster/600*/redis.conf
wget http://download.redis.io/releases/redis-3.2.1.tar.gz /usr/dev/
tar zxvf /usr/dev/redis-3.2.1.tar.gz -C /usr/dev/
cd /usr/dev/redis-3.2.1
make
chmod 755 -R /usr/dev/redis_cluster
gem install redis -v 3.2.1
##启动各节点
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6001/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6002/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6003/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6004/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6005/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6006/redis.conf
/usr/dev/redis-3.2.1/src/redis-trib.rb create --replicas 1 10.115.1.25:6001 10.115.1.25:6002 10.115.1.25:6003 10.115.1.25:6004 10.115.1.25:6005 10.115.1.25:6006
验证
/usr/dev/redis-3.2.1/src/redis-cli -c -h 10.115.1.25 -p 6001
##cluster nodes
##查看dbsize
/usr/dev/redis-3.2.1/src/redis-trib.rb info 10.115.1.25:6001
扩容
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6007/redis.conf
/usr/dev/redis-3.2.1/src/redis-server /usr/dev/redis_cluster/6008/redis.conf
##如果添加的是主节点,只需指定源节点和目标节点的地址即可
/usr/dev/redis-3.2.1/src/redis-trib.rb add-node 10.115.1.25:6007 10.115.1.25:6001
##如果添加的是从节点,其语法如下[注意:--slave和--master-id必须写在前面,同样的参数,如果是下面这样写法,会提示错]
/usr/dev/redis-3.2.1/src/redis-trib.rb add-node --slave --master-id b976432fac89d66876a7ced89dcc0d0be85cc13f 10.115.1.25:6008 10.115.1.25:6001
##先模拟查看redis cluster 的执行计划
##模拟rebalance
/usr/dev/redis-3.2.1/src/redis-trib.rb rebalance --use-empty-masters --simulate 10.115.1.25:6001
##执行rebalance
/usr/dev/redis-3.2.1/src/redis-trib.rb rebalance --use-empty-masters 10.115.1.25:6001
##验证
/usr/dev/redis-3.2.1/src/redis-trib.rb info 10.115.1.25:6001
rebalance 前
rebalance 后
## yml
spring:
#redis cluster 配置
redis:
timeout: 10000
cluster:
nodes: 10.115.1.25:6001
maxRedirects: 6
pool:
max-active: 1024 #最大连接数
max-idle: 10 #最大空闲连接数
max-wait: -1 #获取连接最大等待时间 ms
##
zip -r redis_cluster.zip redis_cluster
unzip -n /usr/dev/redis_cluster.zip -d /usr/dev
来源:oschina
链接:https://my.oschina.net/u/3664884/blog/2874056