Redis集群需要至少6个节点,3主3从,由于服务器资源有些,这里使用3台机器6个端口实现。
#########################
Part1 redis依赖安装
#########################
-
yum install gcc
-
tcl安装
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
rsync -e 'ssh -p 20462' tcl8.6.1-src.tar.gz root@172.36.27.72:/opt/install/
rsync -e 'ssh -p 20462' tcl8.6.1-src.tar.gz root@172.36.27.72:/opt/install/
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make && make install
- ruby安装
wget http://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.5.tar.gz
rsync -e 'ssh -p 20462' ruby-2.3.5.tar.gz root@172.36.27.71:/opt/install/
rsync -e 'ssh -p 20462' ruby-2.3.5.tar.gz root@172.36.27.72:/opt/install/
tar -xvf ruby-2.3.5.tar.gz
cd ruby-2.3.5
./configure --prefix=/opt/ruby
make && make install
ln -s /opt/ruby/bin/ruby /usr/bin/ruby
ln -s /opt/ruby/bin/gem /usr/bin/gem
- rubygem安装
wget http://rubygems.org/downloads/redis-4.0.1.gem
rsync -e 'ssh -p 20462' redis-4.0.1.gem root@172.36.27.71:/opt/install/
rsync -e 'ssh -p 20462' redis-4.0.1.gem root@172.36.27.72:/opt/install/
gem install -l redis-4.0.1.gem
- yum -y install zlib-devel
进入ruby源码文件夹,安装ruby自身提供的zlib包
cd ruby-2.3.5/ext/zlib
ruby ./extconf.rb
make
make install
#########################
Part2 redis下载安装
#########################
wget http://download.redis.io/releases/redis-4.0.0.tar.gz
tar xzf redis-4.0.0.tar.gz
cd redis-4.0.0
#make(make MALLOC=libc)
cd src/
make test
make install
#########################
Part3 redis集群搭建
######################### redis集群的最小单元是3主3从,即6个节点,这里我们用三台物理机,6个端口实现, 三主:6239 三从:6339 host1: 172.36.27.72 host2: 172.36.27.71 host1: 172.36.27.70
分别在3台机器上创建端口目录:
mkdir -p /data/redis-cluster/logs
mkdir -p /data/redis-cluster/{6239,6339}
mkdir -p /data/redis-cluster/{6239,6339}
mkdir -p /data/redis-cluster/{6239,6339}
copy配置文件并修改
cp /opt/install/redis-4.0.0/redis.conf /data/redis-cluster/6239/node_6239.conf
cp /opt/install/redis-4.0.0/redis.conf /data/redis-cluster/6339/node_6339.conf
vim node_6239.conf
bind 0.0.0.0
port 6239
daemonize yes
pidfile /var/run/redis_6239.pid
logfile "/data/redis-cluster/logs/6239.log"
dir /data/redis-cluster/6239/
cluster-enabled yes
cluster-config-file cluster-node-6239.conf
cluster-node-timeout 15000
masterauth Password
requirepass Password
vim node_6339.conf
bind 0.0.0.0
port 6339
daemonize yes
pidfile /var/run/redis_6339.pid
logfile "/data/redis-cluster/logs/6339.log"
dir /data/redis-cluster/6339/
cluster-enabled yes
cluster-config-file cluster-node-6339.conf
cluster-node-timeout 15000
masterauth Password
requirepass Password
#vim编辑替换
:%s/6239/6339/g
#启动3台服务器上的6个redis节点,创建集群,每个节点一个副本
redis-server /data/redis-cluster/6239/node_6239.conf
redis-server /data/redis-cluster/6339/node_6339.conf
cd /opt/install/redis-4.0.0
./redis-4.0.0/src/redis-trib.rb create --replicas 1 172.36.27.72:6239 172.36.27.72:6339 172.36.27.71:6239 172.36.27.71:6339 172.36.27.70:6239 172.36.27.70:6339
##检查集群完整性
cd /opt/install/redis-4.0.0
./src/redis-trib.rb check 172.36.27.72:6339
##登录查看集群状态
redis-cli -h 172.36.27.72 -p 6239 -a Password
> cluster info
##redis重启 //停止某个节点服务
redis-cli -h 172.36.27.71 -p 6239 -a Password shutdown
redis-cli -h 172.36.27.70 -p 6339 -a Password shutdown
//启动某个节点服务
redis-server /data/redis-cluster/6239/node_6239.conf
redis-server /data/redis-cluster/6339/node_6339.conf
###动态修改密码写入文件
redis-cli -h 172.36.27.70 -p 6239 -c
config set masterauth xxx
config set requirepass xxx
config rewrite
###spring boot整合配置
spring.redis.database=0
spring.redis.cluster.nodes=172.36.27.72:6239,172.36.27.72:6339,172.36.27.71:6239,172.36.27.71:6339,172.36.27.70:6239,172.36.27.70:6339
spring.redis.password=Password
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0
spring.redis.timeout=0