第一章redis集群安装
第一步:创建一个文件夹redis-cluster,然后在其下面分别创建6个文件夹如下:
(1) mkdir -p /usr/local/redis-cluster
(2) mkdir 7001 7002 7003 7004 7005 7006
第二步:把之前的redis.conf配置文件分别copy到700*下,进行修改各个文件的内容,也就是对700*下的每个redis.conf配置文件进行修改
(1)bind 192.168.1.115 /daemonize yes /port 700*(分别对每个机器的端口号进行设 置)
(2)redis实例的pid文件: pidfile "/var/run/redis_700*.pid"
(3) 日志的配置文件: logfile "/usr/local/redis-cluster/700*/redis.log"
(4) dir /usr/local/redis-cluster/700*/ (指定数据文件存储位置,必须要指定不同的目录位置,不然会丢失数据)
(5)cluster-enabled yes(启动集群模式,开始玩耍)
(6)cluster-config-file nodes700*.conf(这里700*最好和port对应上)
(7)cluster-node-timeout 5000 (redis超时时间,可改可不改)
(8)appendonly yes / 并修改aof模式为: appendfsync always (开启redis数据实时持久化策略)
第三步:
把修改好的配置文件,分别copy到各个文件夹下面,注意每个文件要修改端口号,并且nodes文件也要不相同!
第四步:由于redis集群需要使用ruby命令,所以我们需要安装ruby
(1)yum install ruby
(2)yum install rubygems
(3)gem install redis (安装redis和ruby的接口)
第五步:分别启动6个redis实例,然后检查是否启动成功
(1)/usr/local/bin/redis-server /usr/local/redis-cluster/
700*
/redis.conf
(2)ps -el | grep redis 查看是否启动成功
第六步:首先到redis3.0的安装目录下,然后执行redis-trib.rb命令。
(1)
cd /usr/local/redis3.0/src
(2)
./redis-trib.rb create --replicas 1 192.168.49.33:7001 192.168.49.33:7002 192.168.49.33:7003 192.168.49.33:7004 192.168.49.33:7005 192.168.49.33:7006
测试
集群信息查看命令
192.168.49.33:7004>
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:1202
cluster_stats_messages_received:1202
192.168.49.33:7004>
cluster nodes
c52932c099bc9d7cdc9979adc1446145992153f0 192.168.49.33:7002 master - 0 1488266045747 2 connected 5461-10922
01f386471c8fbde4a35d8f88486f7b835cf908ba 192.168.49.33:7001 master - 0 1488266048753 1 connected 0-5460
0cfa202ce53f1729d9184baea59e51cce76033dd 192.168.49.33:7005 slave c52932c099bc9d7cdc9979adc1446145992153f0 0 1488266047751 5 connected
165e79a3e4a7f9f8886a179812ae7e5fcf8304ae 192.168.49.33:7004 myself,slave 01f386471c8fbde4a35d8f88486f7b835cf908ba 0 0 4 connected
975a2ccaecf1f0e13621c32d9225df553f94788d 192.168.49.33:7006 slave e1c930b3abf5df888391a86f3bacef2b8d2185e5 0 1488266044746 6 connected
e1c930b3abf5df888391a86f3bacef2b8d2185e5 192.168.49.33:7003 master - 0 1488266046749 3 connected 10923-16383