安装redis5三从三主集群

安装redis

  • 下载安装redis-5.0.5(这里我用得是最新版)

wget http://download.redis.io/releases/redis-5.0.5.tar.gz

  • 解压压缩包

tar -zxvf redis-5.0.5.tar.gz

  • 编译redis

首先安装编译依赖

yum install gcc-c++ tcl

进入文件夹编译文件

cd redis-5.0.5

make

make test

  • 安装redis

make install PREFIX=/usr/local/redis

配置redis集群

创建集群文件

mkdir /usr/local/redis-cluster

mkdir /usr/local/redis-cluster/7000

mkdir /usr/local/redis-cluster/7001

mkdir /usr/local/redis-cluster/7002

mkdir /usr/local/redis-cluster/7003

mkdir /usr/local/redis-cluster/7004

mkdir /usr/local/redis-cluster/7005

cp /home/redis/redis-5.0.5/redis.conf /usr/local/redis-cluster/7000/

修改集群配置

port 7000 //端口

bind 0.0.0.0 //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群,我们这里写0.0.0.0
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置
appendonly yes  //开启aof
requirepass ssxx #设置redis访问密码

masterauth ssxx #设置redis集群间的访问密码,同上面密码一致

将7000中得redis.conf复制到其他文件夹下,并修改相应的70001

创建启动redis脚本

vim /usr/local/redis-cluster/start-redis.sh

/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7000/redis.conf;
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7001/redis.conf;
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7002/redis.conf;
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7003/redis.conf;
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7004/redis.conf;
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7005/redis.conf;

赋予权限

chmod 777 start-redis.sh

创建启动redis集群脚本

vim /usr/local/redis-cluster/redis-cli.sh

/usr/local/redis/bin/redis-cli --cluster create -c 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 -a 123456Aa! --cluster-replicas 1

启动集群

./start-redis.sh

./redis-cli.sh

输入yes 启动成功

查看集群

ps -ef|grep redis

注意:阿里云服务器需要开启安全组端口,7000,7001,7002,7003,7004,7005,17000,17001,17002,17003,17004,17005

你可能感兴趣的:(redis,redis,centos,集群)