redis 3.2.9集群安装

1.安装redis

       另一篇博客里。

2.配置redis.conf

三台服务器

192.168.0.110 7000 7001 7002

192.168.0.111 7000 7001 7002

192.168.0.112 7000 7001 7002

port 7000   bind 192.168.0.110
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
上面的三台机器每个配置三个redis.conf,port每个配置文件都要改,bind 一台机器的三个文件改成一样。然后启动redis-server如下

[root@master 7000]# ps -ef|grep redis
root       2891      1  0 21:54 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.110:7001 [cluster]
root       2895      1  0 21:54 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.110:7002 [cluster]
root       2903      1  0 21:55 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.110:7000 [cluster]
root       2907   2261  0 21:55 pts/0    00:00:00 grep --color=auto redis
[root@slave1 7000]# ps -ef|grep redis
root       7243      1  0 21:58 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.111:7001 [cluster]
root       7247      1  0 21:58 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.111:7002 [cluster]
root       7253      1  0 21:59 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.111:7000 [cluster]
root       7257   2620  0 21:59 pts/0    00:00:00 grep --color=auto redis
[root@slave2 7002]# ps -ef|grep redis
root      13352      1  0 05:53 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.112:7000 [cluster]
root      13356      1  0 05:53 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.112:7001 [cluster]
root      13360      1  0 05:53 ?        00:00:00 /usr/local/redis/src/redis-server 192.168.0.112:7002 [cluster]
root      13364   2624  0 05:53 pts/0    00:00:00 grep --color=auto redis

3.创建集群

yum -y install ruby ruby-devel rubygems rpm-build
gem install redis --version 3.2.2


[root@master 7002]# /usr/local/redis/src/redis-trib.rb create --replicas 2 192.168.0.110:7000 192.168.0.110:7001 192.168.0.110:7002 192.168.0.111:7000 192.168.0.111:7001 192.168.0.111:7002 192.168.0.112:7000 192.168.0.112:7001 192.168.0.112:7002
>>> Creating cluster
>>> Performing hash slots allocation on 9 nodes...
Using 3 masters:
192.168.0.110:7000
192.168.0.111:7000
192.168.0.112:7000
Adding replica 192.168.0.111:7001 to 192.168.0.110:7000
Adding replica 192.168.0.112:7001 to 192.168.0.110:7000
Adding replica 192.168.0.110:7001 to 192.168.0.111:7000
Adding replica 192.168.0.110:7002 to 192.168.0.111:7000
Adding replica 192.168.0.111:7002 to 192.168.0.112:7000
Adding replica 192.168.0.112:7002 to 192.168.0.112:7000
M: 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5 192.168.0.110:7000
   slots:0-5460 (5461 slots) master
S: e0b04812d4eb1d4a0b833d2c8dec2b9e1c3dc119 192.168.0.110:7001
   replicates 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907
S: 462576a6f3a068dcca8505a9ccf779afdb509eeb 192.168.0.110:7002
   replicates 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907
M: 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907 192.168.0.111:7000
   slots:5461-10922 (5462 slots) master
S: df6b84a5b77791199d2ac3611865721c6b90ecec 192.168.0.111:7001
   replicates 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5
S: 2e10b22e4d5c74ce95d9ddd83508e0535ffd4858 192.168.0.111:7002
   replicates dd47c5185f9dd43cdae1a3269c4fbe01da670bd3
M: dd47c5185f9dd43cdae1a3269c4fbe01da670bd3 192.168.0.112:7000
   slots:10923-16383 (5461 slots) master
S: d99a5c5f07c85c7819d0dcbec74fb38edd1c2c06 192.168.0.112:7001
   replicates 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5
S: 675688c3545db1cf9db2c58788a53f2693c1109e 192.168.0.112:7002
   replicates dd47c5185f9dd43cdae1a3269c4fbe01da670bd3
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.0.110:7000)
M: 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5 192.168.0.110:7000
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
M: dd47c5185f9dd43cdae1a3269c4fbe01da670bd3 192.168.0.112:7000
   slots:10923-16383 (5461 slots) master
   2 additional replica(s)
S: 462576a6f3a068dcca8505a9ccf779afdb509eeb 192.168.0.110:7002
   slots: (0 slots) slave
   replicates 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907
M: 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907 192.168.0.111:7000
   slots:5461-10922 (5462 slots) master
   2 additional replica(s)
S: 2e10b22e4d5c74ce95d9ddd83508e0535ffd4858 192.168.0.111:7002
   slots: (0 slots) slave
   replicates dd47c5185f9dd43cdae1a3269c4fbe01da670bd3
S: 675688c3545db1cf9db2c58788a53f2693c1109e 192.168.0.112:7002
   slots: (0 slots) slave
   replicates dd47c5185f9dd43cdae1a3269c4fbe01da670bd3
S: d99a5c5f07c85c7819d0dcbec74fb38edd1c2c06 192.168.0.112:7001
   slots: (0 slots) slave
   replicates 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5
S: e0b04812d4eb1d4a0b833d2c8dec2b9e1c3dc119 192.168.0.110:7001
   slots: (0 slots) slave
   replicates 60d6a3f30f9dd2ed77a38a6d70ffecf584f1f907
S: df6b84a5b77791199d2ac3611865721c6b90ecec 192.168.0.111:7001
   slots: (0 slots) slave
   replicates 82da5af7bc587960b7cd5ed3a853d1ad79b93dc5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

4.测试

[root@master 7002]# /usr/local/redis/src/redis-cli -c -p 7000 -h 192.168.0.110
192.168.0.110:7000> get name
-> Redirected to slot [5798] located at 192.168.0.111:7000
(nil)
192.168.0.111:7000> set name tom
OK
192.168.0.111:7000> get name
"tom"
192.168.0.111:7000> del name
(integer) 1







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值