Redis Cluster 安装配置

作者: 董可伦 | 来源:发表于2018-06-02 18:01 被阅读13次

转载请务必注明原创地址为:http://dongkelun.com/2018/01/09/redisClusterDeployment/

服务器

CentOS
Centos 服务器初始环境配置最好先配置好,服务器时间最好配置为一致
我用的是6个服务器,一个服务器一个端口,便于配置文件的修改

首先下载redis3 到本地(需要3以后的版本,我下载的最新的版本:3.0.4)

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

分别上传到每个服务器

scp -r redis-3.0.4.tar.gz redis@redis1:~/

分别在每个服务器上安装 gcc tcl ruby rubygems gem_redis

sudo yum -y install gcc
sudo yum -y install tcl
sudo yum -y install ruby rubygems
sudo gem install redis --version 3.0.4

(gem_redis如果装不上,可多试几次,若是ubuntu,换源,换成taobao,建议服务器用centOS)

解压安装redis

tar -zxvf redis-3.0.4.tar.gz
cd redis-3.0.4/
sudo make test
sudo make install

修改配置文件redis.conf 以端口9000为例

sudo vim redis.conf

port 9000
pidfile /var/run/redis-9000.pid
dbfilename dump-9000.rdb
appendfilename "appendonly-9000.aof"
cluster-config-file nodes-9000.conf
cluster-enabled yes
cluster-node-timeout 5000
appendonly yes

然后分别在每个服务器上启动redis

src/redis-server redis.conf

查看每个端口是否成功开启

ps -aux | grep redis

结果如下:

redis 26674 1 0 Sep15 ? 00:01:21 src/redis-server *:9000 [cluster]

如果后面有[cluster] 证明开启成功

然后建立集群

src/redis-trib.rb create --replicas 1 192.168.32.195:9000 192.168.32.196:9000
192.168.32.197:9000 192.168.32.198:9000 192.168.32.199:9000 192.168.6.214:9000

(master 至少有三个 1 代表 一个master 对应一个slave)

如果下面这样就代表成功(端口 9000 )

>>> Creating cluster
Connecting to node 192.168.32.195:9000: OK
Connecting to node 192.168.32.196:9000: OK
Connecting to node 192.168.32.197:9000: OK
Connecting to node 192.168.32.198:9000: OK
Connecting to node 192.168.32.199:9000: OK
Connecting to node 192.168.6.214:9000: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.32.199:9000
192.168.32.198:9000
192.168.32.197:9000
Adding replica 192.168.32.196:9000 to 192.168.32.199:9000
Adding replica 192.168.32.195:9000 to 192.168.32.198:9000
Adding replica 192.168.6.214:9000 to 192.168.32.197:9000
S: f4c625f49b6c1b073a379c41073b9ff9786f45f6 192.168.32.195:9000
replicates 20ecac926dba10a056f4d36a72bed35bbb7fcd57
S: 77e68bf6eb86d8bf6cb993b32d726e2cd4d05a54 192.168.32.196:9000
replicates 3276d09525fff0195dd366c8d05f80773d7d9af3
M: c6f4504b2ceb8bcffb682483168b8016e6f5973e 192.168.32.197:9000
slots:10923-16383 (5461 slots) master
M: 20ecac926dba10a056f4d36a72bed35bbb7fcd57 192.168.32.198:9000
slots:5461-10922 (5462 slots) master
M: 3276d09525fff0195dd366c8d05f80773d7d9af3 192.168.32.199:9000
slots:0-5460 (5461 slots) master
S: 627c0ae61d75570dc15a03cbdb03b1a8abd56f58 192.168.6.214:9000
replicates c6f4504b2ceb8bcffb682483168b8016e6f5973e
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 192.168.32.195:9000)
M: f4c625f49b6c1b073a379c41073b9ff9786f45f6 192.168.32.195:9000
slots: (0 slots) master
replicates 20ecac926dba10a056f4d36a72bed35bbb7fcd57
M: 77e68bf6eb86d8bf6cb993b32d726e2cd4d05a54 192.168.32.196:9000
slots: (0 slots) master
replicates 3276d09525fff0195dd366c8d05f80773d7d9af3
M: c6f4504b2ceb8bcffb682483168b8016e6f5973e 192.168.32.197:9000
slots:10923-16383 (5461 slots) master
M: 20ecac926dba10a056f4d36a72bed35bbb7fcd57 192.168.32.198:9000
slots:5461-10922 (5462 slots) master
M: 3276d09525fff0195dd366c8d05f80773d7d9af3 192.168.32.199:9000
slots:0-5460 (5461 slots) master
M: 627c0ae61d75570dc15a03cbdb03b1a8abd56f58 192.168.6.214:9000
slots: (0 slots) master
replicates c6f4504b2ceb8bcffb682483168b8016e6f5973e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

以集群的方式登陆(9000为例)

redis-cli -c -p 9000

查看 主从关系

$ 127.0.0.1:9000> cluster nodes
baa1779a73a8d329dfc96104ac3116a24b16a681 192.168.32.199:9000 myself,master - 0 0
5 connected 0-5460
140a8c76dfd44a6e43045d43a4d853fa330dfd42 192.168.32.198:9000 master - 0
1442403482170 12 connected 5461-10922
c99974ae9a92ed18166d580e4d7bb438a26ad3a2 192.168.32.195:9000 slave
140a8c76dfd44a6e43045d43a4d853fa330dfd42 0 1442403481669 12 connected
e07467f74f81f31c024bb5626c37e550396eebe5 192.168.6.214:9000 master - 0
1442403481168 9 connected 10923-16383
04f3bcd569fb325e77a109a530fd376eb84512ce 192.168.32.196:9000 slave
baa1779a73a8d329dfc96104ac3116a24b16a681 0 1442403480667 5 connected
fd383105b93797d7502a7d6bcaa77308cccf2e71 192.168.32.197:9000 slave
e07467f74f81f31c024bb5626c37e550396eebe5 0 1442403482671 9 connected
$127.0.0.1:9000>

相关文章

  • redis

    redisredis理论Redis:安装和配置redis安装配置和使用redisRedis Cluster程序环境...

  • Redis Cluster 部署

    1、安装 redis 2、配置 redis cluster,以 redis-6379 为例,其他的 redis-6...

  • Redis集群Linux安装

    安装步骤: 1、节点准备: ①新建redis-cluster目录,复制6份redis,修改配置文件redis.co...

  • Redis集群搭建

    安装Redis集群准备 采用原生搭建的方式搭建3主3从的Redis Cluster,分别给3个master节点配置...

  • 数据库(24)redis和集群交互

    安装包如下 pip install redis-py-cluster 创建⽂件redis_cluster.py 示...

  • redis集群模式:redis单点、redis主从、redis哨

    目录 redis单点、redis主从、redis哨兵 sentinel,redis集群cluster配置搭建与使用...

  • Redis Cluster 安装配置

    转载请务必注明原创地址为:http://dongkelun.com/2018/01/09/redisCluster...

  • Redis 安装、Cluster集群配置

    安装条件:Cluster模式至少要3主3从。生产环境中,建议六台,主从也进行分离。本例中使用的是单台虚拟机 Red...

  • Redis Cluster安装与配置

    两种安装 原生命令安装--易于理解架构 (生产环境中,一般不使用原生命令安装) 1.配置开启节点 port ${p...

  • redis-cluster集群的搭建

    1.搭建三主三从的cluster的集群的搭建 2.配置环境 redis版本要求:redis大版本为5.0.8 安装...

网友评论

    本文标题:Redis Cluster 安装配置

    本文链接:https://www.haomeiwen.com/subject/hvwrsftx.html