redis集群构建过程 linux windows

时间:2022-02-24 17:50:36

标签:

redis集群的构建过程 本人初次构建redis集群时,通过查阅资料整理的文档

目录

Linux Redis cluster集群方案... 1

Windows redis集群方案... 5

Linux Redis cluster集群方案

1 安装:

下载地址:

下载版本:redis3.0.7.tar.gz

[[email protected] soft]$ tar -zxzf redis-3.0.7.tar.gz

[[email protected] soft]$ cd redis-3.0.7

[[email protected] redis-3.0.7]$ make

编译后src目录下生成6个可执行文件

redis-server(启动服务端)、

redis-cli(调用客户端)、

redis-benchmark、

redis-check-aof、

redis-check-dump、

redis-sentinel

2 测试redis

[[email protected] redis-3.0.7]$ src/redis-server (启动服务)

[[email protected] redis-3.0.7]$ src/redis-cli (启动客户端)

127.0.0.1:6379> set name lixiaodong

OK

127.0.0.1:6379> get name

"lixiaodong"

127.0.0.1:6379>

3 开机自启动可以继续参考博客

4集群配置 redis3.0以后才支持cluster集群所以要下载正确的redis

创建文件夹redis_cluster,创建三个子文件夹node1,node2,node3作为集群的三个节点

拷贝redis的配置文件redis.conf分别到node1,node2,node3

[[email protected] redis_cluster]$ cp ../soft/redis-3.0.7/redis.conf node1/

[[email protected] redis_cluster]$ cp ../soft/redis-3.0.7/redis.conf node2/

[[email protected] redis_cluster]$ cp ../soft/redis-3.0.7/redis.conf node3/

修改配置文件redis.conf 以node1为例子

修改端口号:6380

绑定ip: 指的是本机网ip。 bind 172.20.16.158

修改pid文件位置:新安装的程序在运行后会在/var/run目录下面产生自己的pid文件,目的是为了防止进程启动多个副本等pidfile /var/run/redis_6380.pid

开启集群: cluster-enabled yes

指定集群配置文件:cluster-config-file nodes-6380.conf 通过注释了解到这个文件不用手动修改,redis会自己生成

指定生成文件的目录:dir /home/lixiaodong/redis_cluster/node1 这样redis生成的文件就会到指定目录,不然的话在哪个目录启动redis这些文件就会生成在相应的目录

5 创建集群

需要提前安装:

yum install ruby //安装ruby

    yum install rubygems //安装rubygems

   gem install redis //

如果安装不成功,

下载安装

wget https://rubygems.global.ssl.fastly.net/gems/redis-3.0.7.gem

  安装命令:gem install -l ./redis-3.0.7.gem

通过命令创建集群,linux下运行如下

[[email protected] lixiaodong]$ soft/redis-3.0.7/src/redis-trib.rb create --replicas 0 172.20.16.158:6380 172.20.16.158:6381 172.20.16.158:6382 >>> Creating cluster >>> Performing hash slots allocation on 3 nodes... Using 3 masters: 172.20.16.158:6380 172.20.16.158:6381 172.20.16.158:6382 M: d276f248a4e0fba1f9e24f19ac97b330b45b2ab3 172.20.16.158:6380 slots:0-5460 (5461 slots) master M: 51eb3b27006cac78672344646a50e4ae6f02215f 172.20.16.158:6381 slots:5461-10922 (5462 slots) master M: 08612b4236d4f4733157ec45f98bc19ff319118e 172.20.16.158:6382 slots:10923-16383 (5461 slots) master Can I set the above configuration? (type yes to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join. >>> Performing Cluster Check (using node 172.20.16.158:6380) M: d276f248a4e0fba1f9e24f19ac97b330b45b2ab3 172.20.16.158:6380 slots:0-5460 (5461 slots) master M: 51eb3b27006cac78672344646a50e4ae6f02215f 172.20.16.158:6381 slots:5461-10922 (5462 slots) master M: 08612b4236d4f4733157ec45f98bc19ff319118e 172.20.16.158:6382 slots:10923-16383 (5461 slots) master [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [[email protected] lixiaodong]$

6测试集群

启动客户端命令如下, –c的作用就是如果key对应的slot不是当前连接的redis-server,那么自动重定向到其对应的redis-server