redis5.0.4 cluster安装部署

注意:首先redis中不能有数据,本人是新搭建的,先有数据再边集群的请自己动手

            需要打开redis端口和集群的总线端口,即redis端口号+10000,如6379则为16379

1、下载并解压redis(不会请参数上面文章)

2、修改redis.conf,修改内容如下:

#bind 127.0.0.1                                  #bing是指只有指定的网段或地址才能访问该redis 
                                                 #注意一定注释掉,网上都是单台搭建,本人我多台
protected-mode no                                #yes开启远程访问
daemonize yes                                    #yes表示后台运行
logfile "/data/package/redis-5.0.4/logs/redis.log" #日志打印位置
cluster-enabled yes                                #开启集群
cluster-node-timeout 15000                         #集群节点超时时间
cluster-config-file nodes-6379.conf                #节点配置时间 
requirepass admin                                  #redis的密码
masterauth admin                                   #集群密码

3、启动redis:

/data/package/redis-5.0.4/src/redis-server /data/package/redis-5.0.4/redis.conf

4、查看:

[root@liu redis-5.0.4]# ps -ef|grep redis
root      2194     1  0 18:56 ?        00:00:02 /data/package/redis-5.0.4/src/redis-server 127.0.0.1:6379 [cluster]            
root      3276  2871  0 19:11 pts/0    00:00:00 grep redis

5、查看占用端口号

[root@liu src]# netstat -tulnp|grep 6379
tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      3025/redis-server * 
tcp        0      0 0.0.0.0:16379               0.0.0.0:*                   LISTEN      3025/redis-server * 

6、按上面步骤分别在192.168.252.8、192.168.252.9、192.168.252.10、192.168.252.11、192.168.252.12、192.168.252.13上面安装redis

7、启动redis集群

./redis-cli --cluster create 192.168.252.8:6379 192.168.252.9:6379 192.168.252.10:6379 192.168.252.11:6379 192.168.252.12:6379 192.168.252.13:6379 --cluster-replicas 1 -a admin

--replicas 1 1其实代表的是一个比例,就是主节点数/从节点数的比例。

那么想一想,在创建集群的时候,哪些节点是主节点呢?哪些节点是从节点呢?答案是将按照命令中IP:PORT的顺序,先是3个主节点,然后是3个从节点。

[root@liu src]# ./redis-cli --cluster create 192.168.252.8:6379 192.168.252.9:6379 192.168.252.10:6379 192.168.252.11:6379 192.168.252.12:6379 192.168.252.13:6379 --cluster-replicas 1 -a admin
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.252.12:6379 to 192.168.252.8:6379
Adding replica 192.168.252.13:6379 to 192.168.252.9:6379
Adding replica 192.168.252.11:6379 to 192.168.252.10:6379
M: 9b6b0b718640664adf96965c9d0881c4f23ae15a 192.168.252.8:6379
   slots:[0-5460] (5461 slots) master
M: 5da81527694d71f531c0455996d2ce64563df4f6 192.168.252.9:6379
   slots:[5461-10922] (5462 slots) master
M: 05c207e52a0637eb2524d8a3158aa77cbce8f22f 192.168.252.10:6379
   slots:[10923-16383] (5461 slots) master
S: e9491b8a33031ba376d0a691491ce8cad1a3459b 192.168.252.11:6379
   replicates 05c207e52a0637eb2524d8a3158aa77cbce8f22f
S: 93cea7df8a032890c3ffed0ddd4fb5b7e91a3b14 192.168.252.12:6379
   replicates 9b6b0b718640664adf96965c9d0881c4f23ae15a
S: 6fddb04c297f20343c356de80f4e57b430c90735 192.168.252.13:6379
   replicates 5da81527694d71f531c0455996d2ce64563df4f6
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.252.8:6379)
M: 9b6b0b718640664adf96965c9d0881c4f23ae15a 192.168.252.8:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 5da81527694d71f531c0455996d2ce64563df4f6 192.168.252.9:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 6fddb04c297f20343c356de80f4e57b430c90735 192.168.252.13:6379
   slots: (0 slots) slave
   replicates 5da81527694d71f531c0455996d2ce64563df4f6
M: 05c207e52a0637eb2524d8a3158aa77cbce8f22f 192.168.252.10:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: e9491b8a33031ba376d0a691491ce8cad1a3459b 192.168.252.11:6379
   slots: (0 slots) slave
   replicates 05c207e52a0637eb2524d8a3158aa77cbce8f22f
S: 93cea7df8a032890c3ffed0ddd4fb5b7e91a3b14 192.168.252.12:6379
   slots: (0 slots) slave
   replicates 9b6b0b718640664adf96965c9d0881c4f23ae15a
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

启动成功即可使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值