redis三主三从搭建

Redis 三主三从集群搭建

方式一:源码安装

下载源码包:

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

解压并进入目录:

tar xf redis-3.2.10 && cd redis-3.2.10

make

redis命令做软连接

ln -s /root/redis-3.2.10/src/* /usr/bin/

方式二:yum安装

yum install –y redis

复制redis多节点的启动脚本至/etc/init.d下

添加执行权限

chmod +x /etc/init.d/redis_8001

 

CentOS 7.2 安装ruby较高版本

环境需求:在centos中通过yum安装的ruby版本为2.0.0 但是有些应用需要较高的ruby环境,比如我这里就是使用redis官方的工具,redis-trib.rb工具构建redis集群

RVM安装方式:

[root@Daya-02 ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

执行官方命令:

[root@Daya-02 ~]# \curl -sSL https://get.rvm.io | bash -s stable

如果看到如下提示证明执行成功:

按照提示执行source命令:

[root@Daya-02 ~]# source /etc/profile.d/rvm.sh

list查看可供安装的版本:

[root@Daya-02 ~]# rvm list known

我这里安装的2.4的版本

[root@Daya-02 ~]# rvm install 2.4.1

[root@Daya-02 ~]# ruby -v

ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

使用gem命令安装redis:

[root@Daya-02 ~]# gem install redis

Fetching: redis-4.0.3.gem (100%)

Successfully installed redis-4.0.3

Parsing documentation for redis-4.0.3

Installing ri documentation for redis-4.0.3

Done installing documentation for redis after 0 seconds

1 gem installed

复制redis-trib.rb命令脚本(redis源码包的src目录下):

[root@Daya-02 src]# cp redis-trib.rb /usr/bin/

创建三主三从集群:

[root@Daya-02 ~]# redis-trib.rb create --replicas 1 10.211.55.8:8002 10.211.55.8:8003 10.211.55.8:8004 10.211.55.8:8005 10.211.55.8:8006 10.211.55.8:8007

>>> Creating cluster

Connecting to node 10.211.55.8:8002: OK

Connecting to node 10.211.55.8:8003: OK

Connecting to node 10.211.55.8:8004: OK

Connecting to node 10.211.55.8:8005: OK

Connecting to node 10.211.55.8:8006: OK

Connecting to node 10.211.55.8:8007: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

10.211.55.8:8002

10.211.55.8:8003

10.211.55.8:8004

Adding replica 10.211.55.8:8005 to 10.211.55.8:8002

Adding replica 10.211.55.8:8006 to 10.211.55.8:8003

Adding replica 10.211.55.8:8007 to 10.211.55.8:8004

M: 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0 10.211.55.8:8002

  slots:0-5460 (5461 slots) master

M: 179523cb9cedd09e76757cd0ad104ed81fd3111d 10.211.55.8:8003

  slots:5461-10922 (5462 slots) master

M: d15b186356f131aaf72137a0efc84c58fcea3349 10.211.55.8:8004

  slots:10923-16383 (5461 slots) master

S: 74fd46c3e2deb003a23a6f65bbdf37c2962a4b58 10.211.55.8:8005

  replicates 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0

S: a79439d9b33f710d0ab7dee708e0da908bc15b6d 10.211.55.8:8006

  replicates 179523cb9cedd09e76757cd0ad104ed81fd3111d

S: 3f5c804d7eaea288c540296c5ada818f4d7b85a5 10.211.55.8:8007

  replicates d15b186356f131aaf72137a0efc84c58fcea3349

Can I set the above configuration? (type 'yes' to accept): yes需要输入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 10.211.55.8:8002)

M: 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0 10.211.55.8:8002

  slots:0-5460 (5461 slots) master

M: 179523cb9cedd09e76757cd0ad104ed81fd3111d 10.211.55.8:8003

  slots:5461-10922 (5462 slots) master

M: d15b186356f131aaf72137a0efc84c58fcea3349 10.211.55.8:8004

  slots:10923-16383 (5461 slots) master

M: 74fd46c3e2deb003a23a6f65bbdf37c2962a4b58 10.211.55.8:8005

  slots: (0 slots) master

  replicates 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0

M: a79439d9b33f710d0ab7dee708e0da908bc15b6d 10.211.55.8:8006

  slots: (0 slots) master

  replicates 179523cb9cedd09e76757cd0ad104ed81fd3111d

M: 3f5c804d7eaea288c540296c5ada818f4d7b85a5 10.211.55.8:8007

  slots: (0 slots) master

  replicates d15b186356f131aaf72137a0efc84c58fcea3349

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

搭建完成

查看集群状态指定其中一个节点即可:

[root@Daya-02 src]# redis-trib.rb check 10.211.55.8:8003


猜你喜欢

转载自blog.51cto.com/13520772/2316992