简单的redis集群

条件:3台主机(也可以1台3实例),redis大版本:5(3、4不太一样)

  1. 下载安装(提前装好gcc)
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar redis-5.0.3.tar.gz -C /usr/local/
cd /usr/local/
mv redis-5.0.3/ redis
cd redis/
make
  1. 配置
vim redis.conf
port 6379(自定义)
bind 10.168.1.166(ip)
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
  1. 启动3个实例
 src/redis-server redis.conf
  1. 创建集群
    再打开一个shell
 ./redis-cli --cluster create 10.168.1.164:6379 10.168.1.165:6379 10.168.1.166:6379
>>> Performing Cluster Check (using node 10.168.1.164:6379)
M: 4ae32b62955874bbd3df846031155e70b59d6668 10.168.1.164:6379
   slots:[0-5460] (5461 slots) master
M: 2adf5ca3cb4d915d1025d61bcb4aa7e1b7c1ede3 10.168.1.166:6379
   slots:[10923-16383] (5461 slots) master
M: 5573a15ce40d4a80b304902c902c0b32dbda60f8 10.168.1.165:6379
   slots:[5461-10922] (5462 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

看到以上基本就成了
5. 测试
登入一个客户端

./redis-cli -h 10.168.1.164 -p 6379 -c


10.168.1.165:6379> set k1 v1
-> Redirected to slot [12706] located at 10.168.1.166:6379
OK
10.168.1.166:6379> set k2 v2
-> Redirected to slot [449] located at 10.168.1.164:6379
OK
10.168.1.164:6379> set k3 v3
OK
10.168.1.164:6379> get k1
-> Redirected to slot [12706] located at 10.168.1.166:6379
"v1"
10.168.1.166:6379> get k2
-> Redirected to slot [449] located at 10.168.1.164:6379
"v2"

更多详情请见

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值