redis3.2.8 linux集群安装
redis3.2.8 linux集群安装
尚浩宇 发表于2年前
redis3.2.8 linux集群安装
  • 发表于 2年前
  • 阅读 1282
  • 收藏 12
  • 点赞 0
  • 评论 0
摘要: redis3 linux集群安装

最少为3+3模式

下载并安装基础组件

yum -y install gcc automake autoconf libtool make jemalloc
yum -y install ruby ruby-devel rubygems rpm-build

下载redis并解压安装

wget http://download.redis.io/releases/redis-3.2.8.tar.gz  
tar –zxvf redis-3.2.8.tar.gz  
cd redis-3.2.8  
make && make install

进入src目录

gem install redis 

每台机器在opt/redis下创建一个文件夹,文件夹名称redis-cluster,在这个文件夹下面再创建三个文件夹6379、6380、6381,然后分别在这三个文件夹下面创建配置文件redis.conf

# 默认以后台方式运行  
daemonize yes  
port 6379 
# 配置日志存放位置  
logfile "/opt/redis/redis-cluster/6379/logs/redis.log"  
     
# 配置持久化文件存放位置  
dir /opt/redis/redis-cluster/6379/data/redis  

#开启集群
cluster-enabled yes

cluster-config-file nodes.conf 

cluster-node-timeout 5000 

appendonly yes

# 取消保护模式(线下环境不需要)  
Protected-mode no  
  
# 绑定IP(线下环境不需要,注释掉即可)  
#bind 172.16.41.151  
 
# 缓存清除策略  
maxmemory-policy volatile-lru

注意修改端口为对应文件夹名称。

然后分别在每个文件夹下面创建logs、data两个文件夹,并且logs文件夹创建redis.log文件,data下面创建redis文件夹。

启动6个redis节点

 redis-server /opt/redis/redis-cluster/6379/redis.conf 

进去redis安装目录下的src文件夹,执行

ruby redis-trib.rb create --replicas 1 172.16.41.151:6379 172.16.41.151:6380 172.16.41.151:6381 172.16.41.152:6379 172.16.41.152:6380 172.16.41.152:6381

提示时输入yes,以下为输出内容

>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.41.152:6379
172.16.41.151:6379
172.16.41.152:6380
Adding replica 172.16.41.151:6380 to 172.16.41.152:6379
Adding replica 172.16.41.152:6381 to 172.16.41.151:6379
Adding replica 172.16.41.151:6381 to 172.16.41.152:6380
M: 0d64c1f6d22f91220ca3d5e563e35e837608b4ed 172.16.41.151:6379
   slots:5461-10922 (5462 slots) master
S: 0066fa22d60fae51db0b6cc32e688216299ff5ea 172.16.41.151:6380
   replicates 8cb5b258faed0b3ff34ced5bb0d9e1325e411e6c
S: 438e56001a39e0b7499aa68df8d91a0941447622 172.16.41.151:6381
   replicates 956cbf171b55fae4a72c29b1a442480408b7a5df
M: 8cb5b258faed0b3ff34ced5bb0d9e1325e411e6c 172.16.41.152:6379
   slots:0-5460 (5461 slots) master
M: 956cbf171b55fae4a72c29b1a442480408b7a5df 172.16.41.152:6380
   slots:10923-16383 (5461 slots) master
S: d63aeada0c7278f3d17209930d52d5c566c8d712 172.16.41.152:6381
   replicates 0d64c1f6d22f91220ca3d5e563e35e837608b4ed
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 172.16.41.151:6379)
M: 0d64c1f6d22f91220ca3d5e563e35e837608b4ed 172.16.41.151:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 956cbf171b55fae4a72c29b1a442480408b7a5df 172.16.41.152:6380
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 438e56001a39e0b7499aa68df8d91a0941447622 172.16.41.151:6381
   slots: (0 slots) slave
   replicates 956cbf171b55fae4a72c29b1a442480408b7a5df
S: d63aeada0c7278f3d17209930d52d5c566c8d712 172.16.41.152:6381
   slots: (0 slots) slave
   replicates 0d64c1f6d22f91220ca3d5e563e35e837608b4ed
M: 8cb5b258faed0b3ff34ced5bb0d9e1325e411e6c 172.16.41.152:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 0066fa22d60fae51db0b6cc32e688216299ff5ea 172.16.41.151:6380
   slots: (0 slots) slave
   replicates 8cb5b258faed0b3ff34ced5bb0d9e1325e411e6c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

关闭命令

redis-cli -h 172.16.41.151 -p 6379 shutdown

 

标签: redis
共有 人打赏支持
粉丝 46
博文 115
码字总数 93116
作品 1
×
尚浩宇
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: