redis5.0.7安装及配置集群

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

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

3.解压

tar -zxvf redis-5.0.7.tar.gz

4.配置文件

 //创建etc文件夹,bin文件夹
[~]#cp redis.conf redis_copy.conf
[~]#mv redis.conf ./etc/
[~]#cd src
[~]mv mkreleasehdr.sh redis-check-aof redis-check-rdb redis-cli redis-server redis-trib.rb redis-benchmark ../bin/
//创建8000-8005文件夹,在etc
[~]#cd ../etc
[~]#mkdir 8000
[~]#mkdir 8001
[~]#mkdir 8002
[~]#mkdir 8003
[~]#mkdir 8004
[~]#mkdir 8005
[~]cp ../redis.conf ./8000/

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

 port 8000 //端口
bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群 ,或者注释掉
daemonize yes //redis后台运行
pidfile /var/run/redis_8000.pid //pidfile文件对应8000,
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_8000.conf //集群的配置 配置文件首次启动自动生成 80002 把注释#去掉
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置 把注释#去掉
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
上一篇:nginx负载均衡fair模块安装和配置


下一篇:Solr集群搭建详细教程(二)