redis 高可用集群模式搭建

redis 高可用集群模式搭建(centos 7)

准备3台linux服务器,分别安装6个redis节点

192.168.15.53 redis1 7000 redis2 7001

192.168.15.54 redis3 7000 redis4 7001

192.168.15.55 redis5 7000 redis6 7001

关闭防火墙

service stop firewalld  && service disable firewalld

redis 安装包下载(每台服务器均需安装)

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
  1. 安装gcc
yum install -y gcc
  1. 解压安装包
#解压安装包
tar -zxvf redis-5.0.5.tar.gz
  1. 编译安装
#进入redis目录执行make
cd redis-5.0.5
make
#进入src目录执行make install
cd src
make install
#进入utils目录执行安装
cd ../utils
./install_server.sh

集群配置文件(每台服务器均需创建)

  1. 创建集群模式redis配置文件

    redis-7000.conf

vi /etc/redis/redis-7000.conf 
daemonize yes
port 7000
logfile 7000.log
dir ./
bind 192.168.15.53 127.0.0.1 #按照实际服务器ip修改

cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 15000

appendonly yes
appendfilename aof-7000.aof
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

​ redis-7001.conf

vi /etc/redis/redis-7001.conf 
daemonize yes
port 7001
logfile 7001.log
dir ./
bind 192.168.15.53 127.0.0.1 ##按照实际服务器ip修改

cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 15000

appendonly yes
appendfilename aof-7001.aof
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

启动redis

#192.168.15.53节点
/usr/local/bin/redis-server ./redis-7000.conf
/usr/local/bin/redis-server ./redis-7001.conf
#192.168.15.54节点
/usr/local/bin/redis-server ./redis-7000.conf
/usr/local/bin/redis-server ./redis-7001.conf
#192.168.15.55节点
/usr/local/bin/redis-server ./redis-7000.conf
/usr/local/bin/redis-server ./redis-7001.conf

redis 高可用集群模式搭建_第1张图片

创建集群

通过redis-cli创建redis集群,指定副本数为1

/usr/local/bin/redis-cli --cluster create 192.168.15.53:7000 192.168.15.54:7000 192.168.15.55:7000 192.168.15.53:7001 192.168.15.54:7001 192.168.15.55:7001 --cluster-replicas 1

查看集群节点状态

./redis-cli -c -p 7000
cluster nodes

在这里插入图片描述
redis 高可用集群模式搭建_第2张图片

你可能感兴趣的:(redis,高可用方案)