阿里雲環境遷移記錄 - Redis集羣搭建

Redis集羣須要至少6個節點,3主3從,因爲服務器資源有些,這裏使用3臺機器6個端口實現。node

#########################redis

Part1 redis依賴安裝

#########################spring

  1. yum install gccvim

  2. tcl安裝ruby

    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
  3. 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
  4. rubygem安裝ssh

    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
  5. yum -y install zlib-devel
    進入ruby源碼文件夾,安裝ruby自身提供的zlib包
    cd ruby-2.3.5/ext/zlib
    ruby ./extconf.rb
    make
    make install

#########################ide

Part2 redis下載安裝

#########################ui

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

#########################.net

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
相關文章
相關標籤/搜索