redis3.0.7集群部署完整版-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 1583230
  • 博文数量: 101
  • 博客积分: 2465
  • 博客等级: 中尉
  • 技术积分: 2126
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-09 15:39
个人简介

https://minminmsn.com/

文章分类

全部博文(101)

文章存档

2018年(2)

2017年(2)

2016年(11)

2015年(14)

2014年(9)

2013年(16)

2012年(47)

相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: nosql

2016-12-11 16:27:21

redis3.0.7集群安装部署
redis集群没有出来前一直使用codis集群,现在测试下redis集群的性能。
一,架构
centos6.5 64位
redis1 redis1:6379主 redis3:6380从
redis2 redis2:6379主 redis1:6380从
redis3 redis3:6379主 redis2:6380从

二,部署redis实例
1,安装依赖
yum -y install tcl-devel
2,下载
wget
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,集群主从节点关系
redis1 redis1:6379主 redis3:6380从
redis2 redis2:6379主 redis1:6380从
redis3 redis3: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 --remove    
查看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:6380 to 192.168.188.38:6379
adding replica 192.168.188.38:6380 to 192.168.188.28:6379
adding replica 192.168.188.18:6380 to 192.168.188.18:6379
m: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
   slots:10923-16383 (5461 slots) master
m: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
   slots:5461-10922 (5462 slots) master
m: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
   slots:0-5460 (5461 slots) master
s: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
   replicates 53c202561155d141a8e24d42bb8eb2907998fce9
s: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
   replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
s: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
   replicates 654c0a7853724fe33683f54e8df665993ea704ed
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.188.18:6379)
m: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
   slots:10923-16383 (5461 slots) master
m: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
   slots:5461-10922 (5462 slots) master
m: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
   slots:0-5460 (5461 slots) master
m: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
   slots: (0 slots) master
   replicates 53c202561155d141a8e24d42bb8eb2907998fce9
m: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
   slots: (0 slots) master
   replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
m: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
   slots: (0 slots) master
   replicates 654c0a7853724fe33683f54e8df665993ea704ed
[ok] all nodes agree about slots configuration.
>>> check for open slots...
>>> check slots coverage...
[ok] all 16384 slots covered.


四,测试验证
调整主从状态
登录redis集群:
设置192.168.188.18:6380为192.168.188.28:6379的从
redis-cli -c -p 6380 -h 192.168.188.18
192.168.188.18:6380> cluster replicate 654c0a7853724fe33683f54e8df665993ea704ed
ok
设置192.168.188.38:6380为192.168.188.18:6379的从
redis-cli -c -p 6380 -h 192.168.188.38
192.168.188.38:6380> cluster replicate 53c202561155d141a8e24d42bb8eb2907998fce9
ok
最后保存配置到硬盘
192.168.188.38:6380> cluster saveconfig
ok


检查集群状态:
#redis-trib.rb check  192.168.188.18:6379
>>> performing cluster check (using node 192.168.188.18:6379)
m: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
s: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
   slots: (0 slots) slave
   replicates 53c202561155d141a8e24d42bb8eb2907998fce9
m: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
s: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
   slots: (0 slots) slave
   replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
s: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
   slots: (0 slots) slave
   replicates 654c0a7853724fe33683f54e8df665993ea704ed
m: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
[ok] all nodes agree about slots configuration.
>>> check for open slots...
>>> check slots coverage...
[ok] all 16384 slots covered.


使用方法
集群  
cluster info 打印集群的信息  
cluster nodes 列出集群当前已知的所有节点(node),以及这些节点的相关信息。  
节点  
cluster meet 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。  
cluster forget 从集群中移除 node_id 指定的节点。  
cluster replicate 将当前节点设置为 node_id 指定的节点的从节点。  
cluster saveconfig 将节点的配置文件保存到硬盘里面。  
槽(slot)  
cluster addslots [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。  
cluster delslots [slot ...] 移除一个或多个槽对当前节点的指派。  
cluster flushslots 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。  
cluster setslot node 将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。  
cluster setslot migrating 将本节点的槽 slot 迁移到 node_id 指定的节点中。  
cluster setslot importing 从 node_id 指定的节点中导入槽 slot 到本节点。  
cluster setslot stable 取消对槽 slot 的导入(import)或者迁移(migrate)。  
键  
cluster keyslot 计算键 key 应该被放置在哪个槽上。  
cluster countkeysinslot 返回槽 slot 目前包含的键值对数量。  
cluster getkeysinslot 返回 count 个 slot 槽中的键。  




五,排错优化
报错
/usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis/client.rb:97:in `call': err slot 16011 is already busy (redis::commanderror)
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:2432:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:2431:in `method_missing'
from /usr/local/bin/redis-trib.rb:212:in `flush_node_config'
from /usr/local/bin/redis-trib.rb:775:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:774:in `each'
from /usr/local/bin/redis-trib.rb:774:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:1295:in `create_cluster_cmd'
from /usr/local/bin/redis-trib.rb:1695:in `send'
from /usr/local/bin/redis-trib.rb:1695
处理   
rm -rf /data/redis/6379/nodes-6379.conf
rm -rf /data/redis/6380/nodes-6380.conf
/etc/init.d/redis_6379 restart
/etc/init.d/redis_6380 restart
gem list
gem uninstall redis --version 3.3.2
gem install redis --version 3.0.7
gem list


警告
 warning overcommit_memory is set to 0! background save may fail under low memory condition. to fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7997:m 08 dec 15:04:59.760 # warning you have transparent huge pages (thp) support enabled in your kernel. this will create latency and memory usage issues with redis. to fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. redis must be restarted after thp is disabled.
优化
vm.overcommit_memory = 1 
echo never > /sys/kernel/mm/transparent_hugepage/enabled
阅读(7451) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图