redis服务器的集群主从配置,从redis的安装到实例开启,到集群创建。集群配置如图:
So in practical terms, what you get with Redis Cluster?
The ability to automatically split your dataset among multiple nodes.
The ability to continue operations when a subset of the nodes are experiencing failures or are unable to communicate with the rest of the cluster.
1.安装redis,下载Redis并编译
在三台服务器上分别安装redis,进行如下操作:
ubuntu需要安装
sudo apt install tcl8.6
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar xzf redis-4.0.1.tar.gz
$ cd redis-4.0.1
$ make
$ mv /opt/
$ make test
2.集群文件配置
resdis集群整体架构
三台服务器,配置如上图,在每台服务器上配置如下(以服务器3为列)
$ /opt/redis-4.0.1# mkdir redis-cluster
$ /opt/redis-4.0.1# mkdir redis-cluster/nodes-7004
$ /opt/redis-4.0.1# mkdir redis-cluster/nodes-7005
$ /opt/redis-4.0.1# cp redis.conf redis-cluster/nodes-7004
$ /opt/redis-4.0.1# cp redis.conf redis-cluster/nodes-7005
依次配置redis.conf(以nodes-7005为列)
$ /opt/redis-4.0.1# vim redis-cluster/nodes-7005/redis.conf
port 7005 #在不同的服务器和nodes-xx中,端口也不同
cluster-enabled yes
bind 10.80.67.238
# daemonize yes #redis后台运行
cluster-config-file nodes-7005.conf
cluster-node-timeout 5000
appendonly yes
3.依次启动redis实例
src/redis-server redis-cluster/nodes-7000/redis.conf
后台启动
nohup src/redis-server redis-cluster/nodes-7000/redis.conf > redis-cluster/nodes-7000/redis-server.out 2>&1 &
nohup(no hang up) 不挂起,后台运行程序。并将输出信息重定向到
redis-cluster/nodes-7000/redis-server.out
如何关闭?
查看pidps aux | grep redis
关闭进程kill -9 pid
每个redis实例都有独立唯一都id,启动和关闭不会改变id。如上依次开启6个redis实例。
4.创建集群
只需在redis-cluster1服务器上操作
仅需要在redis-cluster1服务器上安装gem redis (为来redis-trib可以执行),其他服务器不用。
gem install redis #默认安装的版本上3.3(无所谓)
开启集群
src/redis-trib.rb create --replicas 1 10.80.67.225:7000 10.80.67.225:7001 10.80.67.230:7002 10.80.67.230:7003 10.80.67.238:7004 10.80.67.238:7005
在Can I set the above configuration? (type 'yes' to accept):
输入yes
集群创建完成,运行正常。
[OK] All 16384 slots covered.
意味着集群中的16384个槽至少有一个主节点在处理。