redis5.0.7安装及配置集群

Posted 阳家坡对面的荫凉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis5.0.7安装及配置集群相关的知识,希望对你有一定的参考价值。

1.安装环境linux系统,时间2020年2月

2.官网下载https://redis.io/

3.解压

tar -zxvf redis-5.0.7.tar.gz

4.配置文件

 1 //创建etc文件夹,bin文件夹
 2 [~]#cp redis.conf redis_copy.conf
 3 [~]#mv redis.conf ./etc/
 4 [~]#cd src
 5 [~]mv mkreleasehdr.sh   redis-check-aof redis-check-rdb redis-cli redis-server redis-trib.rb redis-benchmark ../bin/
 6 //创建8000-8005文件夹,在etc
 7 [~]#cd ../etc
 8 [~]#mkdir 8000
 9 [~]#mkdir 8001
10 [~]#mkdir 8002
11 [~]#mkdir 8003
12 [~]#mkdir 8004
13 [~]#mkdir 8005
14 [~]cp ../redis.conf ./8000/

4.1配置8000文件夹下的redis.conf,并复制到其他文件下

1 port 8000 //端口
2 bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群 ,或者注释掉
3 daemonize yes //redis后台运行 
4 pidfile /var/run/redis_8000.pid //pidfile文件对应8000, 
5 cluster-enabled yes //开启集群 把注释#去掉 
6 cluster-config-file nodes_8000.conf //集群的配置 配置文件首次启动自动生成 80002 把注释#去掉 
7 cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置  把注释#去掉 
8 appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志

5.编写启动sh和停止sh

redis官网:The first example, that is, the cluster creation, will be shown using both redis-cli in Redis 5 and redis-trib in Redis 3 and 4. However all the next examples will only use redis-cli, 
since as you can see the syntax is very similar, and you can trivially change one command line into the other by using redis-trib.rb help to get info about the old syntax.
Important: note that you can use Redis 5 redis-cli against Redis 4 clusters without issues if you wish. 从5.0之后,可以不用ruby启动集群,3,4还是要的。例如:
redis-cli --cluster create 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 --cluster-replicas 1
//编写一个简单的startall.sh启动
[~]#touch startall.sh
[~]#vim startall.sh
cd /home/software/redis-5.0.7/bin/
./redis-server ../etc/8000/redis.conf
./redis-server ../etc/8001/redis.conf
./redis-server ../etc/8002/redis.conf
./redis-server ../etc/8003/redis.conf
./redis-server ../etc/8004/redis.conf
./redis-server ../etc/8005/redis.conf
[~]#chmod +x startall.sh//给这个执行的权限
[~]#bash startall.sh
[~]#ps -aux | grep redis //查看启动状态
//编写一个停止sh
[~]#touch shutdown-all.sh
[~]#vim shutdown-all.sh
bin/redis-cli -p 8000 shutdown
bin/redis-cli -p 8001 shutdown
bin/redis-cli -p 8002 shutdown
bin/redis-cli -p 8003 shutdown
bin/redis-cli -p 8004 shutdown
bin/redis-cli -p 8005 shutdown

6.创建集群

[~]#./redis-cli --cluster create 127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 127.0.0.1:8004 127.0.0.1:8005 --cluster-replicas 1

7.测试

[~]#redis-cli -c -p 8000
[~]#cluster info

以上是关于redis5.0.7安装及配置集群的主要内容,如果未能解决你的问题,请参考以下文章

Centos7安装redis5.0.7

redis5.0.7安装

centOS7安装redis5.0.7

Redis5.0.7群集搭建(最新版实战!!!)

《Redis5.x入门教程》之准备工作数据类型

docker 配置redis主从复制