阿汤博客-承接中小企业服务器维护和网站维护,有意者可以联系博主!

Centos7 Redis集群部署

运维文档 186℃ 0评论

Redis安装参考:Redis主从配置并以普通用户启动

安装好以后以单机多实例的方式部署集群

Redis集群部署


1、创建配置和启动脚本

#cd /etc/redis

修改配置文件,开启集群模式

#vim 6379.conf

bind `192.168.2.90

appendonly yes

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000


#cp 6379.conf 7001.conf

#cp 6379.conf 7002.conf

#cp 6379.conf 7003.conf

#cp 6379.conf 7004.conf

#cp 6379.conf 7005.conf

#cp 6379.conf 7006.conf

#sed -i '[email protected]@[email protected]' 7001.conf

#sed -i '[email protected]@[email protected]' 7002.conf

#sed -i '[email protected]@[email protected]' 7003.conf

#sed -i '[email protected]@[email protected]' 7004.conf

#sed -i '[email protected]@[email protected]' 7005.conf

#sed -i '[email protected]@[email protected]' 7006.conf


#cd  /etc/init.d/

#cp 6379.conf redis_7001.conf

#cp 6379.conf redis_7002.conf

#cp 6379.conf redis_7003.conf

#cp 6379.conf redis_7004.conf

#cp 6379.conf redis_7005.conf

#cp 6379.conf redis_7006.conf

#sed -i '[email protected]@[email protected]' redis_7001.conf

#sed -i '[email protected]@[email protected]' redis_7002.conf

#sed -i '[email protected]@[email protected]' redis_7003.conf

#sed -i '[email protected]@[email protected]' redis_7004.conf

#sed -i '[email protected]@[email protected]' redis_7005.conf

#sed -i '[email protected]@[email protected]' redis_7006.conf


#mkdir /var/lib/redis/700{1..6}

# chown -R redis.redis /var/lib/redis/


2、启动实例

#/etc/init.d/redis_7001 start

#/etc/init.d/redis_7002 start

#/etc/init.d/redis_7003 start

#/etc/init.d/redis_7004 start

#/etc/init.d/redis_7005 start

#/etc/init.d/redis_7006 start

Redis集群部署

3、安装rvm

#gpg –keyserver hkp://keys.gnupg.net –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

# \curl -sSL https://get.rvm.io | bash

#echo "source /etc/profile.d/rvm.sh" >> /root/.bashrc

#source /etc/profile.d/rvm.sh


4、安装ruby

#rvm list known #查看版本

#rvm install ruby-2.5.1

#gem -v  #安装好以后查看版本


5、更改gem源

#gem source -l    #查看镜像源

#gem source –remove https://rubygems.org/  #删除默认源

#gem source -a https://ruby.taobao.org  #新增gem的镜像源(确保只有ruby.taobao.org)

#gem sources -a https://mirrors.aliyun.com/rubygems/ #或者添加这个


6、安装redis-trib.rb

#gem install redis

#redis-trib.rb文件在解压包src目录下面

#redis-4.0.11/src/redis-trib.rb  create –replicas  1 192.168.2.90:7001 192.168.2.90:7002 192.168.2.90:7003 192.168.2.90:7004 192.168.2.90:7005 192.168.2.90:7006

>>> Creating cluster

>>> Performing hash slots allocation on 6 nodes…

Using 3 masters:

192.168.2.90:7001

192.168.2.90:7002

192.168.2.90:7003

Adding replica 192.168.2.90:7005 to 192.168.2.90:7001

Adding replica 192.168.2.90:7006 to 192.168.2.90:7002

Adding replica 192.168.2.90:7004 to 192.168.2.90:7003

>>> Trying to optimize slaves allocation for anti-affinity

[WARNING] Some slaves are in the same host as their master

M: e2a547c387bdb92114d6a3a98f284b39b56b1f76 192.168.2.90:7001

  slots:0-5460 (5461 slots) master

M: bb8cb8ed2944151a5f536c6f073eea4181c5e38d 192.168.2.90:7002

  slots:5461-10922 (5462 slots) master

M: 751a55a954e14c5e1aa5d7ddd7f73d576e89a264 192.168.2.90:7003

  slots:10923-16383 (5461 slots) master

S: 939e97dc78a0724d218b1a1d192c8dce5fd091fa 192.168.2.90:7004

  replicates 751a55a954e14c5e1aa5d7ddd7f73d576e89a264

S: 4de2ae05550a9cbb47974b2c301cb91ade0655a2 192.168.2.90:7005

  replicates e2a547c387bdb92114d6a3a98f284b39b56b1f76

S: 048099bafe31c507d0376684a0b5295e6702cf36 192.168.2.90:7006

  replicates bb8cb8ed2944151a5f536c6f073eea4181c5e38d

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.2.90:7001)

M: e2a547c387bdb92114d6a3a98f284b39b56b1f76 192.168.2.90:7001

  slots:0-5460 (5461 slots) master

  1 additional replica(s)

S: 939e97dc78a0724d218b1a1d192c8dce5fd091fa 192.168.2.90:7004

  slots: (0 slots) slave

  replicates 751a55a954e14c5e1aa5d7ddd7f73d576e89a264

S: 048099bafe31c507d0376684a0b5295e6702cf36 192.168.2.90:7006

  slots: (0 slots) slave

  replicates bb8cb8ed2944151a5f536c6f073eea4181c5e38d

M: bb8cb8ed2944151a5f536c6f073eea4181c5e38d 192.168.2.90:7002

  slots:5461-10922 (5462 slots) master

  1 additional replica(s)

M: 751a55a954e14c5e1aa5d7ddd7f73d576e89a264 192.168.2.90:7003

  slots:10923-16383 (5461 slots) master

  1 additional replica(s)

S: 4de2ae05550a9cbb47974b2c301cb91ade0655a2 192.168.2.90:7005

  slots: (0 slots) slave

  replicates e2a547c387bdb92114d6a3a98f284b39b56b1f76

[OK] All nodes agree about slots configuration.

>>> Check for open slots…

>>> Check slots coverage…

[OK] All 16384 slots covered.

Redis集群部署


7、集群测试

Redis集群部署

Redis集群部署

转载请注明:阿汤博客 » Centos7 Redis集群部署

喜欢 (0)or分享 (0)