您的位置:首页 > 数据库 > Redis

centos7 Redis多机多节点集群部署

2017-12-28 11:52 856 查看
redis多机多节点的集群部署可参考redis单机多节点的部署部分http://blog.csdn.net/duguxingfeng/article/details/78918333

这里分别用VMware的两台虚拟机做部署 分别是centos7_1  192.168.0.164与centos_2 192.168.0.170

1.分别在164与170机器上安装redis

164机器为之前单机多节点部署的机器。

在170上安装redis 参考:http://blog.csdn.net/duguxingfeng/article/details/78911640

2.创建节点,修改配置

首先我们在192.168.0.164虚拟机里创建三个节点,端口分别是7001,7002,7003

[root@localhost ~]# mkdir
redis_cluster

[root@localhost ~]#  cd redis_cluster/

[root@localhost redis_cluster]# mkdir 7001 7002 7003
同理我们在192.168.0.170虚拟机里创建三个节点,端口分别是7004,7005,7006

分别修改7001-7006下的配置文件

[root@localhost ~] vi redis_cluster/7001/redis.conf

a. 192.168.0.164的机器 修改一下几个属性

port 7001  //三个节点配置文件分别是7001-7003

bind 192.168.0.164   #默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访,和单机集群有区别

daemonize yes        #redis后台运行

pidfile /var/run/redis_7001.pid   #pidfile文件对应7001-7003

cluster-enabled yes   #开启集群

cluster-config-file nodes_7001.conf  #保存节点配置,自动创建,自动更新对应7001-7003

cluster-node-timeout 5000    #集群超时时间,节点超过这个时间没反应就断定是宕机
b.同理192.168.0.170的机器 修改一下几个属性

bind 192.168.0.170   #默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访,和单机集群有区别

daemonize yes        #redis后台运行

pidfile /var/run/redis_7004.pid   #pidfile文件对应7004-7006

cluster-enabled yes   #开启集群

cluster-config-file nodes_7001.conf  #保存节点配置,自动创建,自动更新对应7004-7006

cluster-node-timeout 5000    #集群超时时间,节点超过这个时间没反应就断定是宕机


3.分别启动164与170机器上的节点
164机器:

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7001/redis.conf

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7002/redis.conf

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7003/redis.conf


170机器:

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7004/redis.conf

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7005/redis.conf

[root@localhost ~]# /usr/local/redis/bin/redis-server redis_cluster/7006/redis.conf


4.分别关闭两台机器的防火墙
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service







systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

5.创建集群 在164机器上(因为之前部署过redis单机多节点,顾可省略安装ruby,以及redis和ruby连接)

yum -y install ruby ruby-devel rubygems rpm-build

gem install redis

在164上创建集群

[root@localhost ~]# redis-trib.rb create --replicas 1  192.168.0.164:7001 192.168.0.164:7002 192.168.0.164:7003 192.168.0.170:7004 192.168.0.170:7005 192.168.0.170:7006





>>> Creating cluster

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

Using 3 masters:

192.168.0.164:7001

192.168.0.170:7004

192.168.0.164:7002

Adding replica 192.168.0.170:7005 to 192.168.0.164:7001

Adding replica 192.168.0.164:7003 to 192.168.0.170:7004

Adding replica 192.168.0.170:7006 to 192.168.0.164:7002

M: 08d5f59fa053d79e3cc71fc5bb8759bec191ff41 192.168.0.164:7001

   slots:0-5460 (5461 slots) master

M: 4bda83bae0aeb9988aeb7d34eff2cc75226a0edd 192.168.0.164:7002

   slots:10923-16383 (5461 slots) master

S: b782f527ead6f63c8278c1b0713b92a9fd4fe995 192.168.0.164:7003

   replicates 86c8cb7975f85a859147fef9672d44b24c5a718b

M: 86c8cb7975f85a859147fef9672d44b24c5a718b 192.168.0.170:7004

   slots:3671,5461-10922,11797,15924 (5465 slots) master

S: 2d44accacb1bb4cd1eef5f98f7af64a43f01544d 192.168.0.170:7005

   replicates 08d5f59fa053d79e3cc71fc5bb8759bec191ff41

S: 2c42433953bcd3ad47015d9f8ac72e7a7cf447c5 192.168.0.170:7006

   replicates 4bda83bae0aeb9988aeb7d34eff2cc75226a0edd

Can I set the above configuration? (type 'yes' to accept):
测试同redis单机多节点的测试:http://blog.csdn.net/duguxingfeng/article/details/78918333
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos redis