成都网站建设设计

将想法与焦点和您一起共享

Redis集群部署方法

本篇内容介绍了“redis集群部署方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

10年积累的网站制作、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有红河哈尼免费网站建设让你可以放心的选择与我们合作。

1、主从节点均安装好redis以及ruby。
[root@D2-LZY245 redis-4.0.1]# yum -y install ruby ruby-devel rubygems rpm-build
[root@D2-LZY245 redis-4.0.1]# gem install redis

2、主节点创建集群目录、配置参数并启动
[root@D2-LZY245 ~]# cd redis-4.0.1/
[root@D2-LZY245 redis-4.0.1]# mkdir redis_cluster
[root@D2-LZY245 redis-4.0.1]# cd redis_cluster/
[root@D2-LZY245 redis_cluster]# mkdir 7000 7001 7002
[root@D2-LZY245 redis_cluster]# cp ../redis.conf 7000/
[root@D2-LZY245 redis_cluster]# vim 7000/redis.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7000/redis_7000.conf
bind 10.163.89.245
port 7000
daemonize yes
pidfile /var/run/redis_7000.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
[root@D2-LZY245 redis_cluster]# mv 7000/redis.conf  7000/redis_7000.conf
[root@D2-LZY245 redis_cluster]# cp 7000/redis_7000.conf 7001/redis_7001.conf
[root@D2-LZY245 redis_cluster]# cp 7000/redis_7000.conf 7002/redis_7002.conf
[root@D2-LZY245 redis_cluster]# vim 7001/redis_7001.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7001/redis_7001.conf
bind 10.163.89.245
port 7001
daemonize yes
pidfile /var/run/redis_7001.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
[root@D2-LZY245 redis_cluster]# vim 7002/redis_7002.conf
[root@D2-LZY245 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7002/redis_7002.conf
bind 10.163.89.245
port 7002
daemonize yes
pidfile /var/run/redis_7002.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7002.conf
cluster-node-timeout 15000

[root@D2-LZY245 redis_cluster]# cd ..
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7000/redis_7000.conf
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7001/redis_7001.conf
[root@D2-LZY245 redis-4.0.1]# src/redis-server redis_cluster/7002/redis_7002.conf
[root@D2-LZY245 redis-4.0.1]# netstat -tunlp | grep 700
tcp        0      0 10.163.89.245:17000     0.0.0.0:*               LISTEN      28447/src/redis-ser
tcp        0      0 10.163.89.245:17001     0.0.0.0:*               LISTEN      28423/src/redis-ser
tcp        0      0 10.163.89.245:17002     0.0.0.0:*               LISTEN      28432/src/redis-ser
tcp        0      0 10.163.89.245:7000      0.0.0.0:*               LISTEN      28447/src/redis-ser
tcp        0      0 10.163.89.245:7001      0.0.0.0:*               LISTEN      28423/src/redis-ser
tcp        0      0 10.163.89.245:7002      0.0.0.0:*               LISTEN      28432/src/redis-ser

3、从节点创建集群目录、配置参数并启动
[root@D2-TRAIN15 ~]# cd redis-4.0.1
[root@D2-TRAIN15 redis-4.0.1]# mkdir redis_cluster
[root@D2-TRAIN15 redis-4.0.1]# cd redis_cluster/
[root@D2-TRAIN15 redis_cluster]# mkdir 7003 7004 7005
[root@D2-TRAIN15 redis_cluster]# cp ../redis.conf 7003/
[root@D2-TRAIN15 redis_cluster]# vim 7003/redis.conf
[root@D2-TRAIN15 redis_cluster]#  egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7003/redis.conf
bind 10.163.89.15
port 7003
daemonize yes
pidfile /var/run/redis_7003.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7003.conf
cluster-node-timeout 15000
[root@D2-TRAIN15 redis_cluster]# mv 7003/redis.conf 7003/redis_7003.conf
[root@D2-TRAIN15 redis_cluster]# cp 7003/redis_7003.conf 7004/redis_7004.conf
[root@D2-TRAIN15 redis_cluster]# cp 7003/redis_7003.conf 7005/redis_7005.conf
[root@D2-TRAIN15 redis_cluster]# vim 7004/redis_7004.conf
[root@D2-TRAIN15 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7004/redis_7004.conf
bind 10.163.89.15
port 7004
daemonize yes
pidfile /var/run/redis_7004.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7004.conf
cluster-node-timeout 15000
[root@D2-TRAIN15 redis_cluster]# vim 7005/redis_7005.conf
[root@D2-TRAIN15 redis_cluster]# egrep '^port|^bind|^daemonize|^pidfile|^cluster-enabled|^cluster-config-file|^cluster-node-timeout|^appendonly' 7005/redis_7005.conf
bind 10.163.89.15
port 7005
daemonize yes
pidfile /var/run/redis_7005.pid
appendonly yes
cluster-enabled yes
cluster-config-file nodes-7005.conf
cluster-node-timeout 15000

[root@D2-TRAIN15 redis_cluster]# cd ..
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7003/redis_7003.conf
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7004/redis_7004.conf
[root@D2-TRAIN15 redis-4.0.1]# src/redis-server redis_cluster/7005/redis_7005.conf
[root@D2-TRAIN15 redis-4.0.1]# netstat -tunlp | grep 700
tcp        0      0 10.163.89.15:17003          0.0.0.0:*                   LISTEN      14258/src/redis-ser
tcp        0      0 10.163.89.15:17004          0.0.0.0:*                   LISTEN      14263/src/redis-ser
tcp        0      0 10.163.89.15:17005          0.0.0.0:*                   LISTEN      14268/src/redis-ser
tcp        0      0 10.163.89.15:7003           0.0.0.0:*                   LISTEN      14258/src/redis-ser
tcp        0      0 10.163.89.15:7004           0.0.0.0:*                   LISTEN      14263/src/redis-ser
tcp        0      0 10.163.89.15:7005           0.0.0.0:*                   LISTEN      14268/src/redis-ser
[root@D2-TRAIN15 redis-4.0.1]#

4、创建集群
[root@D2-LZY245 redis-4.0.1]# src/redis-trib.rb create --replicas 1 10.163.89.245:7000 10.163.89.245:7001 10.163.89.245:7002 10.163.89.15:7003 10.163.89.15:7004 10.163.89.15:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.163.89.245:7000
10.163.89.15:7003
10.163.89.245:7001
Adding replica 10.163.89.15:7004 to 10.163.89.245:7000
Adding replica 10.163.89.245:7002 to 10.163.89.15:7003
Adding replica 10.163.89.15:7005 to 10.163.89.245:7001
M: b545390b3e8c3602e13978cf28f6ef7dd76b6197 10.163.89.245:7000
   slots:0-5460 (5461 slots) master
M: 0e26e28f3c531357db73e522bb6279350ff5275e 10.163.89.245:7001
   slots:10923-16383 (5461 slots) master
S: 8164d21461a9a5612e9657863c1c214f8c116a8e 10.163.89.245:7002
   replicates e81c2072be94bdf7729b10088a312ff519cb0f2b
M: e81c2072be94bdf7729b10088a312ff519cb0f2b 10.163.89.15:7003
   slots:5461-10922 (5462 slots) master
S: 4284f88f612157caa6611173d347ec4ec9f9554b 10.163.89.15:7004
   replicates b545390b3e8c3602e13978cf28f6ef7dd76b6197
S: d141fe7c975728b1243d6d314914179a7febb306 10.163.89.15:7005
   replicates 0e26e28f3c531357db73e522bb6279350ff5275e
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 10.163.89.245:7000)
M: b545390b3e8c3602e13978cf28f6ef7dd76b6197 10.163.89.245:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 8164d21461a9a5612e9657863c1c214f8c116a8e 10.163.89.245:7002
   slots: (0 slots) slave
   replicates e81c2072be94bdf7729b10088a312ff519cb0f2b
S: d141fe7c975728b1243d6d314914179a7febb306 10.163.89.15:7005
   slots: (0 slots) slave
   replicates 0e26e28f3c531357db73e522bb6279350ff5275e
S: 4284f88f612157caa6611173d347ec4ec9f9554b 10.163.89.15:7004
   slots: (0 slots) slave
   replicates b545390b3e8c3602e13978cf28f6ef7dd76b6197
M: e81c2072be94bdf7729b10088a312ff519cb0f2b 10.163.89.15:7003
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 0e26e28f3c531357db73e522bb6279350ff5275e 10.163.89.245:7001
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

5、测试
在主节点7000端口设置key:
[root@D2-LZY245 ~]# cd redis-4.0.1/
[root@D2-LZY245 redis-4.0.1]# src/redis-cli -h 10.163.89.245 -c -p 7000
10.163.89.245:7000> set key1 "hello world"
-> Redirected to slot [9189] located at 10.163.89.15:7003
OK
10.163.89.15:7003> keys *
1) "key1"

在从节点7005端口查看:
[root@D2-TRAIN15 redis-4.0.1]# src/redis-cli -h 10.163.89.15 -c -p 7005
10.163.89.15:7005> get key1
-> Redirected to slot [9189] located at 10.163.89.15:7003
"hello world"

“Redis集群部署方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


文章标题:Redis集群部署方法
分享URL:http://chengdu.cdxwcx.cn/article/iggoip.html