Redis-Cluster实战--4.官方安装(含视频)
程序员文章站
2022-06-12 14:51:24
...
转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426
一、准备redis(下载、编译、安装、配置目录、数据目录)
1. 下载、编译、安装
cd /opt/soft wget http://download.redis.io/releases/redis-3.0.3.tar.gz tar xzf redis-3.0.3.tar.gz cd redis-3.0.3 make make install
2. 配置目录、数据目录
cd /opt/soft/redis-3.0.3 mkdir -p data mkdir -p conf
3.建立软链接:
ln -s /opt/soft/redis-3.0.3 /opt/soft/redis
二、配置、启动Redis节点(本例子以3主、3从组成Redis-Cluster)
(1) 配置redis节点,在conf目录下添加6个(7000-7005)redis-${port}.conf作为6个节点的配置文件
其中7000-7005是六个端口号
port 7000 cluster-enabled yes cluster-config-file nodes-7000.conf cluster-node-timeout 5000 dir "/opt/soft/redis/data/" appendonly yes appendfilename "appendonly-7000.aof" daemonize yes
生成另外5个文件
sed 's/7000/7001/g' redis-7000.conf > redis-7001.conf sed 's/7000/7002/g' redis-7000.conf > redis-7002.conf sed 's/7000/7003/g' redis-7000.conf > redis-7003.conf sed 's/7000/7004/g' redis-7000.conf > redis-7004.conf sed 's/7000/7005/g' redis-7000.conf > redis-7005.conf
(2) 启动6个节点。
redis-server /opt/soft/redis/conf/redis-7000.conf redis-server /opt/soft/redis/conf/redis-7001.conf redis-server /opt/soft/redis/conf/redis-7002.conf redis-server /opt/soft/redis/conf/redis-7003.conf redis-server /opt/soft/redis/conf/redis-7004.conf redis-server /opt/soft/redis/conf/redis-7005.conf
查看节点是否都已经启动:
[@zw_53_162 conf]# [@zw_53_162 conf]# ps -ef | grep redis root 26007 1 0 21:56 ? 00:00:00 redis-server *:7000 [cluster] root 26011 1 0 21:56 ? 00:00:00 redis-server *:7001 [cluster] root 26019 1 0 21:56 ? 00:00:00 redis-server *:7002 [cluster] root 26023 1 0 21:56 ? 00:00:00 redis-server *:7003 [cluster] root 26033 1 0 21:56 ? 00:00:00 redis-server *:7004 [cluster] root 26047 1 0 21:56 ? 00:00:00 redis-server *:7005 [cluster]
查看单个节点:(此时六个节点是分散的,没有形成集群,所有cluster_state=fail)
[@zw_53_162 conf]# redis-cli -c -p 7000 127.0.0.1:7000> cluster info cluster_state:fail cluster_slots_assigned:0 cluster_slots_ok:0 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:1 cluster_size:0 cluster_current_epoch:0 cluster_my_epoch:0 cluster_stats_messages_sent:0 cluster_stats_messages_received:0
三、使用Redis-Cluster的Ruby工具完成集群的搭建:
/opt/soft/redis/src/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
安装信息:
>>> Creating cluster # ping所有节点,如果有一个不OK,安装就结束了。 Connecting to node 127.0.0.1:7000: OK Connecting to node 127.0.0.1:7001: OK Connecting to node 127.0.0.1:7002: OK Connecting to node 127.0.0.1:7003: OK Connecting to node 127.0.0.1:7004: OK Connecting to node 127.0.0.1:7005: OK # 主从节点确认 >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 Adding replica 127.0.0.1:7003 to 127.0.0.1:7000 Adding replica 127.0.0.1:7004 to 127.0.0.1:7001 Adding replica 127.0.0.1:7005 to 127.0.0.1:7002 M: 11e6c12da2521b1877c93cf64437af23b21889b3 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: cee69d4f42bce422e864e0324679f1fbf7506dba 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 32ff9de3a4bcdc9423fdf269b0d1588d50fd18e3 127.0.0.1:7002 slots:10923-16383 (5461 slots) master S: 0e5d897a3be6033ef6733fc37a974124e9e89cc8 127.0.0.1:7003 replicates 11e6c12da2521b1877c93cf64437af23b21889b3 S: b294779edee369c669c44848d71d599c42a0bfe8 127.0.0.1:7004 replicates cee69d4f42bce422e864e0324679f1fbf7506dba S: f57f64229b6a7501d42bd70192eec4acd56422d6 127.0.0.1:7005 replicates 32ff9de3a4bcdc9423fdf269b0d1588d50fd18e3 Can I set the above configuration? (type 'yes' to accept): yes(人工确认安装是否成功) #meet >>> 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 127.0.0.1:7000) #分配slots M: 11e6c12da2521b1877c93cf64437af23b21889b3 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: cee69d4f42bce422e864e0324679f1fbf7506dba 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 32ff9de3a4bcdc9423fdf269b0d1588d50fd18e3 127.0.0.1:7002 slots:10923-16383 (5461 slots) master M: 0e5d897a3be6033ef6733fc37a974124e9e89cc8 127.0.0.1:7003 slots: (0 slots) master replicates 11e6c12da2521b1877c93cf64437af23b21889b3 M: b294779edee369c669c44848d71d599c42a0bfe8 127.0.0.1:7004 slots: (0 slots) master replicates cee69d4f42bce422e864e0324679f1fbf7506dba M: f57f64229b6a7501d42bd70192eec4acd56422d6 127.0.0.1:7005 slots: (0 slots) master replicates 32ff9de3a4bcdc9423fdf269b0d1588d50fd18e3 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
确认集群是否安装成功:
[@zw_53_162 redis]# redis-cli -c -p 7000 127.0.0.1:7000> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_sent:985 cluster_stats_messages_received:985
查看slots使用情况:
127.0.0.1:7000> cluster slots 1) 1) (integer) 5461 2) (integer) 10922 3) 1) "127.0.0.1" 2) (integer) 7001 4) 1) "127.0.0.1" 2) (integer) 7004 2) 1) (integer) 10923 2) (integer) 16383 3) 1) "127.0.0.1" 2) (integer) 7002 4) 1) "127.0.0.1" 2) (integer) 7005 3) 1) (integer) 0 2) (integer) 5460 3) 1) "127.0.0.1" 2) (integer) 7000 4) 1) "127.0.0.1" 2) (integer) 7003
四、完整安装视频:
见附件。
上一篇: maven使用与理解目录
下一篇: ucenter通信原理分析_PHP