设为首页 加入收藏

TOP

Redis3.0.7集群部署完整版(一)
2016-12-14 08:15:11 】 浏览:485
Tags:Redis3.0.7 集群 部署 整版

Redis集群没有出来前,一直使用Codis集群,现在部署Redis集群看看效果如何。


一,架构


redis1redis1:6379主redis3:6380从


redis2redis2:6379主redis1:6380从


redis3redis3:6379主redis2:6380从


二,部署Redis实例


1,安装依赖


yum -y install tcl-devel


2,下载


wget http://download.redis.io/releases/redis-3.0.7.tar.gz


3,编译


cd /usr/local/src/


tar zxvf redis-3.0.7.tar.gz


cd redis-3.0.7


make


4,测试


make test


5,安装二进制程序到/usr/local/bin/目录


make install


ls /usr/local/bin/ -lh


6,安装服务


sh ./utils/install_server.sh


Welcome to the redis service installer


This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379]


Selecting default: 6379


Please select the redis config file name [/etc/redis/6379.conf]


Selected default - /etc/redis/6379.conf


Please select the redis log file name [/var/log/redis_6379.log] /data/redis/redis_6379.log


Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/6379


Please select the redis executable path [/usr/local/bin/redis-server]


Selected config:


Port : 6379


Config file : /etc/redis/6379.conf


Log file : /data/redis/redis_6379.log


Data dir : /data/redis/6379


Executable : /usr/local/bin/redis-server


Cli Executable : /usr/local/bin/redis-cli


Is this ok Then press ENTER to go on or Ctrl-C to abort.


Copied /tmp/6379.conf => /etc/init.d/redis_6379


Installing service...


Successfully added to chkconfig!


Successfully added to runlevels 345!


Starting Redis server...


Installation successful!


7,验证服务


/etc/init.d/redis_6379 status


8,其他节点类似安装


三,部署Cluster环境


1,集群主从节点关系


redis1redis1:6379主redis3:6380从


redis2redis2:6379主redis1:6380从


redis3redis3:6379主redis2:6380从


2,集群环境准备


这是源码安装


tar -xf ruby-2.2.3.tar.gz


cd ruby-2.2.3


./configure --disable-install-rdoc


make && make install


/usr/local/bin/ruby


/usr/local/bin/gem


YUM安装


yum install ruby ruby-devel rubygems


设置ruby gem源为淘宝,安装gems更快。


# gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/


查看gem源


# gem sources -l


安装ruby的redis模块(依赖接口)


# gem install redis(注意这地方要选定版本排错时会提到)


3,配置文件(其他实例相应修改端口)


cat /etc/redis/6379.conf |grep -Ev "^#|^$"


daemonize yes


pidfile /var/run/redis_6379.pid


port 6379


timeout 0


logfile /data/redis/redis_6379.log


dbfilename dump.rdb


dir /data/redis/6379


appendonly no


appendfilename "appendonly.aof"


appendfsync everysec


取消如下注释,让Redis在集群模式下运行


cluster-enabled yes 启动cluster模式


cluster-config-file nodes-6379.conf 集群信息文件名,由redis自己维护


cluster-node-timeout 5000 5秒中联系不到对方node,即认为对方有故障可能


4,重启redis (其他实例相应修改端口)


/etc/init.d/redis_6379 restart


会在/data/redis/6379/下面多出一个文件nodes-6379.conf


5,利用脚本工具建立集群


首先查看帮助看redis-trib脚本功能


注意编译安装时redis-trib.rb没有复制过来


cp ./src/redis-trib.rb /usr/local/bin/


ruby redis-trib.rb help


create:创建集群


check:检查集群


info:查看集群信息


fix:修复集群


reshard:在线迁移slot


rebalance:平衡集群节点slot数量


add-node:将新节点加入集群


del-node:从集群中删除节点


set-timeout:设置集群节点间心跳连接的超时时间


call:在集群全部节点上执行命令


import:将外部redis数据导入集群


开始创建集群注意前三个为主后三个为从(但是不能指定主从关系,后面可以在Cluster里面操作,目的是主从实例不能在统一节点服务器上), 选项 --replicas 1 表示集群中的每个主节点创建一个从节点。


/usr/local/bin/redis-trib.rb create --replicas 1 192.168.188.18:6379 192.168.188.28:6379 192.168.188.38:6379 192.168.188.18:6380 192.168.188.28:6380 192.168.188.38:6380


>>> Creating cluster


>>> Performing hash slots allocation on 6 nodes...


Using 3 masters:


192.168.188.38:6379


192.168.188.28:6379


192.168.188.18:6379


Adding replica 192.168.188.28:63

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用XtraBackup 备份MySQL数据库 下一篇Oracle 11g expdp中query参数的使..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目